Automation: Fix removing trigger

This commit is contained in:
Milos Kozak 2021-12-06 23:47:20 +01:00
parent 3875957801
commit fa4f0eb688
2 changed files with 42 additions and 44 deletions

View file

@ -106,7 +106,10 @@ class EditTriggerDialog : DialogFragmentWithDate() {
if (where is TriggerConnector) { if (where is TriggerConnector) {
for (i in where.list) { for (i in where.list) {
if (i == what) return where if (i == what) return where
if (i is TriggerConnector) return findParent(i, what) if (i is TriggerConnector) {
val found = findParent(i, what)
if (found != null) return found
}
} }
} }
return null return null

View file

@ -120,49 +120,44 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) {
override fun duplicate(): Trigger = TriggerConnector(injector, connectorType) override fun duplicate(): Trigger = TriggerConnector(injector, connectorType)
override fun generateDialog(root: LinearLayout) { override fun generateDialog(root: LinearLayout) {
val mainLayout = LinearLayout(root.context).also { root.addView(
it.orientation = LinearLayout.HORIZONTAL LinearLayout(root.context).also { mainLayout ->
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) mainLayout.orientation = LinearLayout.HORIZONTAL
} mainLayout.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val padding = rh.dpToPx(3) val padding = rh.dpToPx(3)
mainLayout.setPadding(padding, padding, padding, padding) mainLayout.setPadding(padding, padding, padding, padding)
mainLayout.setBackgroundResource(R.drawable.border_automation_unit) mainLayout.setBackgroundResource(R.drawable.border_automation_unit)
// Header with spinner
val buttonLayout = LinearLayout(root.context).also { mainLayout.addView(createVerticalView(root.context))
mainLayout.addView(
LinearLayout(root.context).also { rightSide ->
rightSide.orientation = LinearLayout.VERTICAL
rightSide.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
rightSide.addView(
LinearLayout(root.context).also {
it.orientation = LinearLayout.HORIZONTAL it.orientation = LinearLayout.HORIZONTAL
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
} it.addView(createAddButton(root.context, this))
buttonLayout.addView(createAddButton(root.context, this)) it.addView(createDeleteButton(root.context, this))
buttonLayout.addView(createDeleteButton(root.context, this)) })
val rightSideLayout = LinearLayout(root.context).also {
it.orientation = LinearLayout.VERTICAL
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
}
rightSideLayout.addView(buttonLayout)
// Child triggers // Child triggers
val listLayout = LinearLayout(root.context).also { rightSide.addView(
LinearLayout(root.context).also {
it.orientation = LinearLayout.VERTICAL it.orientation = LinearLayout.VERTICAL
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { params -> it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { params ->
params.setMargins(rh.dpToPx(1), 0, rh.dpToPx(1), rh.dpToPx(2)) params.setMargins(rh.dpToPx(1), 0, rh.dpToPx(1), rh.dpToPx(2))
} }
}
for (t in list) { for (t in list) {
t.generateDialog(listLayout) t.generateDialog(it)
listLayout.addView( it.addView(
TextView(root.context).also { TextView(root.context).also { spacer ->
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) spacer.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
it.setPadding(0, rh.dpToPx(0.3f), 0, 0) spacer.setPadding(0, rh.dpToPx(0.3f), 0, 0)
}) })
} }
rightSideLayout.addView(listLayout) })
})
// Header with spinner })
mainLayout.addView(createVerticalView(root.context))
mainLayout.addView(rightSideLayout)
root.addView(mainLayout)
} }
private fun createVerticalView(context: Context): VerticalTextView = private fun createVerticalView(context: Context): VerticalTextView =