Merge branch 'feature/custom-snooze' into dev

pull/367/merge
Alinson S. Xavier 8 years ago
commit b46b7aae25

@ -18,6 +18,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
} }
dependencies { dependencies {

@ -63,6 +63,7 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
private static final int PULSE_ANIMATOR_DELAY = 300; private static final int PULSE_ANIMATOR_DELAY = 300;
private OnTimeSetListener mCallback; private OnTimeSetListener mCallback;
private DialogInterface.OnDismissListener dismissListener;
private HapticFeedbackController mHapticFeedbackController; private HapticFeedbackController mHapticFeedbackController;
@ -116,7 +117,7 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
*/ */
void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute); void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute);
void onTimeCleared(RadialPickerLayout view); default void onTimeCleared(RadialPickerLayout view) {}
} }
public TimePickerDialog() { public TimePickerDialog() {
@ -998,4 +999,15 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
return false; return false;
} }
} }
public void setDismissListener( DialogInterface.OnDismissListener listener ) {
dismissListener = listener;
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if( dismissListener != null )
dismissListener.onDismiss(dialog);
}
} }

@ -91,6 +91,11 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.habits.list.ListHabitsActivity"/> android:value=".activities.habits.list.ListHabitsActivity"/>
</activity> </activity>
<activity android:name=".notifications.SnoozeDelayPickerActivity"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
<receiver <receiver
android:name=".widgets.CheckmarkWidgetProvider" android:name=".widgets.CheckmarkWidgetProvider"

@ -33,6 +33,7 @@ import org.isoron.uhabits.core.ui.*;
import org.isoron.uhabits.core.ui.screens.habits.list.*; import org.isoron.uhabits.core.ui.screens.habits.list.*;
import org.isoron.uhabits.core.utils.*; import org.isoron.uhabits.core.utils.*;
import org.isoron.uhabits.intents.*; import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.receivers.*;
import org.isoron.uhabits.sync.*; import org.isoron.uhabits.sync.*;
import org.isoron.uhabits.tasks.*; import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.widgets.*; import org.isoron.uhabits.widgets.*;
@ -80,6 +81,8 @@ public interface HabitsApplicationComponent
ReminderScheduler getReminderScheduler(); ReminderScheduler getReminderScheduler();
ReminderController getReminderController();
SyncManager getSyncManager(); SyncManager getSyncManager();
TaskRunner getTaskRunner(); TaskRunner getTaskRunner();

@ -25,7 +25,10 @@ import org.isoron.androidbase.activities.*
import org.isoron.uhabits.* import org.isoron.uhabits.*
import org.isoron.uhabits.activities.habits.list.views.* import org.isoron.uhabits.activities.habits.list.views.*
import org.isoron.uhabits.core.commands.* import org.isoron.uhabits.core.commands.*
import org.isoron.uhabits.core.preferences.*
import org.isoron.uhabits.core.ui.*
import org.isoron.uhabits.core.ui.screens.habits.list.* import org.isoron.uhabits.core.ui.screens.habits.list.*
import org.isoron.uhabits.core.utils.*
import javax.inject.* import javax.inject.*
@ActivityScope @ActivityScope
@ -33,8 +36,10 @@ class ListHabitsSelectionMenu @Inject constructor(
private val screen: ListHabitsScreen, private val screen: ListHabitsScreen,
private val listAdapter: HabitCardListAdapter, private val listAdapter: HabitCardListAdapter,
var commandRunner: CommandRunner, var commandRunner: CommandRunner,
private val prefs: Preferences,
private val behavior: ListHabitsSelectionMenuBehavior, private val behavior: ListHabitsSelectionMenuBehavior,
private val listController: Lazy<HabitCardListController> private val listController: Lazy<HabitCardListController>,
private val notificationTray: NotificationTray
) : BaseSelectionMenu() { ) : BaseSelectionMenu() {
override fun onFinish() { override fun onFinish() {
@ -69,6 +74,12 @@ class ListHabitsSelectionMenu @Inject constructor(
return true return true
} }
R.id.action_notify -> {
for(h in listAdapter.selected)
notificationTray.show(h, DateUtils.getToday(), 0)
return true
}
else -> return false else -> return false
} }
} }
@ -78,12 +89,14 @@ class ListHabitsSelectionMenu @Inject constructor(
val itemColor = menu.findItem(R.id.action_color) val itemColor = menu.findItem(R.id.action_color)
val itemArchive = menu.findItem(R.id.action_archive_habit) val itemArchive = menu.findItem(R.id.action_archive_habit)
val itemUnarchive = menu.findItem(R.id.action_unarchive_habit) val itemUnarchive = menu.findItem(R.id.action_unarchive_habit)
val itemNotify = menu.findItem(R.id.action_notify)
itemColor.isVisible = true itemColor.isVisible = true
itemEdit.isVisible = behavior.canEdit() itemEdit.isVisible = behavior.canEdit()
itemArchive.isVisible = behavior.canArchive() itemArchive.isVisible = behavior.canArchive()
itemUnarchive.isVisible = behavior.canUnarchive() itemUnarchive.isVisible = behavior.canUnarchive()
setTitle(Integer.toString(listAdapter.selected.size)) setTitle(Integer.toString(listAdapter.selected.size))
itemNotify.isVisible = prefs.isDeveloper
return true return true
} }

