// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/service/DeviationService.java
// public class DeviationService extends WakefulIntentService {
//     private static String TAG = "DeviationService";
//     private static String LINE_PATTERN = "[A-Za-zåäöÅÄÖ ]?([\\d]+)[ A-Z]?";
//     private static Pattern sLinePattern = Pattern.compile(LINE_PATTERN);
//     private NotificationManager mNotificationManager;
//     //private Intent mInvokeIntent;
//     private DeviationNotificationDbAdapter mDb;
// 
//     public DeviationService() {
//         super("DeviationService");
//     }
// 
//     @Override
//     protected void doWakefulWork(Intent intent) {
//         mNotificationManager =
//             (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//         //mInvokeIntent = new Intent(this, DeviationsActivity.class);
// 
//         mDb = new DeviationNotificationDbAdapter(getApplicationContext());
//         mDb.open();
// 
//         SharedPreferences sharedPreferences =
//             PreferenceManager.getDefaultSharedPreferences(this);
//         String filterString = sharedPreferences.getString("notification_deviations_lines_csv", "");
//         ArrayList<Integer> triggerFor = DeviationStore.extractLineNumbers(filterString, null);
// 
//         DeviationStore deviationStore = new DeviationStore();
// 
//         try {
//             ArrayList<Deviation> deviations = deviationStore.getDeviations(this);
//             deviations = DeviationStore.filterByLineNumbers(deviations, triggerFor);
// 
//             for (Deviation deviation : deviations) {
//                 if (!mDb.containsReference(deviation.getReference(),
//                         deviation.getMessageVersion())) {
//                     mDb.create(deviation.getReference(), deviation.getMessageVersion());
//                     Log.d(TAG, "Notification triggered for " + deviation.getReference());
//                     showNotification(deviation);
//                 }
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//         mDb.close();
//     }
// 
//     /**
//      * Show a notification while this service is running.
//      */
//     private void showNotification(Deviation deviation) {
//         // The PendingIntent to launch our activity if the user selects this notification
//         Intent i = new Intent(this, DeviationsActivity.class);
//         i.setAction(DeviationsActivity.DEVIATION_FILTER_ACTION);
//         PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
// 
//         Notification notification = new NotificationCompat.Builder(this)
//                 .setSmallIcon(android.R.drawable.stat_notify_error)
//                 .setTicker(deviation.getDetails())
//                 .setWhen(System.currentTimeMillis())
//                 .setContentIntent(contentIntent)
//                 .setContentTitle(getText(R.string.deviations_label))
//                 .setContentText(getText(R.string.new_deviations))
//                 .build();
//         notification.flags = Notification.FLAG_AUTO_CANCEL;
//         // Send the notification.
//         mNotificationManager.notify(R.string.deviations_label, notification);
//     }
// 
//     public static void startAsRepeating(Context context) {
//         stopService(context);
//     }
// 
//     public static void startService(Context context) {
//         stopService(context);
//     }
// 
//     public static void stopService(Context context) {
//         SharedPreferences sharedPreferences =
//             PreferenceManager.getDefaultSharedPreferences(context);
//         AlarmManager mgr =
//             (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
//         Intent i = new Intent(context, OnAlarmReceiver.class);
//         PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
//         mgr.cancel(pi);
//         sharedPreferences.edit().putBoolean("notification_deviations_enabled", false).apply();
//         Log.d(TAG, "Deviation service stopped");
//     }
// }


import com.markupartist.sthlmtraveling.service.DeviationService;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
package com.markupartist.sthlmtraveling.receivers;



public class OnBootReceiver extends BroadcastReceiver {
    //private static final int PERIOD = 300000; // 5 minutes
    private static final int PERIOD = 300000; // 5 minutes
    private static final String TAG = "OnBootReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "OnBootReceiver");

// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/service/DeviationService.java
// public class DeviationService extends WakefulIntentService {
//     private static String TAG = "DeviationService";
//     private static String LINE_PATTERN = "[A-Za-zåäöÅÄÖ ]?([\\d]+)[ A-Z]?";
//     private static Pattern sLinePattern = Pattern.compile(LINE_PATTERN);
//     private NotificationManager mNotificationManager;
//     //private Intent mInvokeIntent;
//     private DeviationNotificationDbAdapter mDb;
// 
//     public DeviationService() {
//         super("DeviationService");
//     }
// 
//     @Override
//     protected void doWakefulWork(Intent intent) {
//         mNotificationManager =
//             (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//         //mInvokeIntent = new Intent(this, DeviationsActivity.class);
// 
//         mDb = new DeviationNotificationDbAdapter(getApplicationContext());
//         mDb.open();
// 
//         SharedPreferences sharedPreferences =
//             PreferenceManager.getDefaultSharedPreferences(this);
//         String filterString = sharedPreferences.getString("notification_deviations_lines_csv", "");
//         ArrayList<Integer> triggerFor = DeviationStore.extractLineNumbers(filterString, null);
// 
//         DeviationStore deviationStore = new DeviationStore();
// 
//         try {
//             ArrayList<Deviation> deviations = deviationStore.getDeviations(this);
//             deviations = DeviationStore.filterByLineNumbers(deviations, triggerFor);
// 
//             for (Deviation deviation : deviations) {
//                 if (!mDb.containsReference(deviation.getReference(),
//                         deviation.getMessageVersion())) {
//                     mDb.create(deviation.getReference(), deviation.getMessageVersion());
//                     Log.d(TAG, "Notification triggered for " + deviation.getReference());
//                     showNotification(deviation);
//                 }
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
// 
//         mDb.close();
//     }
// 
//     /**
//      * Show a notification while this service is running.
//      */
//     private void showNotification(Deviation deviation) {
//         // The PendingIntent to launch our activity if the user selects this notification
//         Intent i = new Intent(this, DeviationsActivity.class);
//         i.setAction(DeviationsActivity.DEVIATION_FILTER_ACTION);
//         PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
// 
//         Notification notification = new NotificationCompat.Builder(this)
//                 .setSmallIcon(android.R.drawable.stat_notify_error)
//                 .setTicker(deviation.getDetails())
//                 .setWhen(System.currentTimeMillis())
//                 .setContentIntent(contentIntent)
//                 .setContentTitle(getText(R.string.deviations_label))
//                 .setContentText(getText(R.string.new_deviations))
//                 .build();
//         notification.flags = Notification.FLAG_AUTO_CANCEL;
//         // Send the notification.
//         mNotificationManager.notify(R.string.deviations_label, notification);
//     }
// 
//     public static void startAsRepeating(Context context) {
//         stopService(context);
//     }
// 
//     public static void startService(Context context) {
//         stopService(context);
//     }
// 
//     public static void stopService(Context context) {
//         SharedPreferences sharedPreferences =
//             PreferenceManager.getDefaultSharedPreferences(context);
//         AlarmManager mgr =
//             (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
//         Intent i = new Intent(context, OnAlarmReceiver.class);
//         PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
//         mgr.cancel(pi);
//         sharedPreferences.edit().putBoolean("notification_deviations_enabled", false).apply();
//         Log.d(TAG, "Deviation service stopped");
//     }
// }


// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/receivers/OnBootReceiver.java
import com.markupartist.sthlmtraveling.service.DeviationService;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;

package com.markupartist.sthlmtraveling.receivers;



public class OnBootReceiver extends BroadcastReceiver {
    //private static final int PERIOD = 300000; // 5 minutes
    private static final int PERIOD = 300000; // 5 minutes
    private static final String TAG = "OnBootReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "OnBootReceiver");

        DeviationService.startAsRepeating(context);