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'
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
@@ -45,6 +46,9 @@ public class ShowHabitScreen extends BaseScreen
|
||||
@NonNull
|
||||
private final EditHabitDialogFactory editHabitDialogFactory;
|
||||
|
||||
@NonNull
|
||||
private final ConfirmDeleteDialogFactory confirmDeleteDialogFactory;
|
||||
|
||||
private final Lazy<ShowHabitBehavior> behavior;
|
||||
|
||||
@Inject
|
||||
@@ -52,8 +56,8 @@ public class ShowHabitScreen extends BaseScreen
|
||||
@NonNull Habit habit,
|
||||
@NonNull ShowHabitRootView view,
|
||||
@NonNull ShowHabitsMenu menu,
|
||||
@NonNull
|
||||
EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||
@NonNull Lazy<ShowHabitBehavior> behavior)
|
||||
{
|
||||
super(activity);
|
||||
@@ -63,6 +67,7 @@ public class ShowHabitScreen extends BaseScreen
|
||||
this.habit = habit;
|
||||
this.behavior = behavior;
|
||||
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||
view.setController(this);
|
||||
}
|
||||
|
||||
@@ -116,6 +121,19 @@ public class ShowHabitScreen extends BaseScreen
|
||||
{
|
||||
case 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();
|
||||
return true;
|
||||
|
||||
case R.id.action_delete:
|
||||
behavior.get().onDeleteHabit();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,15 @@ class PendingIntentFactory
|
||||
},
|
||||
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 =
|
||||
android.support.v4.app.TaskStackBuilder
|
||||
.create(context)
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.*
|
||||
import android.content.*
|
||||
import android.graphics.*
|
||||
import android.graphics.BitmapFactory.*
|
||||
import android.support.annotation.*
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.app.NotificationCompat.*
|
||||
import org.isoron.androidbase.*
|
||||
@@ -43,18 +44,39 @@ 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,
|
||||
notificationId: Int,
|
||||
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,
|
||||
context.getString(R.string.check),
|
||||
context.getString(R.string.yes),
|
||||
pendingIntents.addCheckmark(habit, timestamp))
|
||||
|
||||
val snoozeAction = Action(
|
||||
@@ -62,6 +84,11 @@ class AndroidNotificationTray
|
||||
context.getString(R.string.snooze),
|
||||
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)
|
||||
|
||||
// Even though the set of actions is the same on the phone and
|
||||
@@ -69,7 +96,8 @@ class AndroidNotificationTray
|
||||
// WearableExtender.
|
||||
val wearableExtender = WearableExtender()
|
||||
.setBackground(wearableBg)
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
|
||||
val builder = NotificationCompat.Builder(context)
|
||||
@@ -78,20 +106,32 @@ class AndroidNotificationTray
|
||||
.setContentText(habit.description)
|
||||
.setContentIntent(pendingIntents.showHabit(habit))
|
||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||
.addAction(checkAction)
|
||||
.addAction(addRepetitionAction)
|
||||
.addAction(removeRepetitionAction)
|
||||
.addAction(snoozeAction)
|
||||
.setSound(ringtoneManager.getURI())
|
||||
.extend(wearableExtender)
|
||||
.setWhen(reminderTime)
|
||||
.setShowWhen(true)
|
||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||
.setGroup("default")
|
||||
|
||||
if (preferences.shouldMakeNotificationsLed())
|
||||
builder.setLights(Color.RED, 1000, 1000)
|
||||
|
||||
val notificationManager = context.getSystemService(
|
||||
Activity.NOTIFICATION_SERVICE) as NotificationManager
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
@@ -38,30 +37,26 @@ import static android.content.ContentUris.*;
|
||||
public class ReminderReceiver extends BroadcastReceiver
|
||||
{
|
||||
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 =
|
||||
"org.isoron.uhabits.ACTION_SHOW_REMINDER";
|
||||
"org.isoron.uhabits.ACTION_SHOW_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";
|
||||
|
||||
@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()));
|
||||
|
||||
@@ -80,7 +75,7 @@ public class ReminderReceiver extends BroadcastReceiver
|
||||
case ACTION_SHOW_REMINDER:
|
||||
if (habit == null) return;
|
||||
reminderController.onShowReminder(habit,
|
||||
new Timestamp(timestamp), reminderTime);
|
||||
new Timestamp(timestamp), reminderTime);
|
||||
break;
|
||||
|
||||
case ACTION_DISMISS_REMINDER:
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_notify"
|
||||
android:title="@string/reminder"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
</menu>
|
||||
@@ -26,6 +26,11 @@
|
||||
android:title="@string/export"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_edit_habit"
|
||||
android:icon="?iconEdit"
|
||||
|
||||
@@ -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>
|
||||
@@ -225,4 +228,6 @@
|
||||
<string name="example_question_boolean">e.g. Did you exercise today?</string>
|
||||
<string name="question">Question</string>
|
||||
<string name="target">Target</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
</resources>
|
||||
@@ -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).scheduleMinutesFromNow(habit, 15L);
|
||||
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)
|
||||
{
|
||||
@@ -66,29 +72,29 @@ public final class Reminder
|
||||
Reminder reminder = (Reminder) o;
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(hour, reminder.hour)
|
||||
.append(minute, reminder.minute)
|
||||
.append(days, reminder.days)
|
||||
.isEquals();
|
||||
.append(hour, reminder.hour)
|
||||
.append(minute, reminder.minute)
|
||||
.append(days, reminder.days)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(hour)
|
||||
.append(minute)
|
||||
.append(days)
|
||||
.toHashCode();
|
||||
.append(hour)
|
||||
.append(minute)
|
||||
.append(days)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return new ToStringBuilder(this, defaultToStringStyle())
|
||||
.append("hour", hour)
|
||||
.append("minute", minute)
|
||||
.append("days", days)
|
||||
.toString();
|
||||
.append("hour", hour)
|
||||
.append("minute", minute)
|
||||
.append("days", days)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class MemoryHabitList extends HabitList
|
||||
@Override
|
||||
public synchronized Iterator<Habit> iterator()
|
||||
{
|
||||
return Collections.unmodifiableCollection(list).iterator();
|
||||
return new ArrayList<>(list).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.*;
|
||||
|
||||
@@ -55,19 +52,24 @@ public class ReminderScheduler implements CommandRunner.Listener
|
||||
public void onCommandExecuted(@NonNull Command command,
|
||||
@Nullable Long refreshKey)
|
||||
{
|
||||
if(command instanceof ToggleRepetitionCommand) return;
|
||||
if(command instanceof ChangeHabitColorCommand) return;
|
||||
if (command instanceof ToggleRepetitionCommand) return;
|
||||
if (command instanceof ChangeHabitColorCommand) return;
|
||||
scheduleAll();
|
||||
}
|
||||
|
||||
public void schedule(@NonNull Habit habit, @Nullable Long reminderTime)
|
||||
public void schedule(@NonNull Habit habit)
|
||||
{
|
||||
if (!habit.hasReminder()) return;
|
||||
if (habit.isArchived()) return;
|
||||
Reminder reminder = habit.getReminder();
|
||||
if (reminderTime == null) reminderTime = getReminderTime(reminder);
|
||||
long timestamp = getStartOfDay(removeTimezone(reminderTime));
|
||||
Long reminderTime = habit.getReminder().getTimeInMillis();
|
||||
scheduleAtTime(habit, 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);
|
||||
}
|
||||
|
||||
@@ -76,7 +78,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 +91,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
|
||||
|
||||
@@ -21,8 +21,10 @@ package org.isoron.uhabits.core.ui.screens.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -45,18 +47,23 @@ public class ShowHabitMenuBehavior
|
||||
@NonNull
|
||||
private System system;
|
||||
|
||||
@NonNull
|
||||
private CommandRunner commandRunner;
|
||||
|
||||
@Inject
|
||||
public ShowHabitMenuBehavior(@NonNull HabitList habitList,
|
||||
@NonNull Habit habit,
|
||||
@NonNull TaskRunner taskRunner,
|
||||
@NonNull Screen screen,
|
||||
@NonNull System system)
|
||||
@NonNull System system,
|
||||
@NonNull CommandRunner commandRunner)
|
||||
{
|
||||
this.habitList = habitList;
|
||||
this.habit = habit;
|
||||
this.taskRunner = taskRunner;
|
||||
this.screen = screen;
|
||||
this.system = system;
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
COULD_NOT_EXPORT
|
||||
COULD_NOT_EXPORT, HABIT_DELETED
|
||||
}
|
||||
|
||||
public interface Screen
|
||||
@@ -89,6 +107,11 @@ public class ShowHabitMenuBehavior
|
||||
void showMessage(Message m);
|
||||
|
||||
void showSendFileScreen(String filename);
|
||||
|
||||
void showDeleteConfirmationScreen(
|
||||
@NonNull OnConfirmedCallback callback);
|
||||
|
||||
void close();
|
||||
}
|
||||
|
||||
public interface System
|
||||
|
||||
@@ -48,14 +48,15 @@ public class WidgetBehavior
|
||||
|
||||
public void onAddRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
notificationTray.cancel(habit);
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep != null) return;
|
||||
performToggle(habit, timestamp);
|
||||
notificationTray.cancel(habit);
|
||||
}
|
||||
|
||||
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||
{
|
||||
notificationTray.cancel(habit);
|
||||
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
|
||||
if (rep == null) return;
|
||||
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
|
||||
{
|
||||
MONTH, WEEK_NUMBER, YEAR, QUARTER
|
||||
|
||||
@@ -118,7 +118,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
@Test
|
||||
public void testSchedule_withoutReminder()
|
||||
{
|
||||
reminderScheduler.schedule(habit, null);
|
||||
reminderScheduler.schedule(habit);
|
||||
Mockito.verifyZeroInteractions(sys);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
||||
long expectedCheckmarkTime,
|
||||
long expectedReminderTime)
|
||||
{
|
||||
reminderScheduler.schedule(habit, atTime);
|
||||
if(atTime == null) reminderScheduler.schedule(habit);
|
||||
else reminderScheduler.scheduleAtTime(habit, atTime);
|
||||
verify(sys).scheduleShowReminder(expectedReminderTime, habit,
|
||||
expectedCheckmarkTime);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ShowHabitMenuBehaviorTest extends BaseUnitTest
|
||||
|
||||
habit = fixtures.createShortHabit();
|
||||
menu = new ShowHabitMenuBehavior(habitList, habit, taskRunner, screen,
|
||||
system);
|
||||
system, commandRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user