// Path: app/src/main/java/com/nilhcem/devoxxfr/DevoxxApp.java
// @DebugLog
// public class DevoxxApp extends Application {
// 
//     private AppComponent component;
// 
//     public static DevoxxApp get(Context context) {
//         return (DevoxxApp) context.getApplicationContext();
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         AndroidThreeTen.init(this);
//         initGraph();
//         initLogger();
//     }
// 
//     public AppComponent component() {
//         return component;
//     }
// 
//     private void initGraph() {
//         component = AppComponent.Initializer.init(this);
//     }
// 
//     private void initLogger() {
//         Timber.plant(new Timber.DebugTree());
//     }
// }
// 
// Path: app/src/main/java/com/nilhcem/devoxxfr/receiver/reminder/SessionsReminder.java
// @Singleton
// public class SessionsReminder {
// 
//     private final Context context;
//     private final SessionsDao sessionsDao;
//     private final SharedPreferences preferences;
//     private final AlarmManager alarmManager;
// 
//     @Inject
//     public SessionsReminder(Application app, SessionsDao sessionsDao, SharedPreferences preferences) {
//         this.context = app;
//         this.sessionsDao = sessionsDao;
//         this.preferences = preferences;
//         alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
//     }
// 
//     public boolean isEnabled() {
//         return preferences.getBoolean(context.getString(R.string.settings_notify_key), false);
//     }
// 
//     public void enableSessionReminder() {
//         performOnSelectedSessions(this::addSessionReminder);
//     }
// 
//     public void disableSessionReminder() {
//         performOnSelectedSessions(this::removeSessionReminder);
//     }
// 
//     public void addSessionReminder(@NonNull Session session) {
//         if (!isEnabled()) {
//             Timber.d("SessionsReminder is not enable, skip adding session");
//             return;
//         }
// 
//         PendingIntent intent = createSessionReminderIntent(session);
//         LocalDateTime now = LocalDateTime.now();
//         LocalDateTime sessionStartTime = session.getFromTime().minusMinutes(3);
//         if (!sessionStartTime.isAfter(now)) {
//             Timber.w("Do not set reminder for passed session");
//             return;
//         }
//         Timber.d("Setting reminder on %s", sessionStartTime);
//         App.setExactAlarm(alarmManager, sessionStartTime.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(), intent);
//     }
// 
//     public void removeSessionReminder(@NonNull Session session) {
//         Timber.d("Cancelling reminder on %s", session.getFromTime().minusMinutes(3));
//         createSessionReminderIntent(session).cancel();
//     }
// 
//     private PendingIntent createSessionReminderIntent(@NonNull Session session) {
//         Intent intent = new ReminderReceiverIntentBuilder(session).build(context);
//         return PendingIntent.getBroadcast(context, session.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
//     }
// 
//     private void performOnSelectedSessions(Action1<? super Session> onNext) {
//         sessionsDao.getSelectedSessions()
//                 .flatMap(Observable::from)
//                 .subscribeOn(Schedulers.io())
//                 .observeOn(Schedulers.computation())
//                 .subscribe(onNext, throwable -> Timber.e(throwable, "Error getting sessions"));
//     }
// }


import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.nilhcem.devoxxfr.DevoxxApp;
import com.nilhcem.devoxxfr.receiver.reminder.SessionsReminder;
import javax.inject.Inject;
import hugo.weaving.DebugLog;
package com.nilhcem.devoxxfr.receiver;





@DebugLog
public class BootReceiver extends BroadcastReceiver {

    public static void enable(Context context) {
        setActivationState(context, PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    }

    public static void disable(Context context) {
        setActivationState(context, PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    }

    private static void setActivationState(Context context, int state) {
        ComponentName componentName = new ComponentName(context, BootReceiver.class);
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
    }

// Path: app/src/main/java/com/nilhcem/devoxxfr/DevoxxApp.java
// @DebugLog
// public class DevoxxApp extends Application {
// 
//     private AppComponent component;
// 
//     public static DevoxxApp get(Context context) {
//         return (DevoxxApp) context.getApplicationContext();
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         AndroidThreeTen.init(this);
//         initGraph();
//         initLogger();
//     }
// 
//     public AppComponent component() {
//         return component;
//     }
// 
//     private void initGraph() {
//         component = AppComponent.Initializer.init(this);
//     }
// 
//     private void initLogger() {
//         Timber.plant(new Timber.DebugTree());
//     }
// }
// 
// Path: app/src/main/java/com/nilhcem/devoxxfr/receiver/reminder/SessionsReminder.java
// @Singleton
// public class SessionsReminder {
// 
//     private final Context context;
//     private final SessionsDao sessionsDao;
//     private final SharedPreferences preferences;
//     private final AlarmManager alarmManager;
// 
//     @Inject
//     public SessionsReminder(Application app, SessionsDao sessionsDao, SharedPreferences preferences) {
//         this.context = app;
//         this.sessionsDao = sessionsDao;
//         this.preferences = preferences;
//         alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
//     }
// 
//     public boolean isEnabled() {
//         return preferences.getBoolean(context.getString(R.string.settings_notify_key), false);
//     }
// 
//     public void enableSessionReminder() {
//         performOnSelectedSessions(this::addSessionReminder);
//     }
// 
//     public void disableSessionReminder() {
//         performOnSelectedSessions(this::removeSessionReminder);
//     }
// 
//     public void addSessionReminder(@NonNull Session session) {
//         if (!isEnabled()) {
//             Timber.d("SessionsReminder is not enable, skip adding session");
//             return;
//         }
// 
//         PendingIntent intent = createSessionReminderIntent(session);
//         LocalDateTime now = LocalDateTime.now();
//         LocalDateTime sessionStartTime = session.getFromTime().minusMinutes(3);
//         if (!sessionStartTime.isAfter(now)) {
//             Timber.w("Do not set reminder for passed session");
//             return;
//         }
//         Timber.d("Setting reminder on %s", sessionStartTime);
//         App.setExactAlarm(alarmManager, sessionStartTime.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(), intent);
//     }
// 
//     public void removeSessionReminder(@NonNull Session session) {
//         Timber.d("Cancelling reminder on %s", session.getFromTime().minusMinutes(3));
//         createSessionReminderIntent(session).cancel();
//     }
// 
//     private PendingIntent createSessionReminderIntent(@NonNull Session session) {
//         Intent intent = new ReminderReceiverIntentBuilder(session).build(context);
//         return PendingIntent.getBroadcast(context, session.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
//     }
// 
//     private void performOnSelectedSessions(Action1<? super Session> onNext) {
//         sessionsDao.getSelectedSessions()
//                 .flatMap(Observable::from)
//                 .subscribeOn(Schedulers.io())
//                 .observeOn(Schedulers.computation())
//                 .subscribe(onNext, throwable -> Timber.e(throwable, "Error getting sessions"));
//     }
// }


// Path: app/src/main/java/com/nilhcem/devoxxfr/receiver/BootReceiver.java
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import com.nilhcem.devoxxfr.DevoxxApp;
import com.nilhcem.devoxxfr.receiver.reminder.SessionsReminder;
import javax.inject.Inject;
import hugo.weaving.DebugLog;

package com.nilhcem.devoxxfr.receiver;





@DebugLog
public class BootReceiver extends BroadcastReceiver {

    public static void enable(Context context) {
        setActivationState(context, PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    }

    public static void disable(Context context) {
        setActivationState(context, PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    }

    private static void setActivationState(Context context, int state) {
        ComponentName componentName = new ComponentName(context, BootReceiver.class);
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP);
    }

    @Inject SessionsReminder sessionsReminder;