mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Numerical habits: update notifications and detail screen (#627)
This commit is contained in:
@@ -26,9 +26,9 @@ import androidx.annotation.NonNull;
|
|||||||
import org.isoron.androidbase.activities.*;
|
import org.isoron.androidbase.activities.*;
|
||||||
import org.isoron.uhabits.*;
|
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.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||||
|
import org.isoron.uhabits.core.ui.screens.habits.list.*;
|
||||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.*;
|
||||||
|
|
||||||
@@ -54,6 +54,9 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final IntentFactory intentFactory;
|
private final IntentFactory intentFactory;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final NumberPickerFactory numberPickerFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ShowHabitScreen(@NonNull BaseActivity activity,
|
public ShowHabitScreen(@NonNull BaseActivity activity,
|
||||||
@NonNull Habit habit,
|
@NonNull Habit habit,
|
||||||
@@ -61,6 +64,7 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
@NonNull ShowHabitsMenu menu,
|
@NonNull ShowHabitsMenu menu,
|
||||||
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
@NonNull ConfirmDeleteDialogFactory confirmDeleteDialogFactory,
|
||||||
@NonNull IntentFactory intentFactory,
|
@NonNull IntentFactory intentFactory,
|
||||||
|
@NonNull NumberPickerFactory numberPickerFactory,
|
||||||
@NonNull Lazy<ShowHabitBehavior> behavior)
|
@NonNull Lazy<ShowHabitBehavior> behavior)
|
||||||
{
|
{
|
||||||
super(activity);
|
super(activity);
|
||||||
@@ -71,6 +75,7 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
this.behavior = behavior;
|
this.behavior = behavior;
|
||||||
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
this.confirmDeleteDialogFactory = confirmDeleteDialogFactory;
|
||||||
|
this.numberPickerFactory = numberPickerFactory;
|
||||||
view.setController(this);
|
view.setController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +85,14 @@ public class ShowHabitScreen extends BaseScreen
|
|||||||
behavior.get().onEditHistory();
|
behavior.get().onEditHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showNumberPicker(double value,
|
||||||
|
@NonNull String unit,
|
||||||
|
@NonNull ListHabitsBehavior.NumberPickerCallback callback)
|
||||||
|
{
|
||||||
|
numberPickerFactory.create(value, unit, callback).show();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToggleCheckmark(Timestamp timestamp, int value)
|
public void onToggleCheckmark(Timestamp timestamp, int value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -95,15 +95,17 @@ class AndroidNotificationTray
|
|||||||
context.getString(R.string.no),
|
context.getString(R.string.no),
|
||||||
pendingIntents.removeRepetition(habit))
|
pendingIntents.removeRepetition(habit))
|
||||||
|
|
||||||
|
val enterAction = Action(
|
||||||
|
R.drawable.ic_action_check,
|
||||||
|
context.getString(R.string.enter),
|
||||||
|
pendingIntents.setNumericalValue(context, habit, 0, null))
|
||||||
|
|
||||||
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
|
||||||
// on the watch, Pebble requires us to add them to the
|
// on the watch, Pebble requires us to add them to the
|
||||||
// WearableExtender.
|
// WearableExtender.
|
||||||
val wearableExtender = WearableExtender()
|
val wearableExtender = WearableExtender().setBackground(wearableBg)
|
||||||
.setBackground(wearableBg)
|
|
||||||
.addAction(addRepetitionAction)
|
|
||||||
.addAction(removeRepetitionAction)
|
|
||||||
|
|
||||||
val defaultText = context.getString(R.string.default_reminder_question)
|
val defaultText = context.getString(R.string.default_reminder_question)
|
||||||
val builder = Builder(context, REMINDERS_CHANNEL_ID)
|
val builder = Builder(context, REMINDERS_CHANNEL_ID)
|
||||||
@@ -112,13 +114,23 @@ class AndroidNotificationTray
|
|||||||
.setContentText(if(habit.question.isBlank()) defaultText else habit.question)
|
.setContentText(if(habit.question.isBlank()) defaultText else habit.question)
|
||||||
.setContentIntent(pendingIntents.showHabit(habit))
|
.setContentIntent(pendingIntents.showHabit(habit))
|
||||||
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
.setDeleteIntent(pendingIntents.dismissNotification(habit))
|
||||||
.addAction(addRepetitionAction)
|
|
||||||
.addAction(removeRepetitionAction)
|
|
||||||
.setSound(null)
|
.setSound(null)
|
||||||
.setWhen(reminderTime)
|
.setWhen(reminderTime)
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
.setOngoing(preferences.shouldMakeNotificationsSticky())
|
||||||
|
|
||||||
|
if (habit.isNumerical) {
|
||||||
|
wearableExtender.addAction(enterAction)
|
||||||
|
builder.addAction(enterAction)
|
||||||
|
} else {
|
||||||
|
wearableExtender
|
||||||
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
|
builder
|
||||||
|
.addAction(addRepetitionAction)
|
||||||
|
.addAction(removeRepetitionAction)
|
||||||
|
}
|
||||||
|
|
||||||
if (!disableSound)
|
if (!disableSound)
|
||||||
builder.setSound(ringtoneManager.getURI())
|
builder.setSound(ringtoneManager.getURI())
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.android.datetimepicker.time.TimePickerDialog;
|
|||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
import org.isoron.uhabits.receivers.*;
|
import org.isoron.uhabits.receivers.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -55,6 +56,8 @@ public class SnoozeDelayPickerActivity extends FragmentActivity
|
|||||||
dialog.getListView().setOnItemClickListener(this);
|
dialog.getListView().setOnItemClickListener(this);
|
||||||
dialog.setOnDismissListener(d -> finish());
|
dialog.setOnDismissListener(d -> finish());
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
|
SystemUtils.unlockScreen(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTimePicker()
|
private void showTimePicker()
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ public class WidgetReceiver extends BroadcastReceiver
|
|||||||
data.getTimestamp());
|
data.getTimestamp());
|
||||||
break;
|
break;
|
||||||
case ACTION_SET_NUMERICAL_VALUE:
|
case ACTION_SET_NUMERICAL_VALUE:
|
||||||
|
context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
||||||
Intent numberSelectorIntent = new Intent(context, NumericalCheckmarkWidgetActivity.class);
|
Intent numberSelectorIntent = new Intent(context, NumericalCheckmarkWidgetActivity.class);
|
||||||
numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
numberSelectorIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.isoron.uhabits.utils;
|
||||||
|
|
||||||
|
import android.app.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.os.*;
|
||||||
|
import android.view.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class SystemUtils
|
||||||
|
{
|
||||||
|
public static boolean isAndroidOOrLater()
|
||||||
|
{
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unlockScreen(Activity activity)
|
||||||
|
{
|
||||||
|
if (isAndroidOOrLater()) {
|
||||||
|
KeyguardManager km =
|
||||||
|
(KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
|
||||||
|
km.requestDismissKeyguard(activity, null);
|
||||||
|
} else {
|
||||||
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ import org.isoron.uhabits.activities.common.dialogs.*
|
|||||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||||
import org.isoron.uhabits.core.ui.widgets.*
|
import org.isoron.uhabits.core.ui.widgets.*
|
||||||
import org.isoron.uhabits.intents.*
|
import org.isoron.uhabits.intents.*
|
||||||
|
import org.isoron.uhabits.utils.*
|
||||||
import org.isoron.uhabits.widgets.*
|
import org.isoron.uhabits.widgets.*
|
||||||
|
|
||||||
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
|
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
|
||||||
@@ -51,6 +52,8 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
|||||||
component.notificationTray)
|
component.notificationTray)
|
||||||
widgetUpdater = component.widgetUpdater
|
widgetUpdater = component.widgetUpdater
|
||||||
showNumberSelector(this)
|
showNumberSelector(this)
|
||||||
|
|
||||||
|
SystemUtils.unlockScreen(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNumberPicked(newValue: Double) {
|
override fun onNumberPicked(newValue: Double) {
|
||||||
|
|||||||
@@ -194,6 +194,7 @@
|
|||||||
<string name="every_month">Every month</string>
|
<string name="every_month">Every month</string>
|
||||||
<string name="validation_cannot_be_blank">Cannot be blank</string>
|
<string name="validation_cannot_be_blank">Cannot be blank</string>
|
||||||
<string name="today">Today</string>
|
<string name="today">Today</string>
|
||||||
|
<string name="enter">Enter</string>
|
||||||
<string name="no_habits">No habits found</string>
|
<string name="no_habits">No habits found</string>
|
||||||
<string name="no_numerical_habits">No measurable habits found</string>
|
<string name="no_numerical_habits">No measurable habits found</string>
|
||||||
<string name="no_boolean_habits">No yes-or-no habits found</string>
|
<string name="no_boolean_habits">No yes-or-no habits found</string>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import androidx.annotation.*;
|
|||||||
|
|
||||||
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.ui.screens.habits.list.*;
|
||||||
|
|
||||||
import javax.inject.*;
|
import javax.inject.*;
|
||||||
|
|
||||||
@@ -58,12 +59,29 @@ public class ShowHabitBehavior
|
|||||||
|
|
||||||
public void onToggleCheckmark(Timestamp timestamp, int value)
|
public void onToggleCheckmark(Timestamp timestamp, int value)
|
||||||
{
|
{
|
||||||
|
if (habit.isNumerical()) {
|
||||||
|
CheckmarkList checkmarks = habit.getCheckmarks();
|
||||||
|
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
|
||||||
|
|
||||||
|
screen.showNumberPicker(oldValue / 1000, habit.getUnit(), newValue ->
|
||||||
|
{
|
||||||
|
newValue = Math.round(newValue * 1000);
|
||||||
|
commandRunner.execute(
|
||||||
|
new CreateRepetitionCommand(habitList, habit, timestamp, (int) newValue),
|
||||||
|
habit.getId());
|
||||||
|
});
|
||||||
|
} else {
|
||||||
commandRunner.execute(
|
commandRunner.execute(
|
||||||
new CreateRepetitionCommand(habitList, habit, timestamp, value), null);
|
new CreateRepetitionCommand(habitList, habit, timestamp, value), null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface Screen
|
public interface Screen
|
||||||
{
|
{
|
||||||
void showEditHistoryScreen();
|
void showEditHistoryScreen();
|
||||||
|
|
||||||
|
void showNumberPicker(double value,
|
||||||
|
@NonNull String unit,
|
||||||
|
@NonNull ListHabitsBehavior.NumberPickerCallback callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user