summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-23 16:50:10 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-28 13:52:59 +0000
commitab771bdfb4752d2140e94071f381cdffb2160fe8 (patch)
treef75be09042355f9628b23dac5b20520d0c6973d1
parent0253430781b780a5b3d979be994afe923bacfe87 (diff)
downloadmullvadvpn-ab771bdfb4752d2140e94071f381cdffb2160fe8.tar.xz
mullvadvpn-ab771bdfb4752d2140e94071f381cdffb2160fe8.zip
Create `ToggleCell` helper widget
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ToggleCell.kt45
1 files changed, 45 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ToggleCell.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ToggleCell.kt
new file mode 100644
index 0000000000..cde050bbc2
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ToggleCell.kt
@@ -0,0 +1,45 @@
+package net.mullvad.mullvadvpn.ui.widget
+
+import android.content.Context
+import android.util.AttributeSet
+
+class ToggleCell : Cell {
+ private val toggle = CellSwitch(context).apply {
+ layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.0f)
+ }
+
+ var state
+ get() = toggle.state
+ set(value) { toggle.state = value }
+
+ var listener
+ get() = toggle.listener
+ set(value) { toggle.listener = value }
+
+ constructor(context: Context) : super(context) {}
+
+ constructor(context: Context, attributes: AttributeSet) : super(context, attributes) {}
+
+ constructor(context: Context, attributes: AttributeSet, defaultStyleAttribute: Int) :
+ super(context, attributes, defaultStyleAttribute) {}
+
+ constructor(
+ context: Context,
+ attributes: AttributeSet,
+ defaultStyleAttribute: Int,
+ defaultStyleResource: Int
+ ) : super(context, attributes, defaultStyleAttribute, defaultStyleResource) {}
+
+ init {
+ onClickListener = { toggle() }
+ cell.addView(toggle)
+ }
+
+ fun toggle() {
+ toggle.toggle()
+ }
+
+ fun forcefullySetState(state: CellSwitch.State) {
+ toggle.forcefullySetState(state)
+ }
+}