mirror of https://github.com/iSoron/uhabits.git
parent
1d372a8fbb
commit
e61e2a34e6
@ -1,69 +1,52 @@
|
|||||||
package org.isoron.uhabits.widgets.activities
|
package org.isoron.uhabits.widgets.activities
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.*
|
||||||
import android.appwidget.AppWidgetManager
|
import android.content.*
|
||||||
import org.isoron.uhabits.R
|
import android.os.*
|
||||||
import android.content.Context
|
import android.view.*
|
||||||
import android.os.Bundle
|
import android.widget.FrameLayout
|
||||||
import android.view.Window
|
import org.isoron.uhabits.*
|
||||||
import org.isoron.androidbase.AppContextModule
|
import org.isoron.uhabits.activities.common.dialogs.*
|
||||||
import org.isoron.uhabits.HabitsApplication
|
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
import org.isoron.uhabits.core.ui.widgets.*
|
||||||
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
|
import org.isoron.uhabits.intents.*
|
||||||
import org.isoron.uhabits.core.ui.widgets.NumericalCheckmarkWidgetBehavior
|
import org.isoron.uhabits.widgets.*
|
||||||
import org.isoron.uhabits.intents.IntentFactory
|
|
||||||
import org.isoron.uhabits.intents.IntentParser
|
class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPickerCallback {
|
||||||
import org.isoron.uhabits.intents.PendingIntentFactory
|
|
||||||
import org.isoron.uhabits.widgets.WidgetUpdater
|
private lateinit var behavior: WidgetBehavior
|
||||||
|
private lateinit var data: IntentParser.CheckmarkIntentData
|
||||||
class NumericalCheckmarkWidgetActivity : Activity() {
|
private lateinit var widgetUpdater: WidgetUpdater
|
||||||
|
|
||||||
private lateinit var behavior : NumericalCheckmarkWidgetBehavior
|
|
||||||
private var data: IntentParser.CheckmarkIntentData? = null
|
|
||||||
private lateinit var widgetUpdater : WidgetUpdater
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
setContentView(R.layout.widget_checkmark_number_screen)
|
setContentView(FrameLayout(this))
|
||||||
val app = this.applicationContext as HabitsApplication
|
val app = this.applicationContext as HabitsApplication
|
||||||
val component = app.component
|
val component = app.component
|
||||||
val parser = app.component.intentParser
|
val parser = app.component.intentParser
|
||||||
data = parser.parseCheckmarkIntent(intent)
|
data = parser.parseCheckmarkIntent(intent)
|
||||||
behavior = NumericalCheckmarkWidgetBehavior(component.habitList,component.commandRunner)
|
behavior = WidgetBehavior(component.habitList, component.commandRunner, component.notificationTray)
|
||||||
widgetUpdater = component.widgetUpdater
|
widgetUpdater = component.widgetUpdater
|
||||||
showNumberSelector(this)
|
showNumberSelector(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
class CallBackReceiver : ListHabitsBehavior.NumberPickerCallback{
|
|
||||||
|
|
||||||
private val activity : NumericalCheckmarkWidgetActivity
|
|
||||||
|
|
||||||
constructor(activity: NumericalCheckmarkWidgetActivity){
|
|
||||||
this.activity=activity
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNumberPicked(newValue: Double) {
|
override fun onNumberPicked(newValue: Double) {
|
||||||
activity.saveNewNumer(newValue)
|
behavior.setNumericValue(data!!.habit, data!!.timestamp, (newValue * 1000).toInt())
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveNewNumer(newValue: Double){
|
|
||||||
behavior.setNumericValue(data!!.habit,data!!.timestamp,(newValue*1000).toInt())
|
|
||||||
widgetUpdater.updateWidgets()
|
widgetUpdater.updateWidgets()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun showNumberSelector(context: Context) {
|
fun showNumberSelector(context: Context) {
|
||||||
var localData = data
|
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)
|
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"
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue