diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/InformationView.kt | 78 | ||||
| -rw-r--r-- | android/src/main/res/layout/information_view.xml | 17 | ||||
| -rw-r--r-- | android/src/main/res/values/attrs.xml | 5 | ||||
| -rw-r--r-- | android/src/main/res/values/strings.xml | 2 |
4 files changed, 102 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() + } + } + } +} diff --git a/android/src/main/res/layout/information_view.xml b/android/src/main/res/layout/information_view.xml new file mode 100644 index 0000000000..b59aac9b7b --- /dev/null +++ b/android/src/main/res/layout/information_view.xml @@ -0,0 +1,17 @@ +<merge xmlns:android="http://schemas.android.com/apk/res/android"> + <TextView android:id="@+id/description" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="9dp" + android:textColor="@color/white60" + android:textSize="13sp" + android:textStyle="bold" + android:text="" /> + <TextView android:id="@+id/information_display" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="@color/white" + android:textSize="16sp" + android:textStyle="bold" + android:text="" /> +</merge> diff --git a/android/src/main/res/values/attrs.xml b/android/src/main/res/values/attrs.xml new file mode 100644 index 0000000000..62c7d275b7 --- /dev/null +++ b/android/src/main/res/values/attrs.xml @@ -0,0 +1,5 @@ +<resources> + <declare-styleable name="InformationView"> + <attr name="description" format="reference|string"/> + </declare-styleable> +</resources> diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index de1419cdf8..cc554393f0 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -179,4 +179,6 @@ https://mullvad.net/en/account/create</string> <string name="download_url"> https://mullvad.net/en/download</string> + <string name="copied_to_clipboard">Copied to + clipboard</string> </resources> |