@ -44,8 +44,15 @@ class AndroidNotificationTray
private val ringtoneManager: RingtoneManager private val ringtoneManager: RingtoneManager
) : NotificationTray.SystemTray { ) : NotificationTray.SystemTray {
private var active = HashSet<Int>()
override fun removeNotification(id: Int) { override fun removeNotification(id: Int) {
NotificationManagerCompat.from(context).cancel(id) val manager = NotificationManagerCompat.from(context)
manager.cancel(id)
active.remove(id)
// Clear the group summary notification
if(active.isEmpty()) manager.cancelAll()
} }
override fun showNotification(habit: Habit, override fun showNotification(habit: Habit,
@ -58,6 +65,7 @@ class AndroidNotificationTray
notificationManager.notify(Int.MAX_VALUE, summary) notificationManager.notify(Int.MAX_VALUE, summary)
val notification = buildNotification(habit, reminderTime, timestamp) val notification = buildNotification(habit, reminderTime, timestamp)
notificationManager.notify(notificationId, notification) notificationManager.notify(notificationId, notification)
active.add(notificationId)
} }
@NonNull @NonNull
@ -79,8 +87,7 @@ class AndroidNotificationTray
val removeRepetitionAction = Action( val removeRepetitionAction = Action(
R.drawable.ic_action_cancel, R.drawable.ic_action_cancel,
context.getString(R.string.no), context.getString(R.string.no),
pendingIntents.removeRepetition(habit) pendingIntents.removeRepetition(habit))
)
val wearableBg = decodeResource(context.resources, R.drawable.stripe) val wearableBg = decodeResource(context.resources, R.drawable.stripe)

@ -0,0 +1,85 @@
package org.isoron.uhabits.notifications;
import android.app.*;
import android.os.*;
import android.support.annotation.*;
import android.support.v4.app.*;
import android.text.format.*;
import android.view.*;
import android.widget.*;
import com.android.datetimepicker.time.TimePickerDialog;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.receivers.*;
import java.util.*;
import static android.content.ContentUris.parseId;
public class SnoozeDelayPickerActivity extends FragmentActivity
implements AdapterView.OnItemClickListener
{
private Habit habit;
private ReminderController reminderController;
@Override
protected void onCreate(@Nullable Bundle bundle)
{
super.onCreate(bundle);
if (getIntent() == null) finish();
if (getIntent().getData() == null) finish();
HabitsApplication app = (HabitsApplication) getApplicationContext();
HabitsApplicationComponent appComponent = app.getComponent();
reminderController = appComponent.getReminderController();
habit = appComponent.getHabitList().getById(parseId(getIntent().getData()));
if (habit == null) finish();
int theme = R.style.Theme_AppCompat_Light_Dialog_Alert;
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(this, theme))
.setTitle(R.string.select_snooze_delay)
.setItems(R.array.snooze_picker_names, null)
.create();
dialog.getListView().setOnItemClickListener(this);
dialog.setOnDismissListener(d -> finish());
dialog.show();
}
private void showTimePicker()
{
final Calendar calendar = Calendar.getInstance();
TimePickerDialog dialog = TimePickerDialog.newInstance(
(view, hour, minute) -> {
reminderController.onSnoozeTimePicked(habit, hour, minute);
finish();
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
DateFormat.is24HourFormat(this));
dialog.show(getSupportFragmentManager(), "timePicker");
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
int[] snoozeValues = getResources().getIntArray(R.array.snooze_picker_values);
if (snoozeValues[position] >= 0)
{
reminderController.onSnoozeDelayPicked(habit, snoozeValues[position]);
finish();
}
else showTimePicker();
}
@Override
public void finish()
{
super.finish();
overridePendingTransition(0, 0);
}
}

@ -19,19 +19,21 @@
package org.isoron.uhabits.receivers; package org.isoron.uhabits.receivers;
import android.content.*;
import android.net.*;
import android.support.annotation.*; import android.support.annotation.*;
import org.isoron.uhabits.core.*;
import org.isoron.uhabits.core.models.*; import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.preferences.*; import org.isoron.uhabits.core.preferences.*;
import org.isoron.uhabits.core.reminders.*; import org.isoron.uhabits.core.reminders.*;
import org.isoron.uhabits.core.ui.*; import org.isoron.uhabits.core.ui.*;
import org.isoron.uhabits.core.utils.*;
import org.isoron.uhabits.notifications.*;
import javax.inject.*; import javax.inject.*;
import static org.isoron.uhabits.core.utils.DateUtils.applyTimezone; @AppScope
import static org.isoron.uhabits.core.utils.DateUtils.getLocalTime;
@ReceiverScope
public class ReminderController public class ReminderController
{ {
@NonNull @NonNull
@ -40,6 +42,7 @@ public class ReminderController
@NonNull @NonNull
private final NotificationTray notificationTray; private final NotificationTray notificationTray;
@NonNull
private Preferences preferences; private Preferences preferences;
@Inject @Inject
@ -65,14 +68,25 @@ public class ReminderController
reminderScheduler.scheduleAll(); reminderScheduler.scheduleAll();
} }
public void onSnooze(@NonNull Habit habit) public void onSnoozePressed(@NonNull Habit habit, final Context context)
{ {
long snoozeInterval = preferences.getSnoozeInterval(); long delay = preferences.getSnoozeInterval();
long now = applyTimezone(getLocalTime()); if (delay < 0)
long reminderTime = now + snoozeInterval * 60 * 1000; showSnoozeDelayPicker(habit, context);
else
scheduleReminderMinutesFromNow(habit, delay);
}
reminderScheduler.schedule(habit, reminderTime); public void onSnoozeDelayPicked(Habit habit, int delay)
{
scheduleReminderMinutesFromNow(habit, delay);
}
public void onSnoozeTimePicked(Habit habit, int hour, int minute)
{
Long time = DateUtils.getUpcomingTimeInMillis(hour, minute);
reminderScheduler.scheduleAtTime(habit, time);
notificationTray.cancel(habit); notificationTray.cancel(habit);
} }
@ -80,4 +94,19 @@ public class ReminderController
{ {
notificationTray.cancel(habit); 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));
Intent intent = new Intent(context, SnoozeDelayPickerActivity.class);
intent.setData(Uri.parse(habit.getUriString()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
} }

@ -20,14 +20,13 @@
package org.isoron.uhabits.receivers; package org.isoron.uhabits.receivers;
import android.content.*; import android.content.*;
import android.support.annotation.*;
import android.util.*; import android.util.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*; import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*; import org.isoron.uhabits.core.utils.*;
import dagger.*;
import static android.content.ContentUris.*; import static android.content.ContentUris.*;
/** /**
@ -38,30 +37,26 @@ import static android.content.ContentUris.*;
public class ReminderReceiver extends BroadcastReceiver public class ReminderReceiver extends BroadcastReceiver
{ {
public static final String ACTION_DISMISS_REMINDER = public static final String ACTION_DISMISS_REMINDER =
"org.isoron.uhabits.ACTION_DISMISS_REMINDER"; "org.isoron.uhabits.ACTION_DISMISS_REMINDER";
public static final String ACTION_SHOW_REMINDER = public static final String ACTION_SHOW_REMINDER =
"org.isoron.uhabits.ACTION_SHOW_REMINDER"; "org.isoron.uhabits.ACTION_SHOW_REMINDER";
public static final String ACTION_SNOOZE_REMINDER = public static final String ACTION_SNOOZE_REMINDER =
"org.isoron.uhabits.ACTION_SNOOZE_REMINDER"; "org.isoron.uhabits.ACTION_SNOOZE_REMINDER";
private static final String TAG = "ReminderReceiver"; private static final String TAG = "ReminderReceiver";
@Override @Override
public void onReceive(final Context context, Intent intent) public void onReceive(@Nullable final Context context, @Nullable Intent intent)
{ {
HabitsApplication app = if (context == null || intent == null) return;
(HabitsApplication) context.getApplicationContext(); if (intent.getAction() == null) return;
ReminderComponent component = DaggerReminderReceiver_ReminderComponent
.builder()
.habitsApplicationComponent(app.getComponent())
.build();
HabitList habits = app.getComponent().getHabitList(); HabitsApplication app = (HabitsApplication) context.getApplicationContext();
ReminderController reminderController = HabitsApplicationComponent appComponent = app.getComponent();
component.getReminderController(); HabitList habits = appComponent.getHabitList();
ReminderController reminderController = appComponent.getReminderController();
Log.i(TAG, String.format("Received intent: %s", intent.toString())); Log.i(TAG, String.format("Received intent: %s", intent.toString()));
@ -80,7 +75,7 @@ public class ReminderReceiver extends BroadcastReceiver
case ACTION_SHOW_REMINDER: case ACTION_SHOW_REMINDER:
if (habit == null) return; if (habit == null) return;
reminderController.onShowReminder(habit, reminderController.onShowReminder(habit,
new Timestamp(timestamp), reminderTime); new Timestamp(timestamp), reminderTime);
break; break;
case ACTION_DISMISS_REMINDER: case ACTION_DISMISS_REMINDER:
@ -90,7 +85,7 @@ public class ReminderReceiver extends BroadcastReceiver
case ACTION_SNOOZE_REMINDER: case ACTION_SNOOZE_REMINDER:
if (habit == null) return; if (habit == null) return;
reminderController.onSnooze(habit); reminderController.onSnoozePressed(habit, context);
break; break;
case Intent.ACTION_BOOT_COMPLETED: case Intent.ACTION_BOOT_COMPLETED:
@ -103,11 +98,4 @@ public class ReminderReceiver extends BroadcastReceiver
Log.e(TAG, "could not process intent", e); Log.e(TAG, "could not process intent", e);
} }
} }
@ReceiverScope
@Component(dependencies = HabitsApplicationComponent.class)
interface ReminderComponent
{
ReminderController getReminderController();
}
} }

@ -46,4 +46,9 @@
android:title="@string/delete" android:title="@string/delete"
app:showAsAction="never"/> app:showAsAction="never"/>
<item
android:id="@+id/action_notify"
android:title="@string/reminder"
app:showAsAction="never"/>
</menu> </menu>

@ -35,6 +35,7 @@
<item>@string/interval_4_hour</item> <item>@string/interval_4_hour</item>
<item>@string/interval_8_hour</item> <item>@string/interval_8_hour</item>
<item>@string/interval_24_hour</item> <item>@string/interval_24_hour</item>
<item>@string/interval_always_ask</item>
</string-array> </string-array>
<string-array name="snooze_interval_values" translatable="false"> <string-array name="snooze_interval_values" translatable="false">
@ -45,8 +46,31 @@
<item>240</item> <item>240</item>
<item>480</item> <item>480</item>
<item>1440</item> <item>1440</item>
<item>-1</item>
</string-array> </string-array>
<string-array name="snooze_picker_names">
<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_picker_values" 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"> <string-array name="frequencyQuickSelect" translatable="false">
<item>@string/every_day</item> <item>@string/every_day</item>
<item>@string/every_week</item> <item>@string/every_week</item>

@ -83,6 +83,8 @@
<string name="interval_4_hour">4 hours</string> <string name="interval_4_hour">4 hours</string>
<string name="interval_8_hour">8 hours</string> <string name="interval_8_hour">8 hours</string>
<string name="interval_24_hour">24 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_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_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> <string name="pref_snooze_interval_title">Snooze interval on reminders</string>
@ -95,6 +97,7 @@
<string name="name">Name</string> <string name="name">Name</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="snooze_interval">Snooze interval</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_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> <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>

@ -70,9 +70,9 @@ public class ReminderControllerTest extends BaseAndroidJVMTest
DateUtils.setFixedLocalTime(now); DateUtils.setFixedLocalTime(now);
when(preferences.getSnoozeInterval()).thenReturn(15L); when(preferences.getSnoozeInterval()).thenReturn(15L);
controller.onSnooze(habit); controller.onSnoozePressed(habit,null);
verify(reminderScheduler).schedule(habit, nowTz + 900000); verify(reminderScheduler).scheduleAtTime(habit, nowTz + 900000);
verify(notificationTray).cancel(habit); verify(notificationTray).cancel(habit);
} }

@ -22,8 +22,9 @@ package org.isoron.uhabits.core.models;
import android.support.annotation.*; import android.support.annotation.*;
import org.apache.commons.lang3.builder.*; import org.apache.commons.lang3.builder.*;
import org.isoron.uhabits.core.utils.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle; import static org.isoron.uhabits.core.utils.StringUtils.*;
public final class Reminder public final class Reminder
{ {
@ -56,6 +57,11 @@ public final class Reminder
return minute; return minute;
} }
public long getTimeInMillis()
{
return DateUtils.getUpcomingTimeInMillis(hour, minute);
}
@Override @Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
@ -66,29 +72,29 @@ public final class Reminder
Reminder reminder = (Reminder) o; Reminder reminder = (Reminder) o;
return new EqualsBuilder() return new EqualsBuilder()
.append(hour, reminder.hour) .append(hour, reminder.hour)
.append(minute, reminder.minute) .append(minute, reminder.minute)
.append(days, reminder.days) .append(days, reminder.days)
.isEquals(); .isEquals();
} }
@Override @Override
public int hashCode() public int hashCode()
{ {
return new HashCodeBuilder(17, 37) return new HashCodeBuilder(17, 37)
.append(hour) .append(hour)
.append(minute) .append(minute)
.append(days) .append(days)
.toHashCode(); .toHashCode();
} }
@Override @Override
public String toString() public String toString()
{ {
return new ToStringBuilder(this, defaultToStringStyle()) return new ToStringBuilder(this, defaultToStringStyle())
.append("hour", hour) .append("hour", hour)
.append("minute", minute) .append("minute", minute)
.append("days", days) .append("days", days)
.toString(); .toString();
} }
} }

@ -24,9 +24,6 @@ import android.support.annotation.*;
import org.isoron.uhabits.core.*; import org.isoron.uhabits.core.*;
import org.isoron.uhabits.core.commands.*; import org.isoron.uhabits.core.commands.*;
import org.isoron.uhabits.core.models.*; import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import java.util.*;
import javax.inject.*; import javax.inject.*;
@ -60,14 +57,17 @@ public class ReminderScheduler implements CommandRunner.Listener
scheduleAll(); scheduleAll();
} }
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime) public void schedule(@NonNull Habit habit)
{
Long reminderTime = habit.getReminder().getTimeInMillis();
scheduleAtTime(habit, reminderTime);
}
public void scheduleAtTime(@NonNull Habit habit, @NonNull Long reminderTime)
{ {
if (!habit.hasReminder()) return; if (!habit.hasReminder()) return;
if (habit.isArchived()) return; if (habit.isArchived()) return;
Reminder reminder = habit.getReminder();
if (reminderTime == null) reminderTime = getReminderTime(reminder);
long timestamp = getStartOfDay(removeTimezone(reminderTime)); long timestamp = getStartOfDay(removeTimezone(reminderTime));
sys.scheduleShowReminder(reminderTime, habit, timestamp); sys.scheduleShowReminder(reminderTime, habit, timestamp);
} }
@ -76,7 +76,7 @@ public class ReminderScheduler implements CommandRunner.Listener
HabitList reminderHabits = HabitList reminderHabits =
habitList.getFiltered(HabitMatcher.WITH_ALARM); habitList.getFiltered(HabitMatcher.WITH_ALARM);
for (Habit habit : reminderHabits) for (Habit habit : reminderHabits)
schedule(habit, null); schedule(habit);
} }
public void startListening() public void startListening()
@ -89,19 +89,11 @@ public class ReminderScheduler implements CommandRunner.Listener
commandRunner.removeListener(this); commandRunner.removeListener(this);
} }
@NonNull public void scheduleMinutesFromNow(Habit habit, long minutes)
private Long getReminderTime(@NonNull Reminder reminder)
{ {
Calendar calendar = DateUtils.getStartOfTodayCalendar(); long now = applyTimezone(getLocalTime());
calendar.set(Calendar.HOUR_OF_DAY, reminder.getHour()); long reminderTime = now + minutes * 60 * 1000;
calendar.set(Calendar.MINUTE, reminder.getMinute()); scheduleAtTime(habit, reminderTime);
calendar.set(Calendar.SECOND, 0);
Long time = calendar.getTimeInMillis();
if (DateUtils.getLocalTime() > time)
time += DateUtils.DAY_LENGTH;
return applyTimezone(time);
} }
public interface SystemScheduler public interface SystemScheduler

@ -240,6 +240,20 @@ public abstract class DateUtils
} }
} }
public static long getUpcomingTimeInMillis(int hour, int minute)
{
Calendar calendar = DateUtils.getStartOfTodayCalendar();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
Long time = calendar.getTimeInMillis();
if (DateUtils.getLocalTime() > time)
time += DateUtils.DAY_LENGTH;
return applyTimezone(time);
}
public enum TruncateField public enum TruncateField
{ {
MONTH, WEEK_NUMBER, YEAR, QUARTER MONTH, WEEK_NUMBER, YEAR, QUARTER

Loading…
Cancel
Save