package com.hyperling.apps.wheretheriverfrowns;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by ling on 10/11/16.
 */

public class ServiceReceiver extends WakefulBroadcastReceiver {
    private SharedPreferences sharedPreferences;

    private String sharedPreferencesKey, debugKey, TAG;

    private static boolean DEBUG;

    @Override
    public void onReceive(Context context, Intent intent) {

        // Keys
        sharedPreferencesKey = context.getString(R.string.sharedPreferencesKey);
        debugKey = context.getString(R.string.debugKey);

        // Strings
        TAG = context.getResources().getString(R.string.TAG);

        // Preferences
        sharedPreferences = context.getSharedPreferences(sharedPreferencesKey, MODE_PRIVATE);
        DEBUG = sharedPreferences.getBoolean(debugKey, false);

        if (DEBUG) {
            Log.d(TAG, "ServiceReceiver: onReceive:  intent.getAction()=" + intent.getAction());
        }

        Intent serviceIntent = new Intent(context, MyService.class);
        context.startService(serviceIntent);
    }
}
