mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Preserve selections when reopening EditSettingActivity (#524)
This commit is contained in:
@@ -35,8 +35,10 @@ class EditSettingActivity : BaseActivity() {
|
|||||||
.setCompletedAllowed(true)
|
.setCompletedAllowed(true)
|
||||||
.build())
|
.build())
|
||||||
|
|
||||||
|
val args = SettingUtils.parseIntent(this.intent, habits)
|
||||||
|
|
||||||
val controller = EditSettingController(this)
|
val controller = EditSettingController(this)
|
||||||
val rootView = EditSettingRootView(this, habits, controller)
|
val rootView = EditSettingRootView(this, habits, controller, args)
|
||||||
val screen = BaseScreen(this)
|
val screen = BaseScreen(this)
|
||||||
screen.setRootView(rootView)
|
screen.setRootView(rootView)
|
||||||
setScreen(screen)
|
setScreen(screen)
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ import java.util.*
|
|||||||
class EditSettingRootView(
|
class EditSettingRootView(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val habitList: HabitList,
|
private val habitList: HabitList,
|
||||||
private val controller: EditSettingController
|
private val controller: EditSettingController,
|
||||||
|
args: SettingUtils.Arguments?
|
||||||
) : BaseRootView(context) {
|
) : BaseRootView(context) {
|
||||||
|
|
||||||
@BindView(R.id.toolbar)
|
@BindView(R.id.toolbar)
|
||||||
@@ -50,6 +51,11 @@ class EditSettingRootView(
|
|||||||
addView(inflate(getContext(), R.layout.automation, null))
|
addView(inflate(getContext(), R.layout.automation, null))
|
||||||
ButterKnife.bind(this)
|
ButterKnife.bind(this)
|
||||||
populateHabitSpinner()
|
populateHabitSpinner()
|
||||||
|
|
||||||
|
args?.let {
|
||||||
|
habitSpinner.setSelection(habitList.indexOf(it.habit))
|
||||||
|
actionSpinner.setSelection(it.action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getToolbar(): Toolbar {
|
override fun getToolbar(): Toolbar {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class FireSettingReceiver : BroadcastReceiver() {
|
|||||||
.habitsApplicationComponent(app.component)
|
.habitsApplicationComponent(app.component)
|
||||||
.build()
|
.build()
|
||||||
allHabits = app.component.habitList
|
allHabits = app.component.habitList
|
||||||
val args = parseIntent(intent) ?: return
|
val args = SettingUtils.parseIntent(intent, allHabits) ?: return
|
||||||
val timestamp = DateUtils.getToday()
|
val timestamp = DateUtils.getToday()
|
||||||
val controller = component.widgetController
|
val controller = component.widgetController
|
||||||
|
|
||||||
@@ -55,19 +55,9 @@ class FireSettingReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseIntent(intent: Intent): Arguments? {
|
|
||||||
val bundle = intent.getBundleExtra(EXTRA_BUNDLE) ?: return null
|
|
||||||
val action = bundle.getInt("action")
|
|
||||||
if (action < 0 || action > 2) return null
|
|
||||||
val habit = allHabits.getById(bundle.getLong("habit")) ?: return null
|
|
||||||
return Arguments(action, habit)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReceiverScope
|
@ReceiverScope
|
||||||
@Component(dependencies = arrayOf(HabitsApplicationComponent::class))
|
@Component(dependencies = arrayOf(HabitsApplicationComponent::class))
|
||||||
internal interface ReceiverComponent {
|
internal interface ReceiverComponent {
|
||||||
val widgetController: WidgetBehavior
|
val widgetController: WidgetBehavior
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Arguments(var action: Int, var habit: Habit)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.isoron.uhabits.automation
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import org.isoron.uhabits.core.models.Habit
|
||||||
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
|
|
||||||
|
object SettingUtils {
|
||||||
|
@JvmStatic
|
||||||
|
fun parseIntent(intent: Intent, allHabits: HabitList): Arguments? {
|
||||||
|
val bundle = intent.getBundleExtra(EXTRA_BUNDLE) ?: return null
|
||||||
|
val action = bundle.getInt("action")
|
||||||
|
if (action < 0 || action > 2) return null
|
||||||
|
val habit = allHabits.getById(bundle.getLong("habit")) ?: return null
|
||||||
|
return Arguments(action, habit)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Arguments(var action: Int, var habit: Habit)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user