mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'feature/custom-snooze' into dev
This commit is contained in:
@@ -18,6 +18,11 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -63,6 +63,7 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
|
||||
private static final int PULSE_ANIMATOR_DELAY = 300;
|
||||
|
||||
private OnTimeSetListener mCallback;
|
||||
private DialogInterface.OnDismissListener dismissListener;
|
||||
|
||||
private HapticFeedbackController mHapticFeedbackController;
|
||||
|
||||
@@ -116,7 +117,7 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
|
||||
*/
|
||||
void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute);
|
||||
|
||||
void onTimeCleared(RadialPickerLayout view);
|
||||
default void onTimeCleared(RadialPickerLayout view) {}
|
||||
}
|
||||
|
||||
public TimePickerDialog() {
|
||||
@@ -998,4 +999,15 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
|
||||
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:value=".activities.habits.list.ListHabitsActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".notifications.SnoozeDelayPickerActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
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.utils.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.receivers.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
@@ -80,6 +81,8 @@ public interface HabitsApplicationComponent
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
ReminderController getReminderController();
|
||||
|
||||
SyncManager getSyncManager();
|
||||
|
||||
TaskRunner getTaskRunner();
|
||||
|
||||
@@ -25,7 +25,10 @@ import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
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.utils.*
|
||||
import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
@@ -33,8 +36,10 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
private val screen: ListHabitsScreen,
|
||||
private val listAdapter: HabitCardListAdapter,
|
||||
var commandRunner: CommandRunner,
|
||||
private val prefs: Preferences,
|
||||
private val behavior: ListHabitsSelectionMenuBehavior,
|
||||
private val listController: Lazy<HabitCardListController>
|
||||
private val listController: Lazy<HabitCardListController>,
|
||||
private val notificationTray: NotificationTray
|
||||
) : BaseSelectionMenu() {
|
||||
|
||||
override fun onFinish() {
|
||||
@@ -69,6 +74,12 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.action_notify -> {
|
||||
for(h in listAdapter.selected)
|
||||
notificationTray.show(h, DateUtils.getToday(), 0)
|
||||
return true
|
||||
}
|
||||
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
@@ -78,12 +89,14 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
val itemColor = menu.findItem(R.id.action_color)
|
||||
val itemArchive = menu.findItem(R.id.action_archive_habit)
|
||||
val itemUnarchive = menu.findItem(R.id.action_unarchive_habit)
|
||||
val itemNotify = menu.findItem(R.id.action_notify)
|
||||
|
||||
itemColor.isVisible = true
|
||||
itemEdit.isVisible = behavior.canEdit()
|
||||
itemArchive.isVisible = behavior.canArchive()
|
||||
itemUnarchive.isVisible = behavior.canUnarchive()
|
||||
setTitle(Integer.toString(listAdapter.selected.size))
|
||||
itemNotify.isVisible = prefs.isDeveloper
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -44,8 +44,15 @@ class AndroidNotificationTray
|
||||
private val ringtoneManager: RingtoneManager
|
||||
) : NotificationTray.SystemTray {
|
||||
|
||||
private var active = HashSet<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,
|
||||
@@ -58,6 +65,7 @@ class AndroidNotificationTray
|
||||
notificationManager.notify(Int.MAX_VALUE, summary)
|
||||
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||
notificationManager.notify(notificationId, notification)
|
||||
active.add(notificationId)
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -79,8 +87,7 @@ class AndroidNotificationTray
|
||||
val removeRepetitionAction = Action(
|
||||
R.drawable.ic_action_cancel,
|
||||
context.getString(R.string.no),
|
||||
pendingIntents.removeRepetition(habit)
|
||||
)
|
||||
pendingIntents.removeRepetition(habit))
|
||||
|
||||
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;
|
||||
|
||||
import android.content.*;
|
||||
import android.net.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.reminders.*;
|
||||
import org.isoron.uhabits.core.ui.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.applyTimezone;
|
||||
import static org.isoron.uhabits.core.utils.DateUtils.getLocalTime;
|
||||
|
||||
@ReceiverScope
|
||||
@AppScope
|
||||
public class ReminderController
|
||||
{
|
||||
@NonNull
|
||||
@@ -40,6 +42,7 @@ public class ReminderController
|
||||
@NonNull
|
||||
private final NotificationTray notificationTray;
|
||||
|
||||
@NonNull
|
||||
private Preferences preferences;
|
||||
|
||||
@Inject
|
||||
@@ -65,14 +68,25 @@ public class ReminderController
|
||||
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());
|
||||
long reminderTime = now + snoozeInterval * 60 * 1000;
|
||||
if (delay < 0)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -80,4 +94,19 @@ 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));
|
||||
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;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
import static android.content.ContentUris.*;
|
||||
|
||||
/**
|
||||
@@ -49,19 +48,15 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
private static final String TAG = "ReminderReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent)
|
||||
public void onReceive(@Nullable final Context context, @Nullable Intent intent)
|
||||
{
|
||||
HabitsApplication app =
|
||||
(HabitsApplication) context.getApplicationContext();
|
||||
if (context == null || intent == null) return;
|
||||
if (intent.getAction() == null) return;
|
||||
|
||||
ReminderComponent component = DaggerReminderReceiver_ReminderComponent
|
||||
.builder()
|
||||
.habitsApplicationComponent(app.getComponent())
|
||||
.build();
|
||||
|
||||
HabitList habits = app.getComponent().getHabitList();
|
||||
ReminderController reminderController =
|
||||
component.getReminderController();
|
||||
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()));
|
||||
|
||||
@@ -90,7 +85,7 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
|
||||
case ACTION_SNOOZE_REMINDER:
|
||||
if (habit == null) return;
|
||||
reminderController.onSnooze(habit);
|
||||
reminderController.onSnoozePressed(habit, context);
|
||||
break;
|
||||
|
||||
case Intent.ACTION_BOOT_COMPLETED:
|
||||
@@ -103,11 +98,4 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
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"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_notify"
|
||||
android:title="@string/reminder"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
@@ -35,6 +35,7 @@
|
||||
<item>@string/interval_4_hour</item>
|
||||
<item>@string/interval_8_hour</item>
|
||||
<item>@string/interval_24_hour</item>
|
||||
<item>@string/interval_always_ask</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="snooze_interval_values" translatable="false">
|
||||
@@ -45,8 +46,31 @@
|
||||
<item>240</item>
|
||||
<item>480</item>
|
||||
<item>1440</item>
|
||||
<item>-1</item>
|
||||
</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">
|
||||
<item>@string/every_day</item>
|
||||
<item>@string/every_week</item>
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
<string name="interval_4_hour">4 hours</string>
|
||||
<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>
|
||||
@@ -95,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>
|
||||
|
||||
@@ -70,9 +70,9 @@ public class ReminderControllerTest extends BaseAndroidJVMTest
|
||||
DateUtils.setFixedLocalTime(now);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,9 @@ package org.isoron.uhabits.core.models;
|
||||
import android.support.annotation.*;
|
||||
|
||||
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
|
||||
{
|
||||
@@ -56,6 +57,11 @@ public final class Reminder
|
||||
return minute;
|
||||
}
|
||||
|
||||
public long getTimeInMillis()
|
||||
{
|
||||
return DateUtils.getUpcomingTimeInMillis(hour, minute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
||||
@@ -24,9 +24,6 @@ import android.support.annotation.*;
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@@ -60,14 +57,17 @@ public class ReminderScheduler implements CommandRunner.Listener
|
||||
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.isArchived()) return;
|
||||
Reminder reminder = habit.getReminder();
|
||||
if (reminderTime == null) reminderTime = getReminderTime(reminder);
|
||||
long timestamp = getStartOfDay(removeTimezone(reminderTime));
|
||||
|
||||
sys.scheduleShowReminder(reminderTime, habit, timestamp);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ReminderScheduler implements CommandRunner.Listener
|
||||
HabitList reminderHabits =
|
||||
habitList.getFiltered(HabitMatcher.WITH_ALARM);
|
||||
for (Habit habit : reminderHabits)
|
||||
schedule(habit, null);
|
||||
schedule(habit);
|
||||
}
|
||||
|
||||
public void startListening()
|
||||
@@ -89,19 +89,11 @@ public class ReminderScheduler implements CommandRunner.Listener
|
||||
commandRunner.removeListener(this);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Long getReminderTime(@NonNull Reminder reminder)
|
||||
public void scheduleMinutesFromNow(Habit habit, long minutes)
|
||||
{
|
||||
Calendar calendar = DateUtils.getStartOfTodayCalendar();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, reminder.getHour());
|
||||
calendar.set(Calendar.MINUTE, reminder.getMinute());
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
Long time = calendar.getTimeInMillis();
|
||||
|
||||
if (DateUtils.getLocalTime() > time)
|
||||
time += DateUtils.DAY_LENGTH;
|
||||
|
||||
return applyTimezone(time);
|
||||
long now = applyTimezone(getLocalTime());
|
||||
long reminderTime = now + minutes * 60 * 1000;
|
||||
scheduleAtTime(habit, reminderTime);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
MONTH, WEEK_NUMBER, YEAR, QUARTER
|
||||
|
||||
Reference in New Issue
Block a user