Automation: remove proper event
This commit is contained in:
parent
125ed945bb
commit
d7e5eea4a3
4 changed files with 5 additions and 16 deletions
|
@ -21,7 +21,6 @@ class AutomationEventObject(private val injector: HasAndroidInjector) : Automati
|
|||
|
||||
override var title: String = ""
|
||||
override var isEnabled = true
|
||||
var position = -1
|
||||
var systemAction: Boolean = false // true = generated by AAPS, false = entered by user
|
||||
var readOnly: Boolean = false // removing, editing disabled
|
||||
var autoRemove: Boolean = false // auto-remove once used
|
||||
|
@ -76,12 +75,11 @@ class AutomationEventObject(private val injector: HasAndroidInjector) : Automati
|
|||
.toString()
|
||||
}
|
||||
|
||||
fun fromJSON(data: String, position: Int): AutomationEventObject {
|
||||
fun fromJSON(data: String): AutomationEventObject {
|
||||
val d = JSONObject(data)
|
||||
title = d.optString("title", "")
|
||||
isEnabled = d.optBoolean("enabled", true)
|
||||
systemAction = d.optBoolean("systemAction", false)
|
||||
this.position = position
|
||||
readOnly = d.optBoolean("readOnly", false)
|
||||
autoRemove = d.optBoolean("autoRemove", false)
|
||||
userAction = d.optBoolean("userAction", false)
|
||||
|
|
|
@ -293,7 +293,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener, MenuProvider {
|
|||
OKDialog.showConfirmation(activity, rh.gs(app.aaps.core.ui.R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, event ->
|
||||
uel.log(Action.AUTOMATION_REMOVED, Sources.Automation, event.title)
|
||||
automationPlugin.removeAt(event.position)
|
||||
automationPlugin.remove(event)
|
||||
rxBus.send(EventAutomationDataChanged())
|
||||
}
|
||||
actionHelper.finish()
|
||||
|
|
|
@ -211,14 +211,14 @@ class AutomationPlugin @Inject constructor(
|
|||
val array = JSONArray(data)
|
||||
for (i in 0 until array.length()) {
|
||||
val o = array.getJSONObject(i)
|
||||
val event = AutomationEventObject(injector).fromJSON(o.toString(), i)
|
||||
val event = AutomationEventObject(injector).fromJSON(o.toString())
|
||||
automationEvents.add(event)
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
else
|
||||
automationEvents.add(AutomationEventObject(injector).fromJSON(event, 0))
|
||||
automationEvents.add(AutomationEventObject(injector).fromJSON(event))
|
||||
}
|
||||
|
||||
internal fun processActions() {
|
||||
|
@ -309,7 +309,6 @@ class AutomationPlugin @Inject constructor(
|
|||
@Synchronized
|
||||
fun add(event: AutomationEventObject) {
|
||||
automationEvents.add(event)
|
||||
event.position = automationEvents.size - 1
|
||||
rxBus.send(EventAutomationDataChanged())
|
||||
}
|
||||
|
||||
|
@ -338,14 +337,6 @@ class AutomationPlugin @Inject constructor(
|
|||
rxBus.send(EventAutomationDataChanged())
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun removeAt(index: Int) {
|
||||
if (index >= 0 && index < automationEvents.size) {
|
||||
automationEvents.removeAt(index)
|
||||
rxBus.send(EventAutomationDataChanged())
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun remove(event: AutomationEvent) {
|
||||
automationEvents.remove(event)
|
||||
|
|
|
@ -57,7 +57,7 @@ class EditEventDialog : BaseDialog() {
|
|||
// load data from bundle
|
||||
(savedInstanceState ?: arguments)?.let { bundle ->
|
||||
position = bundle.getInt("position", -1)
|
||||
bundle.getString("event")?.let { event = AutomationEventObject(injector).fromJSON(it, position) }
|
||||
bundle.getString("event")?.let { event = AutomationEventObject(injector).fromJSON(it) }
|
||||
}
|
||||
|
||||
onCreateViewGeneral()
|
||||
|
|
Loading…
Reference in a new issue