/*
 * Copyright (c) 2011-2019, Zingaya, Inc. All rights reserved.
 */

package com.dyteMobileSdk;

import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;


public class ForegroundService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = intent.getAction();
        if (action != null) {
            if (action.equals(Constants.ACTION_FOREGROUND_SERVICE_START)) {
                Notification notification = NotificationHelper.getInstance(DyteInstanceManager.getCurrentActivity())
                                .buildNotification(DyteInstanceManager.getCurrentActivity());
                if (notification != null) {
                    startForeground(NotificationHelper.NOTIFICATION_ID, notification);
                }

            } else if (action.equals(Constants.ACTION_FOREGROUND_SERVICE_STOP)) {
                stopSelf();
            }
        }
        return START_NOT_STICKY;

    }
}