diff options
| author | Aleksandr Granin <aleksandr@mullvad.net> | 2021-03-02 10:20:58 +0100 |
|---|---|---|
| committer | Aleksandr Granin <aleksandr@mullvad.net> | 2021-03-12 14:57:41 +0100 |
| commit | 3251d457d0f1da0dc5e9500708399c0ba4d2cb5b (patch) | |
| tree | 72b9850e81f7936214a77202fc678cd6642db6c5 /android/src | |
| parent | e0c0e496841ec755ecf2cf8a3ed4a1a13e9c1708 (diff) | |
| download | mullvadvpn-3251d457d0f1da0dc5e9500708399c0ba4d2cb5b.tar.xz mullvadvpn-3251d457d0f1da0dc5e9500708399c0ba4d2cb5b.zip | |
Use system animation timings
Diffstat (limited to 'android/src')
7 files changed, 79 insertions, 16 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt index 865d50db24..69581c245f 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt @@ -1,11 +1,11 @@ package net.mullvad.mullvadvpn.ui.listitemview import android.content.Context +import android.content.res.Resources import android.util.AttributeSet import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView -import androidx.core.view.isInvisible import androidx.core.view.isVisible import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.model.WidgetState @@ -16,20 +16,23 @@ open class ActionListItemView @JvmOverloads constructor( defStyleAttr: Int = R.attr.actionListItemViewStyle, defStyleRes: Int = 0 ) : ListItemView(context, attrs, defStyleAttr, defStyleRes) { - override val layoutRes: Int - get() = R.layout.list_item_action - override val heightRes: Int - get() = R.dimen.cell_height protected var widgetController: WidgetViewController<*>? = null + protected val itemText: TextView = findViewById(R.id.itemText) + protected val itemIcon: ImageView = findViewById(R.id.itemIcon) + protected val widgetContainer: ViewGroup = findViewById(R.id.widgetContainer) + protected val clickListener = OnClickListener { itemData.action?.let { _ -> listItemListener?.onItemAction(itemData) } } - protected val itemIcon: ImageView = findViewById(R.id.itemIcon) - protected val itemText: TextView = findViewById(R.id.itemText) - protected val widgetContainer: ViewGroup = findViewById(R.id.widgetContainer) + + override val layoutRes: Int + get() = R.layout.list_item_action + + override val heightRes: Int + get() = R.dimen.cell_height override fun onUpdate() { updateImage() @@ -39,9 +42,15 @@ open class ActionListItemView @JvmOverloads constructor( } protected open fun updateImage() { - itemData.iconRes?.let { + try { + itemData.iconRes?.let { + itemIcon.isVisible = true + itemIcon.setImageResource(it) + return + } + } catch (ignore: Resources.NotFoundException) { itemIcon.isVisible = true - itemIcon.setImageResource(it) + itemIcon.setImageResource(R.drawable.ic_icons_missing) return } @@ -61,7 +70,7 @@ open class ActionListItemView @JvmOverloads constructor( itemText.text = "" } - private fun updateAction() { + protected open fun updateAction() { if (itemData.action == null) { setOnClickListener(null) isClickable = false @@ -96,10 +105,15 @@ open class ActionListItemView @JvmOverloads constructor( if (widgetController != null) { widgetController = null widgetContainer.removeAllViews() - widgetContainer.isInvisible = true + widgetContainer.isVisible = false } } } } } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + widgetContainer.requestLayout() + } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt new file mode 100644 index 0000000000..61bb5bf400 --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt @@ -0,0 +1,15 @@ +package net.mullvad.mullvadvpn.ui.listitemview + +import android.content.Context +import androidx.appcompat.view.ContextThemeWrapper +import net.mullvad.mullvadvpn.R + +class DividerGroupListItemView(context: Context) : + ListItemView(ContextThemeWrapper(context, R.style.ListItem_DividerGroup)) { + + override val layoutRes: Int + get() = R.layout.list_item_group_divider + + override val heightRes: Int + get() = R.dimen.vertical_space +} diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt index 3042e4e5af..d1149d1afd 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt @@ -15,7 +15,6 @@ abstract class ListItemView @JvmOverloads constructor( defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes) { - private val inflater: LayoutInflater = LayoutInflater.from(context) @get:LayoutRes protected abstract val layoutRes: Int @get:DimenRes @@ -24,7 +23,7 @@ abstract class ListItemView @JvmOverloads constructor( var listItemListener: ListItemListener? = null init { - val view = inflater.inflate(layoutRes, this, true) + val view = LayoutInflater.from(context).inflate(layoutRes, this, true) val height = if (heightRes != null) { resources.getDimensionPixelSize(heightRes!!) } else { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt index 0f2bb3fa5b..dcc3597749 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt @@ -1,12 +1,34 @@ package net.mullvad.mullvadvpn.ui.listitemview import android.content.Context +import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper import net.mullvad.mullvadvpn.R class TwoActionListItemView(context: Context) : ActionListItemView(ContextThemeWrapper(context, R.style.ListItem_Action_Double)) { - override val layoutRes: Int get() = R.layout.list_item_two_action + + init { + isClickable = false + isFocusable = false + } + + private val container: ViewGroup = findViewById(R.id.container_without_widget) + + override fun updateAction() { + if (itemData.action == null) { + container.setOnClickListener(null) + container.isClickable = false + container.isFocusable = false + } else { + container.setOnClickListener(clickListener) + container.isClickable = true + container.isFocusable = true + } + widgetContainer.setOnClickListener(clickListener) + widgetContainer.isClickable = true + widgetContainer.isFocusable = true + } } diff --git a/android/src/main/res/drawable/ic_icons_missing.xml b/android/src/main/res/drawable/ic_icons_missing.xml new file mode 100644 index 0000000000..726a5c7f74 --- /dev/null +++ b/android/src/main/res/drawable/ic_icons_missing.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path android:fillColor="#D8D8D8" + android:fillType="nonZero" + android:pathData="M16.327,10.25l1.422,-2.519c0.124,-0.246 0.031,-0.547 -0.2,-0.673 -0.225,-0.12 -0.503,-0.048 -0.642,0.174l-1.453,2.567c-2.21,-0.959 -4.698,-0.959 -6.908,0L7.093,7.232c-0.147,-0.23 -0.448,-0.301 -0.672,-0.159 -0.216,0.143 -0.286,0.428 -0.17,0.658l1.422,2.52C5.277,11.652 3.716,14.18 3.5,17h17c-0.216,-2.82 -1.777,-5.347 -4.173,-6.75zM8.137,14.821c-0.534,0 -0.967,-0.443 -0.967,-0.99 0,-0.547 0.433,-0.99 0.966,-0.99 0.534,0 0.966,0.443 0.966,0.99 0,0.547 -0.432,0.99 -0.966,0.99zM15.864,14.821c-0.534,0 -0.966,-0.443 -0.966,-0.99 0,-0.547 0.432,-0.99 0.966,-0.99 0.533,0 0.966,0.443 0.966,0.99 0,0.547 -0.433,0.99 -0.966,0.99zM12,24C5.373,24 0,18.627 0,12S5.373,0 12,0s12,5.373 12,12 -5.373,12 -12,12z" /> +</vector> diff --git a/android/src/main/res/layout/list_item_base.xml b/android/src/main/res/layout/list_item_base.xml index d4b723d70a..0c22feef21 100644 --- a/android/src/main/res/layout/list_item_base.xml +++ b/android/src/main/res/layout/list_item_base.xml @@ -10,6 +10,7 @@ android:layout_width="@dimen/icon_size" android:layout_height="@dimen/icon_size" android:layout_marginEnd="@dimen/cell_inner_spacing" + android:background="@null" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/itemText" app:layout_constraintStart_toStartOf="@id/startGuideline" @@ -22,6 +23,7 @@ android:gravity="center_vertical" android:textAppearance="@style/TextAppearance.Mullvad.Title1" android:textStyle="bold" + android:background="@null" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/widgetBarrier" app:layout_constraintStart_toEndOf="@id/itemIcon" @@ -36,6 +38,7 @@ <androidx.constraintlayout.widget.Barrier android:id="@+id/widgetBarrier" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:tag="base" app:barrierDirection="start" app:constraint_referenced_ids="parent" /> </merge> diff --git a/android/src/main/res/values/integers.xml b/android/src/main/res/values/integers.xml index 1ae43d4d23..3089382d18 100644 --- a/android/src/main/res/values/integers.xml +++ b/android/src/main/res/values/integers.xml @@ -1,4 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <integer name="transition_animation_duration">450</integer> + <integer name="transition_animation_duration">@android:integer/config_mediumAnimTime</integer> </resources> |
