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