/*
 * 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;
import android.app.Activity;


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)) {
                final Activity currActivity = DyteInstanceManager.getCurrentActivity();
                if(currActivity!=null) {
                    Notification notification = NotificationHelper.getInstance(currActivity)
                                    .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;

    }
}
