mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'dev' into feature/stackview
This commit is contained in:
@@ -19,6 +19,11 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion '26.0.2'
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.isoron.uhabits.*;
|
|||||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||||
import org.isoron.uhabits.activities.habits.edit.*;
|
import org.isoron.uhabits.activities.habits.edit.*;
|
||||||
import org.isoron.uhabits.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
|
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
@@ -45,6 +46,9 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final EditHabitDialogFactory editHabitDialogFactory;
|
private final EditHabitDialogFactory editHabitDialogFactory;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
||||||
|
|
||||||
private final Lazy<ShowHabitBehavior> behavior;
|
private final Lazy<ShowHabitBehavior> behavior;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -52,8 +56,8 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
@NonNull Habit habit,
|
@NonNull Habit habit,
|
||||||
@NonNull ShowHabitRootView view,
|
@NonNull ShowHabitRootView view,
|
||||||
@NonNull ShowHabitsMenu menu,
|
@NonNull ShowHabitsMenu menu,
|
||||||
@NonNull
|
@NonNull EditHabitDialogFactory editHabitDialogFactory,
|
||||||
EditHabitDialogFactory editHabitDialogFactory,
|
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||||
@NonNull Lazy<ShowHabitBehavior> behavior)
|
@NonNull Lazy<ShowHabitBehavior> behavior)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
@@ -63,6 +67,7 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.behavior = behavior;
|
this.behavior = behavior;
|
||||||
this.editHabitDialogFactory = editHabitDialogFactory;
|
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||||
|
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||||
view.setController(this);
|
view.setController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +121,19 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
{
|
{
|
||||||
case COULD_NOT_EXPORT:
|
case COULD_NOT_EXPORT:
|
||||||
showMessage(R.string.could_not_export);
|
showMessage(R.string.could_not_export);
|
||||||
|
|
||||||
|
case HABIT_DELETED:
|
||||||
|
showMessage(R.string.delete_habits_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showDeleteConfirmationScreen(@NonNull OnConfirmedCallback callback) {
|
||||||
|
activity.showDialog(confirmDeleteDialogFactory.create(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public class ShowHabitsMenu extends BaseMenu
|
|||||||
behavior.get().onExportCSV();
|
behavior.get().onExportCSV();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.action_delete:
|
||||||
|
behavior.get().onDeleteHabit();
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,15 @@ class PendingIntentFactory
|
|||||||
},
|
},
|
||||||
FLAG_UPDATE_CURRENT)
|
FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
|
fun removeRepetition(habit: Habit): PendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context, 3,
|
||||||
|
Intent(context, WidgetReceiver::class.java).apply {
|
||||||
|
action = WidgetReceiver.ACTION_REMOVE_REPETITION
|
||||||
|
data = Uri.parse(habit.uriString)
|
||||||
|
},
|
||||||
|
FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
fun showHabit(habit: Habit): PendingIntent =
|
fun showHabit(habit: Habit): PendingIntent =
|
||||||
android.support.v4.app.TaskStackBuilder
|
android.support.v4.app.TaskStackBuilder
|
||||||
.create(context)
|
.create(context)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.app.*
|
|||||||
import android.content.*
|
import android.content.*
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
import android.graphics.BitmapFactory.*
|
import android.graphics.BitmapFactory.*
|
||||||
|
import android.support.annotation.*
|
||||||
import android.support.v4.app.*
|
import android.support.v4.app.*
|
||||||
import android.support.v4.app.NotificationCompat.*
|
import android.support.v4.app.NotificationCompat.*
|
||||||
import org.isoron.androidbase.*
|
import org.isoron.androidbase.*
|
||||||
@@ -43,18 +44,39 @@ 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,
|
||||||
notificationId: Int,
|
notificationId: Int,
|
||||||
timestamp: Timestamp,
|
timestamp: Timestamp,
|
||||||
reminderTime: Long) {
|
reminderTime: Long)
|
||||||
|
{
|
||||||
|
val notificationManager = NotificationManagerCompat.from(context)
|
||||||
|
val summary = buildSummary(reminderTime)
|
||||||
|
notificationManager.notify(Int.MAX_VALUE, summary)
|
||||||
|
val notification = buildNotification(habit, reminderTime, timestamp)
|
||||||
|
notificationManager.notify(notificationId, notification)
|
||||||
|
active.add(notificationId)
|
||||||
|
}
|
||||||
|
|
||||||
val checkAction = Action(
|
@NonNull
|
||||||
|
fun buildNotification(@NonNull habit: Habit,
|
||||||
|
@NonNull reminderTime: Long,
|
||||||
|
@NonNull timestamp: Timestamp) : Notification
|
||||||
|
{
|
||||||
|
|
||||||
|
val addRepetitionAction = Action(
|
||||||
R.drawable.ic_action_check,
|
R.drawable.ic_action_check,
|
||||||
context.getString(R.string.check),
|
context.getString(R.string.yes),
|
||||||
pendingIntents.addCheckmark(habit, timestamp))
|
pendingIntents.addCheckmark(habit, timestamp))
|
||||||
|
|
||||||
val snoozeAction = Action(
|
val snoozeAction = Action(
|
||||||
@@ -62,6 +84,11 @@ class AndroidNotificationTray
|
|||||||
context.getString(R.string.snooze),
|
context.getString(R.string.snooze),
|
||||||
pendingIntents.snoozeNotification(habit))
|
pendingIntents.snoozeNotification(habit))
|
||||||
|
|
||||||
|
val removeRepetitionAction = Action(
|
||||||
|
R.drawable.ic_action_cancel,
|
||||||
|
context.getString(R.string.no),
|
||||||
|
pendingIntents.removeRepetition(habit))
|
||||||
|
|
||||||
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
val wearableBg = decodeResource(context.resources, R.drawable.stripe)
|
||||||
|
|
||||||
// Even though the set of actions is the same on the phone and
|
// Even though the set of actions is the same on the phone and
|
||||||
@@ -69,7 +96,8 @@ class AndroidNotificationTray
|
|||||||
// WearableExtender.
|
// WearableExtender.
|
||||||
val wearableExtender = WearableExtender()
|
val wearableExtender = WearableExtender()
|
||||||
.setBackground(wearableBg)
|
.setBackground(wearableBg)
|
||||||
.addAction(checkAction)
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
.addAction(snoozeAction)
|
.addAction(snoozeAction)
|
||||||
|
|
||||||
val builder = NotificationCompat.Builder(context)
|
val builder = NotificationCompat.Builder(context)
|
||||||
@@ -78,20 +106,32 @@ class AndroidNotificationTray
|
|||||||
.setContentText(habit.description)
|
.setContentText(habit.description)
|
||||||
.setContentIntent(pendingIntents.showHabit(habit))
|
.setContentIntent(pendingIntents.showHabit(habit))
|
||||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||||
.addAction(checkAction)
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
.addAction(snoozeAction)
|
.addAction(snoozeAction)
|
||||||
.setSound(ringtoneManager.getURI())
|
.setSound(ringtoneManager.getURI())
|
||||||
.extend(wearableExtender)
|
.extend(wearableExtender)
|
||||||
.setWhen(reminderTime)
|
.setWhen(reminderTime)
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||||
|
.setGroup("default")
|
||||||
|
|
||||||
if (preferences.shouldMakeNotificationsLed())
|
if (preferences.shouldMakeNotificationsLed())
|
||||||
builder.setLights(Color.RED, 1000, 1000)
|
builder.setLights(Color.RED, 1000, 1000)
|
||||||
|
|
||||||
val notificationManager = context.getSystemService(
|
return builder.build()
|
||||||
Activity.NOTIFICATION_SERVICE) as NotificationManager
|
}
|
||||||
|
|
||||||
notificationManager.notify(notificationId, builder.build())
|
@NonNull
|
||||||
|
private fun buildSummary(@NonNull reminderTime: Long) : Notification
|
||||||
|
{
|
||||||
|
return NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
|
.setWhen(reminderTime)
|
||||||
|
.setShowWhen(true)
|
||||||
|
.setGroup("default")
|
||||||
|
.setGroupSummary(true)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
HabitsApplication app = (HabitsApplication) context.getApplicationContext();
|
||||||
.builder()
|
HabitsApplicationComponent appComponent = app.getComponent();
|
||||||
.habitsApplicationComponent(app.getComponent())
|
HabitList habits = appComponent.getHabitList();
|
||||||
.build();
|
ReminderController reminderController = appComponent.getReminderController();
|
||||||
|
|
||||||
HabitList habits = app.getComponent().getHabitList();
|
|
||||||
ReminderController reminderController =
|
|
||||||
component.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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 266 B |
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 198 B |
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
BIN
uhabits-android/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 323 B |
Binary file not shown.
|
After Width: | Height: | Size: 531 B |
@@ -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>
|
||||||
@@ -26,6 +26,11 @@
|
|||||||
android:title="@string/export"
|
android:title="@string/export"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_delete"
|
||||||
|
android:title="@string/delete"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_edit_habit"
|
android:id="@+id/action_edit_habit"
|
||||||
android:icon="?iconEdit"
|
android:icon="?iconEdit"
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -225,4 +228,6 @@
|
|||||||
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||||
<string name="question">Question</string>
|
<string name="question">Question</string>
|
||||||
<string name="target">Target</string>
|
<string name="target">Target</string>
|
||||||
|
<string name="yes">Yes</string>
|
||||||
|
<string name="no">No</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -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).scheduleMinutesFromNow(habit, 15L);
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class MemoryHabitList extends HabitList
|
|||||||
@Override
|
@Override
|
||||||
public synchronized Iterator<Habit> iterator()
|
public synchronized Iterator<Habit> iterator()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableCollection(list).iterator();
|
return new ArrayList<>(list).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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.*;
|
||||||
|
|
||||||
@@ -55,19 +52,24 @@ public class ReminderScheduler implements CommandRunner.Listener
|
|||||||
public void onCommandExecuted(@NonNull Command command,
|
public void onCommandExecuted(@NonNull Command command,
|
||||||
@Nullable Long refreshKey)
|
@Nullable Long refreshKey)
|
||||||
{
|
{
|
||||||
if(command instanceof ToggleRepetitionCommand) return;
|
if (command instanceof ToggleRepetitionCommand) return;
|
||||||
if(command instanceof ChangeHabitColorCommand) return;
|
if (command instanceof ChangeHabitColorCommand) return;
|
||||||
scheduleAll();
|
scheduleAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)
|
public void schedule(@NonNull Habit habit)
|
||||||
{
|
{
|
||||||
if (!habit.hasReminder()) return;
|
if (!habit.hasReminder()) return;
|
||||||
if (habit.isArchived()) return;
|
Long reminderTime = habit.getReminder().getTimeInMillis();
|
||||||
Reminder reminder = habit.getReminder();
|
scheduleAtTime(habit, reminderTime);
|
||||||
if (reminderTime == null) reminderTime = getReminderTime(reminder);
|
}
|
||||||
long timestamp = getStartOfDay(removeTimezone(reminderTime));
|
|
||||||
|
|
||||||
|
public void scheduleAtTime(@NonNull Habit habit, @NonNull Long reminderTime)
|
||||||
|
{
|
||||||
|
if (reminderTime == null) throw new IllegalArgumentException();
|
||||||
|
if (!habit.hasReminder()) return;
|
||||||
|
if (habit.isArchived()) return;
|
||||||
|
long timestamp = getStartOfDay(removeTimezone(reminderTime));
|
||||||
sys.scheduleShowReminder(reminderTime, habit, timestamp);
|
sys.scheduleShowReminder(reminderTime, habit, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +78,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 +91,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
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ package org.isoron.uhabits.core.ui.screens.habits.show;
|
|||||||
|
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.core.commands.*;
|
||||||
import org.isoron.uhabits.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
import org.isoron.uhabits.core.tasks.*;
|
import org.isoron.uhabits.core.tasks.*;
|
||||||
|
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -45,18 +47,23 @@ public class ShowHabitMenuBehavior
|
|||||||
@NonNull
|
@NonNull
|
||||||
private System system;
|
private System system;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private CommandRunner commandRunner;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ShowHabitMenuBehavior(@NonNull HabitList habitList,
|
public ShowHabitMenuBehavior(@NonNull HabitList habitList,
|
||||||
@NonNull Habit habit,
|
@NonNull Habit habit,
|
||||||
@NonNull TaskRunner taskRunner,
|
@NonNull TaskRunner taskRunner,
|
||||||
@NonNull Screen screen,
|
@NonNull Screen screen,
|
||||||
@NonNull System system)
|
@NonNull System system,
|
||||||
|
@NonNull CommandRunner commandRunner)
|
||||||
{
|
{
|
||||||
this.habitList = habitList;
|
this.habitList = habitList;
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.taskRunner = taskRunner;
|
this.taskRunner = taskRunner;
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
this.system = system;
|
this.system = system;
|
||||||
|
this.commandRunner = commandRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEditHabit()
|
public void onEditHabit()
|
||||||
@@ -77,9 +84,20 @@ public class ShowHabitMenuBehavior
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDeleteHabit()
|
||||||
|
{
|
||||||
|
List<Habit> selected = Collections.singletonList(habit);
|
||||||
|
|
||||||
|
screen.showDeleteConfirmationScreen(() -> {
|
||||||
|
commandRunner.execute(new DeleteHabitsCommand(habitList, selected),
|
||||||
|
null);
|
||||||
|
screen.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public enum Message
|
public enum Message
|
||||||
{
|
{
|
||||||
COULD_NOT_EXPORT
|
COULD_NOT_EXPORT, HABIT_DELETED
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Screen
|
public interface Screen
|
||||||
@@ -89,6 +107,11 @@ public class ShowHabitMenuBehavior
|
|||||||
void showMessage(Message m);
|
void showMessage(Message m);
|
||||||
|
|
||||||
void showSendFileScreen(String filename);
|
void showSendFileScreen(String filename);
|
||||||
|
|
||||||
|
void showDeleteConfirmationScreen(
|
||||||
|
@NonNull OnConfirmedCallback callback);
|
||||||
|
|
||||||
|
void close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface System
|
public interface System
|
||||||
|
|||||||
@@ -48,14 +48,15 @@ public class WidgetBehavior
|
|||||||
|
|
||||||
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
|
notificationTray.cancel(habit);
|
||||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||||
if (rep != null) return;
|
if (rep != null) return;
|
||||||
performToggle(habit, timestamp);
|
performToggle(habit, timestamp);
|
||||||
notificationTray.cancel(habit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
|
notificationTray.cancel(habit);
|
||||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||||
if (rep == null) return;
|
if (rep == null) return;
|
||||||
performToggle(habit, timestamp);
|
performToggle(habit, timestamp);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testSchedule_withoutReminder()
|
public void testSchedule_withoutReminder()
|
||||||
{
|
{
|
||||||
reminderScheduler.schedule(habit, null);
|
reminderScheduler.schedule(habit);
|
||||||
Mockito.verifyZeroInteractions(sys);
|
Mockito.verifyZeroInteractions(sys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,8 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
long expectedCheckmarkTime,
|
long expectedCheckmarkTime,
|
||||||
long expectedReminderTime)
|
long expectedReminderTime)
|
||||||
{
|
{
|
||||||
reminderScheduler.schedule(habit, atTime);
|
if(atTime == null) reminderScheduler.schedule(habit);
|
||||||
|
else reminderScheduler.scheduleAtTime(habit, atTime);
|
||||||
verify(sys).scheduleShowReminder(expectedReminderTime, habit,
|
verify(sys).scheduleShowReminder(expectedReminderTime, habit,
|
||||||
expectedCheckmarkTime);
|
expectedCheckmarkTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class ShowHabitMenuBehaviorTest extends BaseUnitTest
|
|||||||
|
|
||||||
habit = fixtures.createShortHabit();
|
habit = fixtures.createShortHabit();
|
||||||
menu = new ShowHabitMenuBehavior(habitList, habit, taskRunner, screen,
|
menu = new ShowHabitMenuBehavior(habitList, habit, taskRunner, screen,
|
||||||
system);
|
system, commandRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user