package de.beyondsoft.ownchat.utils;

import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.data.prefs.BooleanPreference;
import de.beyondsoft.ownchat.di.InjectionHelper;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import javax.inject.Inject;
import javax.inject.Named;

import de.beyondsoft.ownchat.page.login.LoginActivity;

/**
 * Service should be started only when "Password Save"
 * is not checked in {@link LoginActivity};
 */
public class AppStoppedService extends Service {

    @Inject
    @Named(AppPrefsConstants.APP_KILLED)
    BooleanPreference mAppKilledPreference;

    @Inject
    @Named(AppPrefsConstants.SAVE_PASSWORD)
    BooleanPreference mSavedPasswordPref;

    @Inject
    NotificationManager mNotificationManager;

    @Override
    public void onCreate() {
        super.onCreate();
        InjectionHelper.getMainComponent(this).inject(this);
    }

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

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        mAppKilledPreference.set(true);

        stopSelf();
    }
}