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))
it.orientation = LinearLayout.HORIZONTAL mainLayout.addView(
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) LinearLayout(root.context).also { rightSide ->
} rightSide.orientation = LinearLayout.VERTICAL
buttonLayout.addView(createAddButton(root.context, this)) rightSide.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
buttonLayout.addView(createDeleteButton(root.context, this)) rightSide.addView(
LinearLayout(root.context).also {
val rightSideLayout = LinearLayout(root.context).also { it.orientation = LinearLayout.HORIZONTAL
it.orientation = LinearLayout.VERTICAL it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f) it.addView(createAddButton(root.context, this))
} it.addView(createDeleteButton(root.context, this))
})
rightSideLayout.addView(buttonLayout) // Child triggers
rightSide.addView(
// Child triggers LinearLayout(root.context).also {
val listLayout = 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) {
} t.generateDialog(it)
for (t in list) { it.addView(
t.generateDialog(listLayout) TextView(root.context).also { spacer ->
listLayout.addView( spacer.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
TextView(root.context).also { spacer.setPadding(0, rh.dpToPx(0.3f), 0, 0)
it.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) })
it.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 =