diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt | 23 | ||||
| -rw-r--r-- | android/src/main/res/layout/button.xml | 7 | ||||
| -rw-r--r-- | android/src/main/res/values/attrs.xml | 1 |
3 files changed, 31 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt index 2738e2aba6..826c93e1e4 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/Button.kt @@ -1,10 +1,12 @@ package net.mullvad.mullvadvpn.ui.widget import android.content.Context +import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.widget.FrameLayout +import android.widget.ImageView import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.util.JobTracker @@ -33,6 +35,7 @@ open class Button : FrameLayout { private val button = container.findViewById<android.widget.Button>(R.id.button) private val spinner: View = container.findViewById(R.id.spinner) + private val image: ImageView = container.findViewById(R.id.image) private var clickJobName: String? = null private var onClickAction: (suspend () -> Unit)? = null @@ -51,6 +54,20 @@ open class Button : FrameLayout { button.setBackgroundResource(backgroundResource) } + var detailImage: Drawable? = null + set(value) { + field = value + + image.apply { + if (value == null) { + visibility = GONE + } else { + visibility = VISIBLE + setImageDrawable(value) + } + } + } + var showSpinner = false constructor(context: Context) : super(context) {} @@ -87,12 +104,17 @@ open class Button : FrameLayout { button.setOnClickListener { jobTracker?.newUiJob(clickJobName!!) { if (showSpinner) { + image.visibility = GONE spinner.visibility = VISIBLE } onClickAction!!.invoke() spinner.visibility = GONE + + if (detailImage != null) { + image.visibility = VISIBLE + } } } } @@ -114,6 +136,7 @@ open class Button : FrameLayout { try { button.text = getString(R.styleable.Button_text) ?: "" buttonColor = ButtonColor.fromCode(getInteger(R.styleable.Button_buttonColor, 0)) + detailImage = getDrawable(R.styleable.Button_detailImage) showSpinner = getBoolean(R.styleable.Button_showSpinner, false) } finally { recycle() diff --git a/android/src/main/res/layout/button.xml b/android/src/main/res/layout/button.xml index 1f7cb39130..51d273af97 100644 --- a/android/src/main/res/layout/button.xml +++ b/android/src/main/res/layout/button.xml @@ -13,4 +13,11 @@ android:indeterminateDuration="600" android:indeterminateDrawable="@drawable/icon_spinner" android:visibility="gone" /> + <ImageView android:id="@+id/image" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="9dp" + android:layout_gravity="right|center_vertical" + android:src="@android:color/transparent" + android:visibility="gone" /> </merge> diff --git a/android/src/main/res/values/attrs.xml b/android/src/main/res/values/attrs.xml index 8ffa0ef8df..bda6c3b9b6 100644 --- a/android/src/main/res/values/attrs.xml +++ b/android/src/main/res/values/attrs.xml @@ -4,6 +4,7 @@ <enum name="blue" value="0"/> <enum name="green" value="1"/> </attr> + <attr name="detailImage" format="reference"/> <attr name="showSpinner" format="boolean"/> <attr name="text" format="reference|string"/> </declare-styleable> |
