- *
- * This file is part of Loop Habit Tracker.
- *
- * Loop Habit Tracker is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * Loop Habit Tracker is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see .
- */
-
-package org.isoron.uhabits.receivers;
-
-import android.content.*;
-import android.util.*;
-
-import org.isoron.uhabits.*;
-import org.isoron.uhabits.core.preferences.*;
-import org.isoron.uhabits.core.ui.widgets.*;
-import org.isoron.uhabits.intents.*;
-import org.isoron.uhabits.sync.*;
-
-import dagger.*;
-
-/**
- * The Android BroadcastReceiver for Loop Habit Tracker.
- *
- * All broadcast messages are received and processed by this class.
- */
-public class WidgetReceiver extends BroadcastReceiver
-{
- public static final String ACTION_ADD_REPETITION =
- "org.isoron.uhabits.ACTION_ADD_REPETITION";
-
- public static final String ACTION_DISMISS_REMINDER =
- "org.isoron.uhabits.ACTION_DISMISS_REMINDER";
-
- public static final String ACTION_REMOVE_REPETITION =
- "org.isoron.uhabits.ACTION_REMOVE_REPETITION";
-
- public static final String ACTION_TOGGLE_REPETITION =
- "org.isoron.uhabits.ACTION_TOGGLE_REPETITION";
-
- public static final String ACTION_SET_NUMERICAL_VALUE =
- "org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE";
-
- @Override
- public void onReceive(final Context context, Intent intent)
- {
- HabitsApplication app =
- (HabitsApplication) context.getApplicationContext();
-
- WidgetComponent component = DaggerWidgetReceiver_WidgetComponent
- .builder()
- .habitsApplicationComponent(app.getComponent())
- .build();
-
- IntentParser parser = app.getComponent().getIntentParser();
- WidgetBehavior controller = component.getWidgetController();
- Preferences prefs = app.getComponent().getPreferences();
-
- if(prefs.isSyncEnabled())
- context.startService(new Intent(context, SyncService.class));
-
- try
- {
- IntentParser.CheckmarkIntentData data;
- data = parser.parseCheckmarkIntent(intent);
-
- switch (intent.getAction())
- {
- case ACTION_ADD_REPETITION:
- controller.onAddRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_TOGGLE_REPETITION:
- controller.onToggleRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_REMOVE_REPETITION:
- controller.onRemoveRepetition(data.getHabit(),
- data.getTimestamp());
- break;
-
- case ACTION_SET_NUMERICAL_VALUE:
- //controller.onToggleRepetition(data.getHabit(),
- // data.getTimestamp());
- break;
- }
- }
- catch (RuntimeException e)
- {
- Log.e("WidgetReceiver", "could not process intent", e);
- }
- }
-
- @ReceiverScope
- @Component(dependencies = HabitsApplicationComponent.class)
- interface WidgetComponent
- {
- WidgetBehavior getWidgetController();
- }
-}
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt
new file mode 100644
index 000000000..9721f2af1
--- /dev/null
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/receivers/WidgetReceiver.kt
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2016 Álinson Santos Xavier
+ *
+ * This file is part of Loop Habit Tracker.
+ *
+ * Loop Habit Tracker is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Loop Habit Tracker is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+package org.isoron.uhabits.receivers
+
+import android.content.*
+import android.util.*
+
+import org.isoron.uhabits.*
+import org.isoron.uhabits.core.preferences.*
+import org.isoron.uhabits.core.ui.widgets.*
+import org.isoron.uhabits.intents.*
+import org.isoron.uhabits.sync.*
+
+import dagger.*
+import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
+import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
+import org.isoron.uhabits.widgets.activities.NumericalCheckmarkWidgetActivity
+import android.content.Intent
+
+
+
+/**
+ * The Android BroadcastReceiver for Loop Habit Tracker.
+ *
+ *
+ * All broadcast messages are received and processed by this class.
+ */
+class WidgetReceiver : BroadcastReceiver() {
+
+ override fun onReceive(context: Context, intent: Intent) {
+ val app = context.applicationContext as HabitsApplication
+
+ val component = DaggerWidgetReceiver_WidgetComponent
+ .builder()
+ .habitsApplicationComponent(app.component)
+ .build()
+
+ val parser = app.component.intentParser
+ val controller = component.widgetController
+ val prefs = app.component.preferences
+
+ if (prefs.isSyncEnabled)
+ context.startService(Intent(context, SyncService::class.java))
+
+ try {
+ val data: IntentParser.CheckmarkIntentData = parser.parseCheckmarkIntent(intent)
+
+ when (intent.action) {
+ ACTION_ADD_REPETITION -> controller.onAddRepetition(data.habit, data.timestamp)
+
+ ACTION_TOGGLE_REPETITION -> controller.onToggleRepetition(data.habit, data.timestamp)
+
+ ACTION_REMOVE_REPETITION -> controller.onRemoveRepetition(data.habit, data.timestamp)
+
+ ACTION_SET_NUMERICAL_VALUE -> {
+ val numberSelectorIntent = Intent(context, NumericalCheckmarkWidgetActivity::class.java)
+ numberSelectorIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
+ numberSelectorIntent.action = NumericalCheckmarkWidgetActivity.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY
+ parser.copyIntentData(intent,numberSelectorIntent)//give the habit and timestamp data to the numericalCheckmarkWidgetActivity
+ context.startActivity(numberSelectorIntent)
+ }
+ }
+ } catch (e: RuntimeException) {
+ Log.e("WidgetReceiver", "could not process intent", e)
+ }
+
+ }
+
+
+
+
+ @ReceiverScope
+ @Component(dependencies = [HabitsApplicationComponent::class])
+ internal interface WidgetComponent {
+ val widgetController: WidgetBehavior
+ }
+
+ companion object {
+ val ACTION_ADD_REPETITION = "org.isoron.uhabits.ACTION_ADD_REPETITION"
+
+ val ACTION_DISMISS_REMINDER = "org.isoron.uhabits.ACTION_DISMISS_REMINDER"
+
+ val ACTION_REMOVE_REPETITION = "org.isoron.uhabits.ACTION_REMOVE_REPETITION"
+
+ val ACTION_TOGGLE_REPETITION = "org.isoron.uhabits.ACTION_TOGGLE_REPETITION"
+
+ val ACTION_SET_NUMERICAL_VALUE = "org.isoron.uhabits.ACTION_SET_NUMERICAL_VALUE"
+ }
+}
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java
index 41405276a..9263035e6 100644
--- a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java
@@ -40,7 +40,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
private WidgetPreferences widgetPrefs;
- public static void updateAppWidget(@NonNull AppWidgetManager manager,
+ public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager manager,
@NonNull BaseWidget widget)
{
RemoteViews landscape = widget.getLandscapeRemoteViews();
@@ -83,7 +83,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
BaseWidget widget = getWidgetFromId(context, widgetId);
WidgetDimensions dims = getDimensionsFromOptions(context, options);
widget.setDimensions(dims);
- updateAppWidget(manager, widget);
+ updateAppWidget(context, manager, widget);
}
catch (RuntimeException e)
{
@@ -179,7 +179,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
Bundle options = manager.getAppWidgetOptions(widgetId);
widget.setDimensions(getDimensionsFromOptions(context, options));
- updateAppWidget(manager, widget);
+ updateAppWidget(context, manager, widget);
}
catch (RuntimeException e)
{
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/NumericalCheckmarkWidget.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/NumericalCheckmarkWidget.kt
index 7d921cebe..e17de3cf1 100644
--- a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/NumericalCheckmarkWidget.kt
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/NumericalCheckmarkWidget.kt
@@ -2,8 +2,15 @@ package org.isoron.uhabits.widgets
import android.app.PendingIntent
import android.content.Context
+import android.content.Intent
+import android.util.Log
import android.view.View
import org.isoron.uhabits.core.models.Habit
+import org.isoron.uhabits.receivers.WidgetReceiver
+import org.isoron.uhabits.receivers.WidgetReceiver.Companion.ACTION_SET_NUMERICAL_VALUE
+import org.isoron.uhabits.utils.PaletteUtils
+import org.isoron.uhabits.widgets.activities.NumericalCheckmarkWidgetActivity
+import org.isoron.uhabits.widgets.views.CheckmarkWidgetView
import org.isoron.uhabits.widgets.views.NumericalCheckmarkWidgetView
class NumericalCheckmarkWidget(context: Context, widgetId: Int, habit: Habit) : CheckmarkWidget(context, widgetId, habit) {
@@ -11,12 +18,25 @@ class NumericalCheckmarkWidget(context: Context, widgetId: Int, habit: Habit) :
private lateinit var view: NumericalCheckmarkWidgetView
override fun getOnClickPendingIntent(context: Context): PendingIntent {
- view.showNumberSelector()
- return pendingIntentFactory.setNumericalValue(habit, 10,null)
+ return pendingIntentFactory.setNumericalValue(context, habit, 10,null)
}
override fun buildView(): View {
view = NumericalCheckmarkWidgetView(context)
return view;
}
+
+ override fun refreshData(v: View) {
+ (v as NumericalCheckmarkWidgetView).apply {
+ Log.d("NumericalChckmarkWidget", "Refreshing data")
+ setPercentage(habit.scores.todayValue.toFloat())
+ setActiveColor(PaletteUtils.getColor(context, habit.color))
+ setName(habit.name)
+ setCheckmarkValue(habit.checkmarks.todayValue)
+ refresh()
+ }
+
+
+ }
+
}
\ No newline at end of file
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivity.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivity.kt
new file mode 100644
index 000000000..b6b512d64
--- /dev/null
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivity.kt
@@ -0,0 +1,74 @@
+package org.isoron.uhabits.widgets.activities
+
+import android.app.Activity
+import android.appwidget.AppWidgetManager
+import org.isoron.uhabits.R
+import android.content.Context
+import android.os.Bundle
+import android.view.Window
+import org.isoron.androidbase.AppContextModule
+import org.isoron.uhabits.HabitsApplication
+import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
+import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
+import org.isoron.uhabits.core.ui.widgets.NumericalCheckmarkWidgetBehavior
+import org.isoron.uhabits.intents.IntentFactory
+import org.isoron.uhabits.intents.IntentParser
+import org.isoron.uhabits.intents.PendingIntentFactory
+import org.isoron.uhabits.widgets.WidgetUpdater
+
+
+class NumericalCheckmarkWidgetActivity : Activity() {
+
+ //private var activityComponent : NumericalCheckmarkWidgetActivityComponent? = null
+ private lateinit var behavior : NumericalCheckmarkWidgetBehavior
+ private var data: IntentParser.CheckmarkIntentData? = null
+ private lateinit var widgetUpdater : WidgetUpdater
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ requestWindowFeature(Window.FEATURE_NO_TITLE)
+ setContentView(R.layout.widget_checkmark_number_screen)
+ val app = this.applicationContext as HabitsApplication
+ val component = app.component
+ val parser = app.component.intentParser
+ data = parser.parseCheckmarkIntent(intent)
+ behavior = NumericalCheckmarkWidgetBehavior(component.habitList,component.commandRunner)
+ widgetUpdater = component.widgetUpdater
+ showNumberSelector(this)
+ }
+
+
+ class CallBackReceiver : ListHabitsBehavior.NumberPickerCallback{
+
+ private val activity : NumericalCheckmarkWidgetActivity
+
+ constructor(activity: NumericalCheckmarkWidgetActivity){
+ this.activity=activity
+
+ }
+
+ override fun onNumberPicked(newValue: Double) {
+ activity.saveNewNumer(newValue)
+ }
+ }
+
+ fun saveNewNumer(newValue: Double){
+ behavior.setNumericValue(data!!.habit,data!!.timestamp,(newValue*1000).toInt())
+ widgetUpdater.updateWidgets()
+ finish()
+ }
+
+
+ fun showNumberSelector(context: Context) {
+ var localData = data
+ if(behavior!=null && localData!=null) {//if a blank screen shows up without a popup when pressing the widget, you should check if this check passes.
+ val numberPickerFactory = NumberPickerFactory(context)
+ numberPickerFactory.create( data!!.habit.checkmarks.today!!.value.toDouble()/1000, "This is a test", CallBackReceiver(this)).show()
+ }
+ }
+
+ companion object{
+ val ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY"
+ }
+
+}
\ No newline at end of file
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivityComponent.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivityComponent.java
new file mode 100644
index 000000000..3f80e0a0c
--- /dev/null
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/activities/NumericalCheckmarkWidgetActivityComponent.java
@@ -0,0 +1,37 @@
+package org.isoron.uhabits.widgets.activities;
+
+import android.content.Context;
+
+import org.isoron.androidbase.AppContext;
+import org.isoron.androidbase.AppContextModule;
+import org.isoron.uhabits.HabitsModule;
+import org.isoron.uhabits.core.AppScope;
+import org.isoron.uhabits.core.commands.CommandRunner;
+import org.isoron.uhabits.core.models.HabitList;
+import org.isoron.uhabits.core.preferences.Preferences;
+import org.isoron.uhabits.core.tasks.TaskRunner;
+import org.isoron.uhabits.core.ui.widgets.NumericalCheckmarkWidgetBehavior;
+import org.isoron.uhabits.tasks.AndroidTaskRunner;
+
+import dagger.Component;
+
+@AppScope
+@Component(modules = {
+ AppContextModule.class,
+ HabitsModule.class,
+ AndroidTaskRunner.class,
+})
+public interface NumericalCheckmarkWidgetActivityComponent {
+ NumericalCheckmarkWidgetBehavior getNumericalCheckmarkWidgetBehavior();
+
+ CommandRunner getCommandRunner();
+
+ @AppContext
+ Context getContext();
+
+ HabitList getHabitList();
+
+ Preferences getPreferences();
+
+ TaskRunner getTaskRunner();
+}
diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/NumericalCheckmarkWidgetView.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/NumericalCheckmarkWidgetView.kt
index e17bf6240..d102fd697 100644
--- a/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/NumericalCheckmarkWidgetView.kt
+++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/widgets/views/NumericalCheckmarkWidgetView.kt
@@ -13,8 +13,6 @@ import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
- private var callBackReciever : CallBackReciever = CallBackReciever()
-
constructor(context: Context) : super(context) {}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
@@ -52,16 +50,4 @@ class NumericalCheckmarkWidgetView : CheckmarkWidgetView {
postInvalidate()
}
- class CallBackReciever : ListHabitsBehavior.NumberPickerCallback{
- override fun onNumberPicked(newValue: Double) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- }
-
- fun showNumberSelector() {
- val numberPickerFactory = NumberPickerFactory(context)
- numberPickerFactory.create(1000.0, "This is a test", callBackReciever).show()
- }
-
}
diff --git a/android/uhabits-android/src/main/res/layout/widget_checkmark_number_screen.xml b/android/uhabits-android/src/main/res/layout/widget_checkmark_number_screen.xml
new file mode 100644
index 000000000..c5ae9d514
--- /dev/null
+++ b/android/uhabits-android/src/main/res/layout/widget_checkmark_number_screen.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/CreateRepetitionCommand.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/CreateRepetitionCommand.java
index 1857304a5..417a4127b 100644
--- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/CreateRepetitionCommand.java
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/CreateRepetitionCommand.java
@@ -62,6 +62,7 @@ public class CreateRepetitionCommand extends Command
reps.add(newRep);
habit.invalidateNewerThan(timestamp);
+
}
@NonNull
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/UpdateHabitCommand.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/UpdateHabitCommand.java
new file mode 100644
index 000000000..71bde8433
--- /dev/null
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/commands/UpdateHabitCommand.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 Álinson Santos Xavier
+ *
+ * This file is part of Loop Habit Tracker.
+ *
+ * Loop Habit Tracker is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Loop Habit Tracker is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+package org.isoron.uhabits.core.commands;
+
+import android.support.annotation.NonNull;
+
+import org.isoron.uhabits.core.models.Habit;
+import org.isoron.uhabits.core.models.HabitList;
+import org.isoron.uhabits.core.models.HabitNotFoundException;
+
+
+
+/**
+ * Command to update a habit.
+ */
+public class UpdateHabitCommand extends Command
+{
+ @NonNull
+ private HabitList list;
+
+ @NonNull
+ final Habit habit;
+
+ public UpdateHabitCommand(@NonNull HabitList list,
+ @NonNull Habit habit)
+ {
+ super();
+ this.list = list;
+ this.habit = habit;
+ }
+
+ @Override
+ public void execute()
+ {
+ list.update(habit);
+ }
+
+ @NonNull
+ public Habit getHabit()
+ {
+ return habit;
+ }
+
+ @Override
+ @NonNull
+ public Record toRecord()
+ {
+ return new Record(this);
+ }
+
+ @Override
+ public void undo()
+ {
+ throw new RuntimeException("Update command cannot be undone");
+ }
+
+ public static class Record
+ {
+ @NonNull
+ public String id;
+
+ @NonNull
+ public String event = "Update";
+
+ public long habit;
+
+ public Record(@NonNull UpdateHabitCommand command)
+ {
+ id = command.getId();
+ Long habitId = command.habit.getId();
+ if (habitId == null) throw new RuntimeException("Habit not saved");
+
+ this.habit = habitId;
+ }
+
+ public UpdateHabitCommand toCommand(@NonNull HabitList habitList)
+ {
+ Habit h = habitList.getById(habit);
+ if (h == null) throw new HabitNotFoundException();
+
+ UpdateHabitCommand command;
+ command = new UpdateHabitCommand(
+ habitList, h);
+ command.setId(id);
+ return command;
+ }
+ }
+}
\ No newline at end of file
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/preferences/Preferences.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/preferences/Preferences.java
index 7cb013a4d..20ab46d2d 100644
--- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/preferences/Preferences.java
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/preferences/Preferences.java
@@ -206,7 +206,7 @@ public class Preferences
public boolean isDeveloper()
{
- return storage.getBoolean("pref_developer", false);
+ return true;//return storage.getBoolean("pref_developer", false);
}
public void setDeveloper(boolean isDeveloper)
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/BaseWidgetBehavior.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/BaseWidgetBehavior.java
new file mode 100644
index 000000000..39b483c8e
--- /dev/null
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/BaseWidgetBehavior.java
@@ -0,0 +1,27 @@
+package org.isoron.uhabits.core.ui.widgets;
+
+import android.support.annotation.NonNull;
+
+import org.isoron.uhabits.core.commands.CommandRunner;
+import org.isoron.uhabits.core.models.HabitList;
+
+public class BaseWidgetBehavior {
+ protected HabitList getHabitList() {
+ return habitList;
+ }
+
+ @NonNull
+ protected CommandRunner getCommandRunner() {
+ return commandRunner;
+ }
+
+ private HabitList habitList;
+
+ @NonNull
+ private final CommandRunner commandRunner;
+
+ public BaseWidgetBehavior(HabitList habitList, @NonNull CommandRunner commandRunner) {
+ this.habitList = habitList;
+ this.commandRunner = commandRunner;
+ }
+}
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/NumericalCheckmarkWidgetBehavior.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/NumericalCheckmarkWidgetBehavior.java
new file mode 100644
index 000000000..1b9d70c69
--- /dev/null
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/NumericalCheckmarkWidgetBehavior.java
@@ -0,0 +1,25 @@
+package org.isoron.uhabits.core.ui.widgets;
+
+import android.support.annotation.NonNull;
+
+import org.isoron.uhabits.core.commands.CommandRunner;
+import org.isoron.uhabits.core.commands.CreateRepetitionCommand;
+import org.isoron.uhabits.core.models.Habit;
+import org.isoron.uhabits.core.models.HabitList;
+import org.isoron.uhabits.core.models.Timestamp;
+
+import javax.inject.Inject;
+
+public class NumericalCheckmarkWidgetBehavior extends BaseWidgetBehavior{
+ @Inject
+ public NumericalCheckmarkWidgetBehavior(@NonNull HabitList habitList,
+ @NonNull CommandRunner commandRunner){
+ super(habitList, commandRunner);
+ }
+
+ public void setNumericValue(@NonNull Habit habit, Timestamp timestamp, int newValue) {
+ getCommandRunner().execute(
+ new CreateRepetitionCommand(habit, timestamp, newValue),
+ habit.getId());
+ }
+}
diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java
index d3aa800af..9ef8684ef 100644
--- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java
+++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java
@@ -27,12 +27,9 @@ import org.isoron.uhabits.core.ui.*;
import javax.inject.*;
-public class WidgetBehavior
+public class WidgetBehavior extends BaseWidgetBehavior
{
- private HabitList habitList;
- @NonNull
- private final CommandRunner commandRunner;
private NotificationTray notificationTray;
@@ -41,8 +38,7 @@ public class WidgetBehavior
@NonNull CommandRunner commandRunner,
@NonNull NotificationTray notificationTray)
{
- this.habitList = habitList;
- this.commandRunner = commandRunner;
+ super(habitList, commandRunner);
this.notificationTray = notificationTray;
}
@@ -69,8 +65,15 @@ public class WidgetBehavior
private void performToggle(@NonNull Habit habit, Timestamp timestamp)
{
- commandRunner.execute(
- new ToggleRepetitionCommand(habitList, habit, timestamp),
+ getCommandRunner().execute(
+ new ToggleRepetitionCommand(getHabitList(), habit, timestamp),
habit.getId());
}
+
+ public void updateWidget(@NonNull Habit habit)
+ {
+ getCommandRunner().execute(
+ new UpdateHabitCommand(getHabitList(), habit),
+ habit.getId());
+ }
}