- * All broadcast messages are received and processed by this class.
- */
-public class ReminderReceiver extends BroadcastReceiver
-{
- public static final String ACTION_DISMISS_REMINDER =
- "org.isoron.uhabits.ACTION_DISMISS_REMINDER";
-
- public static final String ACTION_SHOW_REMINDER =
- "org.isoron.uhabits.ACTION_SHOW_REMINDER";
-
- public static final String ACTION_SNOOZE_REMINDER =
- "org.isoron.uhabits.ACTION_SNOOZE_REMINDER";
-
- private static final String TAG = "ReminderReceiver";
-
- private static Intent lastReceivedIntent = null;
-
- @Override
- public void onReceive(@Nullable final Context context, @Nullable Intent intent)
- {
- if (context == null || intent == null) return;
- if (intent.getAction() == null) return;
- lastReceivedIntent = intent;
-
- HabitsApplication app = (HabitsApplication) context.getApplicationContext();
- HabitsApplicationComponent appComponent = app.getComponent();
- HabitList habits = appComponent.getHabitList();
- ReminderController reminderController = appComponent.getReminderController();
-
- Log.i(TAG, String.format("Received intent: %s", intent.toString()));
-
- Habit habit = null;
- long today = DateUtils.getStartOfTodayWithOffset();
-
- if (intent.getData() != null)
- habit = habits.getById(parseId(intent.getData()));
- final long timestamp = intent.getLongExtra("timestamp", today);
- final long reminderTime = intent.getLongExtra("reminderTime", today);
-
- try
- {
- switch (intent.getAction())
- {
- case ACTION_SHOW_REMINDER:
- if (habit == null) return;
- Log.d("ReminderReceiver", String.format(
- "onShowReminder habit=%d timestamp=%d reminderTime=%d",
- habit.getId(),
- timestamp,
- reminderTime));
- reminderController.onShowReminder(habit,
- new Timestamp(timestamp), reminderTime);
- break;
-
- case ACTION_DISMISS_REMINDER:
- if (habit == null) return;
- Log.d("ReminderReceiver", String.format("onDismiss habit=%d", habit.getId()));
- reminderController.onDismiss(habit);
- break;
-
- case ACTION_SNOOZE_REMINDER:
- if (habit == null) return;
- Log.d("ReminderReceiver", String.format("onSnoozePressed habit=%d", habit.getId()));
- reminderController.onSnoozePressed(habit, context);
- break;
-
- case Intent.ACTION_BOOT_COMPLETED:
- Log.d("ReminderReceiver", "onBootCompleted");
- reminderController.onBootCompleted();
- break;
- }
- }
- catch (RuntimeException e)
- {
- Log.e(TAG, "could not process intent", e);
- }
- }
-
- public static void clearLastReceivedIntent()
- {
- lastReceivedIntent = null;
- }
-
- public static Intent getLastReceivedIntent()
- {
- return lastReceivedIntent;
- }
-}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt
new file mode 100644
index 000000000..026f99bec
--- /dev/null
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderReceiver.kt
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2016-2021 Álinson Santos Xavier
- * All broadcast messages are received and processed by this class.
- */
-public class WidgetReceiver extends BroadcastReceiver
-{
- public static final String ACTION_ADD_REPETITION =
- "org.isoron.uhabits.ACTION_ADD_REPETITION";
-
- public static final String ACTION_DISMISS_REMINDER =
- "org.isoron.uhabits.ACTION_DISMISS_REMINDER";
-
- public static final String ACTION_REMOVE_REPETITION =
- "org.isoron.uhabits.ACTION_REMOVE_REPETITION";
-
- public static final String ACTION_TOGGLE_REPETITION =
- "org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
-
- public static final String ACTION_SET_NUMERICAL_VALUE =
- "org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE";
-
- public static final String ACTION_UPDATE_WIDGETS_VALUE =
- "org.isoron.uhabits.ACTION_UPDATE_WIDGETS_VALUE";
-
- private static final String TAG = "WidgetReceiver";
-
- private static Intent lastReceivedIntent = null;
-
- @Override
- public void onReceive(final Context context, Intent intent)
- {
- HabitsApplication app =
- (HabitsApplication) context.getApplicationContext();
-
- WidgetComponent component = DaggerWidgetReceiver_WidgetComponent
- .builder()
- .habitsApplicationComponent(app.getComponent())
- .build();
-
- IntentParser parser = app.getComponent().getIntentParser();
- WidgetBehavior controller = component.getWidgetController();
- Preferences prefs = app.getComponent().getPreferences();
- WidgetUpdater widgetUpdater = app.getComponent().getWidgetUpdater();
-
- Log.i(TAG, String.format("Received intent: %s", intent.toString()));
- lastReceivedIntent = intent;
-
- try
- {
- IntentParser.CheckmarkIntentData data = null;
- if (intent.getAction() != ACTION_UPDATE_WIDGETS_VALUE)
- {
- data = parser.parseCheckmarkIntent(intent);
- }
-
- switch (intent.getAction())
- {
- case ACTION_ADD_REPETITION:
- Log.d(TAG, String.format(
- "onAddRepetition habit=%d timestamp=%d",
- data.getHabit().getId(),
- data.getTimestamp().getUnixTime()));
- controller.onAddRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_TOGGLE_REPETITION:
- Log.d(TAG, String.format(
- "onToggleRepetition habit=%d timestamp=%d",
- data.getHabit().getId(),
- data.getTimestamp().getUnixTime()));
- controller.onToggleRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_REMOVE_REPETITION:
- Log.d(TAG, String.format(
- "onRemoveRepetition habit=%d timestamp=%d",
- data.getHabit().getId(),
- data.getTimestamp().getUnixTime()));
- controller.onRemoveRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_SET_NUMERICAL_VALUE:
- context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
- Intent numberSelectorIntent = new Intent(context, NumericalCheckmarkWidgetActivity.class);
- numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- numberSelectorIntent.setAction(NumericalCheckmarkWidgetActivity.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY);
- parser.copyIntentData(intent,numberSelectorIntent);
- context.startActivity(numberSelectorIntent);
- break;
-
- case ACTION_UPDATE_WIDGETS_VALUE:
- widgetUpdater.updateWidgets();
- widgetUpdater.scheduleStartDayWidgetUpdate();
- break;
- }
- }
- catch (RuntimeException e)
- {
- Log.e("WidgetReceiver", "could not process intent", e);
- }
- }
-
- @ReceiverScope
- @Component(dependencies = HabitsApplicationComponent.class)
- interface WidgetComponent
- {
- WidgetBehavior getWidgetController();
- }
-
- public static Intent getLastReceivedIntent()
- {
- return lastReceivedIntent;
- }
-
- public static void clearLastReceivedIntent()
- {
- lastReceivedIntent = null;
- }
-}
diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt
new file mode 100644
index 000000000..2f5702796
--- /dev/null
+++ b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2016-2021 Álinson Santos Xavier