Handled more feedback (Simplified WidgetBehavior class structure)

pull/499/head
Thomas S 5 years ago
parent 1d372a8fbb
commit e61e2a34e6

@ -1,69 +1,52 @@
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 lateinit var behavior : NumericalCheckmarkWidgetBehavior
private var data: IntentParser.CheckmarkIntentData? = null
private lateinit var widgetUpdater : WidgetUpdater
import android.app.*
import android.content.*
import android.os.*
import android.view.*
import android.widget.FrameLayout
import org.isoron.uhabits.*
import org.isoron.uhabits.activities.common.dialogs.*
import org.isoron.uhabits.core.ui.screens.habits.list.*
import org.isoron.uhabits.core.ui.widgets.*
import org.isoron.uhabits.intents.*
import org.isoron.uhabits.widgets.*
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
private lateinit var behavior: WidgetBehavior
private lateinit var data: IntentParser.CheckmarkIntentData
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)
setContentView(FrameLayout(this))
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)
behavior = WidgetBehavior(component.habitList, component.commandRunner, component.notificationTray)
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())
override fun onNumberPicked(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.
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()
numberPickerFactory.create(data!!.habit.checkmarks.today!!.value.toDouble() / 1000, "This is a test", this).show()
}
}
companion object{
companion object {
const val ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY = "org.isoron.uhabits.ACTION_SHOW_NUMERICAL_VALUE_ACTIVITY"
}
}

@ -1,27 +0,0 @@
package org.isoron.uhabits.core.ui.widgets;
import androidx.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;
}
}

@ -1,25 +0,0 @@
package org.isoron.uhabits.core.ui.widgets;
import androidx.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());
}
}

@ -27,9 +27,22 @@ import org.isoron.uhabits.core.ui.*;
import javax.inject.*;
public class WidgetBehavior extends BaseWidgetBehavior
public class WidgetBehavior
{
private HabitList getHabitList() {
return habitList;
}
@NonNull
private CommandRunner getCommandRunner() {
return commandRunner;
}
private HabitList habitList;
@NonNull
private final CommandRunner commandRunner;
private NotificationTray notificationTray;
@ -38,7 +51,8 @@ public class WidgetBehavior extends BaseWidgetBehavior
@NonNull CommandRunner commandRunner,
@NonNull NotificationTray notificationTray)
{
super(habitList, commandRunner);
this.habitList = habitList;
this.commandRunner = commandRunner;
this.notificationTray = notificationTray;
}
@ -69,4 +83,11 @@ public class WidgetBehavior extends BaseWidgetBehavior
new ToggleRepetitionCommand(getHabitList(), habit, timestamp),
habit.getId());
}
public void setNumericValue(@NonNull Habit habit, Timestamp timestamp, int newValue) {
getCommandRunner().execute(
new CreateRepetitionCommand(habit, timestamp, newValue),
habit.getId());
}
}

Loading…
Cancel
Save