when asking for snooze delay, first show a list of common options

pull/367/merge
Luboš Luňák 8 years ago
parent aac59367dc
commit cec05ccbca

@ -1,5 +1,6 @@
package org.isoron.uhabits.notifications;
import android.app.*;
import android.content.*;
import android.os.*;
import android.support.v4.app.*;
@ -7,6 +8,7 @@ import android.text.format.*;
import android.util.*;
import com.android.datetimepicker.time.*;
import com.android.datetimepicker.time.TimePickerDialog;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.utils.DateUtils;
@ -18,12 +20,14 @@ import static org.isoron.uhabits.core.ui.ThemeSwitcher.THEME_DARK;
import static org.isoron.uhabits.core.utils.DateUtils.applyTimezone;
public class SnoozeDelayActivity extends FragmentActivity implements
TimePickerDialog.OnTimeSetListener, DialogInterface.OnDismissListener {
TimePickerDialog.OnTimeSetListener, DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
public static final String ACTION_ASK_SNOOZE = "org.isoron.uhabits.ACTION_ASK_SNOOZE";
private static final String TAG = "SnoozeDelayActivity";
private AlertDialog activeDelayDialog;
@Override
protected void onCreate(Bundle bundle)
{
@ -45,6 +49,34 @@ public class SnoozeDelayActivity extends FragmentActivity implements
}
private void AskSnooze()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.select_snooze_delay)
.setItems(R.array.snooze_interval_names_reminder, this);
AlertDialog dialog = builder.create();
dialog.setOnDismissListener(this);
activeDelayDialog = dialog;
dialog.show();
}
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
int[] snoozeDelay = getResources().getIntArray(R.array.snooze_interval_values_reminder);
assert (i >= 0 && i <= snoozeDelay.length);
if( snoozeDelay[ i ] < 0 )
{
activeDelayDialog.setOnDismissListener(null);
AskCustomSnooze();
return;
}
Intent intent = new Intent( ReminderReceiver.ACTION_SNOOZE_REMINDER_DELAY, getIntent().getData(),
this, ReminderReceiver.class );
intent.putExtra("snoozeDelay", snoozeDelay[ i ]);
sendBroadcast(intent);
}
private void AskCustomSnooze()
{
final Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);

@ -49,6 +49,9 @@ public class ReminderReceiver extends BroadcastReceiver
public static final String ACTION_SNOOZE_REMINDER_SET =
"org.isoron.uhabits.ACTION_SNOOZE_REMINDER_SET";
public static final String ACTION_SNOOZE_REMINDER_DELAY =
"org.isoron.uhabits.ACTION_SNOOZE_REMINDER_DELAY";
private static final String TAG = "ReminderReceiver";
@Override
@ -101,6 +104,12 @@ public class ReminderReceiver extends BroadcastReceiver
reminderController.snoozeNotificationSetReminderTime(habit, reminderTime);
break;
case ACTION_SNOOZE_REMINDER_DELAY:
if (habit == null) return;
long snoozeDelay = intent.getIntExtra("snoozeDelay", 0);
reminderController.snoozeNotificationAddDelay(habit, snoozeDelay);
break;
case Intent.ACTION_BOOT_COMPLETED:
reminderController.onBootCompleted();
break;

@ -49,6 +49,28 @@
<item>-1</item>
</string-array>
<string-array name="snooze_interval_names_reminder">
<item>@string/interval_15_minutes</item>
<item>@string/interval_30_minutes</item>
<item>@string/interval_1_hour</item>
<item>@string/interval_2_hour</item>
<item>@string/interval_4_hour</item>
<item>@string/interval_8_hour</item>
<item>@string/interval_24_hour</item>
<item>@string/interval_custom</item>
</string-array>
<integer-array name="snooze_interval_values_reminder" translatable="false">
<item>15</item>
<item>30</item>
<item>60</item>
<item>120</item>
<item>240</item>
<item>480</item>
<item>1440</item>
<item>-1</item>
</integer-array>
<string-array name="frequencyQuickSelect" translatable="false">
<item>@string/every_day</item>
<item>@string/every_week</item>

@ -84,6 +84,7 @@
<string name="interval_8_hour">8 hours</string>
<string name="interval_24_hour">24 hours</string>
<string name="interval_always_ask">Always ask</string>
<string name="interval_custom">Custom...</string>
<string name="pref_toggle_title">Toggle with short press</string>
<string name="pref_toggle_description">Put checkmarks with a single tap instead of press-and-hold. More convenient, but might cause accidental toggles.</string>
<string name="pref_snooze_interval_title">Snooze interval on reminders</string>
@ -96,6 +97,7 @@
<string name="name">Name</string>
<string name="settings">Settings</string>
<string name="snooze_interval">Snooze interval</string>
<string name="select_snooze_delay">Select snooze delay</string>
<string name="hint_title">Did you know?</string>
<string name="hint_drag">To rearrange the entries, press-and-hold on the name of the habit, then drag it to the correct place.</string>

Loading…
Cancel
Save