summaryrefslogtreecommitdiffhomepage
path: root/android/src/main/kotlin
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-03-31 19:43:57 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-27 16:21:51 +0000
commit57fa33f93693539ec91b72bb15bbe56963d18d50 (patch)
tree611a1634ed6b5f1de2e87cf172d1a37c4c727522 /android/src/main/kotlin
parent777c02df0194a175f346f5918615bc139bd77e3c (diff)
downloadmullvadvpn-57fa33f93693539ec91b72bb15bbe56963d18d50.tar.xz
mullvadvpn-57fa33f93693539ec91b72bb15bbe56963d18d50.zip
Create `InformationView` helper widget
Diffstat (limited to 'android/src/main/kotlin')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/InformationView.kt78
1 files changed, 78 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/InformationView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/InformationView.kt
new file mode 100644
index 0000000000..32721421bf
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/InformationView.kt
@@ -0,0 +1,78 @@
+package net.mullvad.mullvadvpn.ui
+
+import android.content.Context
+import android.util.AttributeSet
+import android.util.TypedValue
+import android.view.LayoutInflater
+import android.widget.LinearLayout
+import android.widget.TextView
+import net.mullvad.mullvadvpn.R
+
+class InformationView : LinearLayout {
+ private val container =
+ context.getSystemService(Context.LAYOUT_INFLATER_SERVICE).let { service ->
+ val inflater = service as LayoutInflater
+
+ inflater.inflate(R.layout.information_view, this).apply {
+ setOnClickListener { onClick?.invoke() }
+ setEnabled(false)
+ }
+ }
+
+ private val description: TextView = findViewById(R.id.description)
+ private val informationDisplay: TextView = findViewById(R.id.information_display)
+
+ var information: String
+ get() = informationDisplay.text?.toString() ?: ""
+ set(value) {
+ informationDisplay.text = value
+ setEnabled(value != null)
+ }
+
+ var onClick: (() -> Unit)? = null
+
+ constructor(context: Context) : super(context) {}
+
+ constructor(context: Context, attributes: AttributeSet) : super(context, attributes) {
+ loadAttributes(attributes)
+ }
+
+ constructor(context: Context, attributes: AttributeSet, defaultStyleAttribute: Int) :
+ super(context, attributes, defaultStyleAttribute) {
+ loadAttributes(attributes)
+ }
+
+ constructor(
+ context: Context,
+ attributes: AttributeSet,
+ defaultStyleAttribute: Int,
+ defaultStyleResource: Int
+ ) : super(context, attributes, defaultStyleAttribute, defaultStyleResource) {
+ loadAttributes(attributes)
+ }
+
+ init {
+ val backgroundResource = TypedValue()
+
+ context.theme.resolveAttribute(
+ android.R.attr.selectableItemBackground,
+ backgroundResource,
+ true
+ )
+
+ orientation = VERTICAL
+ setBackgroundResource(backgroundResource.resourceId)
+ }
+
+ private fun loadAttributes(attributes: AttributeSet) {
+ val styleableId = R.styleable.InformationView
+
+ context.theme.obtainStyledAttributes(attributes, styleableId, 0, 0).apply {
+ try {
+ description.text = getString(R.styleable.InformationView_description) ?: ""
+ } finally {
+ recycle()
+ }
+ }
+ }
+}