diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-24 14:11:45 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-28 13:52:59 +0000 |
| commit | d8bb6f1f881c6fffe1133ff7f1bf65229bff424a (patch) | |
| tree | fb187de17ad6a5edd3a505757b718c05ed2ef1c1 /android/src/main | |
| parent | a10fa073d93a143174fb7020aa1fd8692b727b4f (diff) | |
| download | mullvadvpn-d8bb6f1f881c6fffe1133ff7f1bf65229bff424a.tar.xz mullvadvpn-d8bb6f1f881c6fffe1133ff7f1bf65229bff424a.zip | |
Create `AppVersionCell` widget
Diffstat (limited to 'android/src/main')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AppVersionCell.kt | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AppVersionCell.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AppVersionCell.kt new file mode 100644 index 0000000000..cba7095eda --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AppVersionCell.kt @@ -0,0 +1,90 @@ +package net.mullvad.mullvadvpn.ui.widget + +import android.content.Context +import android.content.Intent +import android.graphics.Typeface +import android.net.Uri +import android.util.AttributeSet +import android.util.TypedValue +import android.view.Gravity +import android.widget.ImageView +import android.widget.TextView +import kotlin.properties.Delegates.observable +import net.mullvad.mullvadvpn.R + +class AppVersionCell : Cell { + private val warningIcon = ImageView(context).apply { + layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.0f) + + resources.getDimensionPixelSize(R.dimen.cell_label_horizontal_padding).let { padding -> + setPadding(padding, 0, 0, 0) + } + + setImageResource(R.drawable.icon_alert) + } + + private val versionLabel = TextView(context).apply { + layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.0f) + gravity = Gravity.RIGHT + + resources.getDimensionPixelSize(R.dimen.cell_label_horizontal_padding).let { padding -> + setPadding(padding, 0, padding, 0) + } + + setTextColor(context.getColor(R.color.white60)) + setTextSize(TypedValue.COMPLEX_UNIT_SP, 13.0f) + setTypeface(null, Typeface.BOLD) + + text = "" + } + + private val externalLinkIcon = ImageView(context).apply { + layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.0f) + alpha = 0.6f + + setImageResource(R.drawable.icon_extlink) + } + + var updateAvailable by observable(false) { _, _, updateAvailable -> + if (updateAvailable) { + warningIcon.visibility = VISIBLE + footer?.visibility = VISIBLE + } else { + warningIcon.visibility = GONE + footer?.visibility = GONE + } + } + + var version by observable("") { _, _, version -> + versionLabel.text = version + } + + 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 { + cell.addView(warningIcon, 0) + cell.addView(versionLabel) + cell.addView(externalLinkIcon) + + onClickListener = { openLink() } + } + + private fun openLink() { + val url = context.getString(R.string.download_url) + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + + context.startActivity(intent) + } +} |
