mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Bring back snooze button
This commit is contained in:
@@ -48,9 +48,10 @@ class HabitsModule {
|
||||
fun getReminderScheduler(
|
||||
sys: IntentScheduler,
|
||||
commandRunner: CommandRunner,
|
||||
habitList: HabitList
|
||||
habitList: HabitList,
|
||||
widgetPreferences: WidgetPreferences
|
||||
): ReminderScheduler {
|
||||
return ReminderScheduler(commandRunner, habitList, sys)
|
||||
return ReminderScheduler(commandRunner, habitList, sys, widgetPreferences)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -148,13 +148,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
updateWeekdayPreference();
|
||||
|
||||
if (SDK_INT < Build.VERSION_CODES.O)
|
||||
findPreference("reminderCustomize").setVisible(false);
|
||||
else
|
||||
{
|
||||
findPreference("reminderSound").setVisible(false);
|
||||
findPreference("pref_snooze_interval").setVisible(false);
|
||||
}
|
||||
// Temporarily disable this; we now always ask
|
||||
findPreference("reminderSound").setVisible(false);
|
||||
findPreference("pref_snooze_interval").setVisible(false);
|
||||
|
||||
updateSync();
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ class AndroidNotificationTray
|
||||
timestamp: Timestamp,
|
||||
reminderTime: Long) {
|
||||
val notificationManager = NotificationManagerCompat.from(context)
|
||||
val summary = buildSummary(habit, reminderTime)
|
||||
notificationManager.notify(Int.MAX_VALUE, summary)
|
||||
//val summary = buildSummary(habit, reminderTime)
|
||||
//notificationManager.notify(Int.MAX_VALUE, summary)
|
||||
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||
createAndroidNotificationChannel(context)
|
||||
try {
|
||||
@@ -132,13 +132,11 @@ class AndroidNotificationTray
|
||||
if (preferences.shouldMakeNotificationsLed())
|
||||
builder.setLights(Color.RED, 1000, 1000)
|
||||
|
||||
if (SDK_INT < Build.VERSION_CODES.O) {
|
||||
val snoozeAction = Action(R.drawable.ic_action_snooze,
|
||||
context.getString(R.string.snooze),
|
||||
pendingIntents.snoozeNotification(habit))
|
||||
wearableExtender.addAction(snoozeAction)
|
||||
builder.addAction(snoozeAction)
|
||||
}
|
||||
val snoozeAction = Action(R.drawable.ic_action_snooze,
|
||||
context.getString(R.string.snooze),
|
||||
pendingIntents.snoozeNotification(habit))
|
||||
wearableExtender.addAction(snoozeAction)
|
||||
builder.addAction(snoozeAction)
|
||||
|
||||
builder.extend(wearableExtender)
|
||||
return builder.build()
|
||||
|
||||
@@ -26,6 +26,9 @@ public class SnoozeDelayPickerActivity extends FragmentActivity
|
||||
|
||||
private ReminderController reminderController;
|
||||
|
||||
@Nullable
|
||||
private AlertDialog dialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle bundle)
|
||||
{
|
||||
@@ -40,7 +43,7 @@ public class SnoozeDelayPickerActivity extends FragmentActivity
|
||||
if (habit == null) finish();
|
||||
|
||||
int theme = R.style.Theme_AppCompat_Light_Dialog_Alert;
|
||||
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(this, theme))
|
||||
dialog = new AlertDialog.Builder(new ContextThemeWrapper(this, theme))
|
||||
.setTitle(R.string.select_snooze_delay)
|
||||
.setItems(R.array.snooze_picker_names, null)
|
||||
.create();
|
||||
@@ -82,4 +85,11 @@ public class SnoozeDelayPickerActivity extends FragmentActivity
|
||||
super.finish();
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
if (dialog != null) dialog.dismiss();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,17 +70,13 @@ public class ReminderController
|
||||
|
||||
public void onSnoozePressed(@NonNull Habit habit, final Context context)
|
||||
{
|
||||
long delay = preferences.getSnoozeInterval();
|
||||
|
||||
if (delay < 0)
|
||||
showSnoozeDelayPicker(habit, context);
|
||||
else
|
||||
scheduleReminderMinutesFromNow(habit, delay);
|
||||
showSnoozeDelayPicker(habit, context);
|
||||
}
|
||||
|
||||
public void onSnoozeDelayPicked(Habit habit, int delay)
|
||||
public void onSnoozeDelayPicked(Habit habit, int delayInMinutes)
|
||||
{
|
||||
scheduleReminderMinutesFromNow(habit, delay);
|
||||
reminderScheduler.snoozeReminder(habit, delayInMinutes);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
public void onSnoozeTimePicked(Habit habit, int hour, int minute)
|
||||
@@ -95,12 +91,6 @@ public class ReminderController
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
private void scheduleReminderMinutesFromNow(Habit habit, long minutes)
|
||||
{
|
||||
reminderScheduler.scheduleMinutesFromNow(habit, minutes);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
private void showSnoozeDelayPicker(@NonNull Habit habit, Context context)
|
||||
{
|
||||
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
||||
|
||||
@@ -61,21 +61,6 @@ public class ReminderControllerTest extends BaseAndroidJVMTest
|
||||
verifyNoMoreInteractions(preferences);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSnooze() throws Exception
|
||||
{
|
||||
Habit habit = mock(Habit.class);
|
||||
long now = timestamp(2015, 1, 1);
|
||||
long nowTz = DateUtils.applyTimezone(now);
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
when(preferences.getSnoozeInterval()).thenReturn(15L);
|
||||
|
||||
controller.onSnoozePressed(habit,null);
|
||||
|
||||
verify(reminderScheduler).scheduleMinutesFromNow(habit, 15L);
|
||||
verify(notificationTray).cancel(habit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnShowReminder() throws Exception
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user