diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-23 16:47:40 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-28 13:52:59 +0000 |
| commit | 42581eda42f34d5f00c1c45823b2c421d463ce34 (patch) | |
| tree | 553d69ab696b1b8dd589a501510be4ba8e811753 /android/src | |
| parent | 75c5d4be3d2e9b67ba7024897b61da62275a8930 (diff) | |
| download | mullvadvpn-42581eda42f34d5f00c1c45823b2c421d463ce34.tar.xz mullvadvpn-42581eda42f34d5f00c1c45823b2c421d463ce34.zip | |
Allow setting a footer to `Cell` widget
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt | 43 | ||||
| -rw-r--r-- | android/src/main/res/values/attrs.xml | 4 | ||||
| -rw-r--r-- | android/src/main/res/values/dimensions.xml | 2 |
3 files changed, 48 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt index bd16d94775..4affaa84db 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Cell.kt @@ -23,6 +23,21 @@ open class Cell : LinearLayout { setTypeface(null, Typeface.BOLD) } + private var footer: TextView? = null + set(value) { + field = value?.apply { + val horizontalPadding = + resources.getDimensionPixelSize(R.dimen.cell_footer_horizontal_padding) + val topPadding = resources.getDimensionPixelSize(R.dimen.cell_footer_top_padding) + + layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) + setPadding(horizontalPadding, topPadding, horizontalPadding, 0) + + setTextColor(context.getColor(R.color.white60)) + setTextSize(TypedValue.COMPLEX_UNIT_SP, 13.0f) + } + } + protected var cell: LinearLayout = this set(value) { field = value.apply { @@ -73,6 +88,32 @@ open class Cell : LinearLayout { } } - cell = this + context.theme.obtainStyledAttributes(attributes, R.styleable.Cell, 0, 0).apply { + try { + footer = getString(R.styleable.Cell_footer)?.let { footerText -> + TextView(context).apply { text = footerText } + } + } finally { + recycle() + } + } + + setUp() + } + + private fun setUp() { + if (footer != null) { + cell = LinearLayout(context).apply { + layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) + } + + isClickable = false + orientation = VERTICAL + + addView(cell) + addView(footer) + } else { + cell = this + } } } diff --git a/android/src/main/res/values/attrs.xml b/android/src/main/res/values/attrs.xml index 1ddae37ee7..f0f573d138 100644 --- a/android/src/main/res/values/attrs.xml +++ b/android/src/main/res/values/attrs.xml @@ -14,6 +14,10 @@ <attr name="showSpinner" format="boolean" /> </declare-styleable> + <declare-styleable name="Cell"> + <attr name="footer" + format="reference|string" /> + </declare-styleable> <declare-styleable name="CopyableInformationView"> <attr name="clipboardLabel" format="reference|string" /> diff --git a/android/src/main/res/values/dimensions.xml b/android/src/main/res/values/dimensions.xml index 468a8a42f3..0d95bb9633 100644 --- a/android/src/main/res/values/dimensions.xml +++ b/android/src/main/res/values/dimensions.xml @@ -18,6 +18,8 @@ <dimen name="cell_horizontal_padding">16dp</dimen> <dimen name="cell_label_horizontal_padding">8dp</dimen> <dimen name="cell_label_vertical_padding">17dp</dimen> + <dimen name="cell_footer_top_padding">8dp</dimen> + <dimen name="cell_footer_horizontal_padding">24dp</dimen> <dimen name="chevron_width">14dp</dimen> <dimen name="chevron_height">24dp</dimen> </resources> |
