diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt deleted file mode 100644 index e80807427bd0..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ActionListItemView.kt +++ /dev/null @@ -1,120 +0,0 @@ -package net.mullvad.mullvadvpn.ui.listitemview - -import android.content.Context -import android.content.res.Resources -import android.util.AttributeSet -import android.view.View.OnClickListener -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import androidx.core.view.isVisible -import net.mullvad.mullvadvpn.R -import net.mullvad.mullvadvpn.ui.widget.WidgetState - -open class ActionListItemView -@JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = R.attr.actionListItemViewStyle, - defStyleRes: Int = 0 -) : ListItemView(context, attrs, defStyleAttr, defStyleRes) { - - 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) } - } - - override val layoutRes: Int - get() = R.layout.list_item_action - - override val heightRes: Int - get() = R.dimen.cell_height - - override fun onUpdate() { - updateImage() - updateText() - updateWidget() - updateAction() - } - - protected open fun updateImage() { - try { - itemData.iconRes?.let { - itemIcon.isVisible = true - itemIcon.setImageResource(it) - return - } - } catch (ignore: Resources.NotFoundException) { - itemIcon.isVisible = true - itemIcon.setImageResource(R.drawable.ic_icons_missing) - return - } - - itemIcon.isVisible = false - itemIcon.setImageDrawable(null) - } - - protected open fun updateText() { - itemData.textRes?.let { - itemText.setText(it) - return - } - itemData.text?.let { - itemText.setText(it) - return - } - itemText.text = "" - } - - protected open fun updateAction() { - if (itemData.action == null) { - setOnClickListener(null) - isClickable = false - isFocusable = false - } else { - setOnClickListener(clickListener) - isClickable = true - isFocusable = true - } - } - - protected open fun updateWidget() { - itemData.widget.let { state -> - when (state) { - is WidgetState.ImageState -> { - if (widgetController !is WidgetViewController.StandardController) { - widgetContainer.removeAllViews() - widgetContainer.isVisible = true - widgetController = WidgetViewController.StandardController(widgetContainer) - } - (widgetController as WidgetViewController.StandardController).updateState(state) - } - is WidgetState.SwitchState -> { - if (widgetController !is WidgetViewController.SwitchController) { - widgetContainer.removeAllViews() - widgetContainer.isVisible = true - widgetController = WidgetViewController.SwitchController(widgetContainer) - } - (widgetController as WidgetViewController.SwitchController).updateState(state) - } - null -> { - if (widgetController != null) { - widgetController = null - widgetContainer.removeAllViews() - widgetContainer.isVisible = false - } - } - } - } - } - - override fun onAttachedToWindow() { - super.onAttachedToWindow() - widgetContainer.requestLayout() - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt deleted file mode 100644 index 61bb5bf4004f..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/DividerGroupListItemView.kt +++ /dev/null @@ -1,15 +0,0 @@ -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/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt deleted file mode 100644 index 981d6d081312..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ListItemView.kt +++ /dev/null @@ -1,43 +0,0 @@ -package net.mullvad.mullvadvpn.ui.listitemview - -import android.content.Context -import android.util.AttributeSet -import android.view.LayoutInflater -import androidx.annotation.DimenRes -import androidx.annotation.LayoutRes -import androidx.constraintlayout.widget.ConstraintLayout -import net.mullvad.mullvadvpn.applist.ListItemData -import net.mullvad.mullvadvpn.ui.ListItemListener - -abstract class ListItemView -@JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0, - defStyleRes: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr, defStyleRes) { - @get:LayoutRes protected abstract val layoutRes: Int - - @get:DimenRes protected abstract val heightRes: Int? - protected lateinit var itemData: ListItemData - var listItemListener: ListItemListener? = null - - init { - val view = LayoutInflater.from(context).inflate(layoutRes, this, true) - val height = - if (heightRes != null) { - resources.getDimensionPixelSize(heightRes!!) - } else { - LayoutParams.WRAP_CONTENT - } - view.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, height) - } - - fun update(data: ListItemData) { - itemData = data - onUpdate() - } - - protected open fun onUpdate() {} -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/PlainListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/PlainListItemView.kt deleted file mode 100644 index b0553619f9fc..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/PlainListItemView.kt +++ /dev/null @@ -1,31 +0,0 @@ -package net.mullvad.mullvadvpn.ui.listitemview - -import android.content.Context -import android.widget.TextView -import androidx.appcompat.view.ContextThemeWrapper -import net.mullvad.mullvadvpn.R - -class PlainListItemView(context: Context) : - ListItemView(ContextThemeWrapper(context, R.style.ListItem_PlainText)) { - override val layoutRes: Int - get() = R.layout.list_item_plain_text - - override val heightRes: Int? = null - private val plainText: TextView = findViewById(R.id.plain_text) - - override fun onUpdate() { - updateText() - } - - private fun updateText() { - itemData.textRes?.let { - plainText.setText(it) - return - } - itemData.text?.let { - plainText.text = it - return - } - plainText.text = "" - } -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ProgressListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ProgressListItemView.kt deleted file mode 100644 index 724caf0c618b..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/ProgressListItemView.kt +++ /dev/null @@ -1,15 +0,0 @@ -package net.mullvad.mullvadvpn.ui.listitemview - -import android.content.Context -import androidx.appcompat.view.ContextThemeWrapper -import net.mullvad.mullvadvpn.R - -class ProgressListItemView(context: Context) : - ListItemView(ContextThemeWrapper(context, R.style.ListItem_DividerGroup)) { - - override val layoutRes: Int - get() = R.layout.list_item_progress - - override val heightRes: Int - get() = R.dimen.progress_size -} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt deleted file mode 100644 index ffe6d0ae89db..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/TwoActionListItemView.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 - - private val container: ViewGroup = findViewById(R.id.container_without_widget) - - init { - isClickable = false - isFocusable = false - } - - 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/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/WidgetViewController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/WidgetViewController.kt deleted file mode 100644 index 62325b4e1d55..000000000000 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/listitemview/WidgetViewController.kt +++ /dev/null @@ -1,42 +0,0 @@ -package net.mullvad.mullvadvpn.ui.listitemview - -import android.view.LayoutInflater -import android.view.ViewGroup -import android.widget.ImageView -import androidx.annotation.LayoutRes -import androidx.appcompat.widget.SwitchCompat -import net.mullvad.mullvadvpn.R -import net.mullvad.mullvadvpn.ui.widget.WidgetState - -sealed class WidgetViewController(val parent: ViewGroup) { - @get:LayoutRes protected abstract val layoutRes: Int - - init { - LayoutInflater.from(parent.context).inflate(layoutRes, parent) - } - - abstract fun updateState(state: T) - - class StandardController(parent: ViewGroup) : - WidgetViewController(parent) { - override val layoutRes: Int - get() = R.layout.list_item_widget_image - - private val imageView: ImageView = parent.findViewById(R.id.widgetImage) - - override fun updateState(state: WidgetState.ImageState) = - imageView.setImageResource(state.imageRes) - } - - class SwitchController(parent: ViewGroup) : - WidgetViewController(parent) { - override val layoutRes: Int - get() = R.layout.list_item_widget_switch - - private val switch: SwitchCompat = parent.findViewById(R.id.widgetSwitch) - - override fun updateState(state: WidgetState.SwitchState) { - switch.isChecked = state.isChecked - } - } -} diff --git a/android/app/src/main/res/layout/list_item_action.xml b/android/app/src/main/res/layout/list_item_action.xml deleted file mode 100644 index 9b9fc806f0f1..000000000000 --- a/android/app/src/main/res/layout/list_item_action.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - diff --git a/android/app/src/main/res/layout/list_item_base.xml b/android/app/src/main/res/layout/list_item_base.xml deleted file mode 100644 index 0c22feef21df..000000000000 --- a/android/app/src/main/res/layout/list_item_base.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - diff --git a/android/app/src/main/res/layout/list_item_group_divider.xml b/android/app/src/main/res/layout/list_item_group_divider.xml deleted file mode 100644 index 9546d55c98f7..000000000000 --- a/android/app/src/main/res/layout/list_item_group_divider.xml +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/android/app/src/main/res/layout/list_item_plain_text.xml b/android/app/src/main/res/layout/list_item_plain_text.xml deleted file mode 100644 index f17bc6ed5eba..000000000000 --- a/android/app/src/main/res/layout/list_item_plain_text.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - diff --git a/android/app/src/main/res/layout/list_item_progress.xml b/android/app/src/main/res/layout/list_item_progress.xml deleted file mode 100644 index 221947ea85bc..000000000000 --- a/android/app/src/main/res/layout/list_item_progress.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - diff --git a/android/app/src/main/res/layout/list_item_two_action.xml b/android/app/src/main/res/layout/list_item_two_action.xml deleted file mode 100644 index 81e6a5c652f4..000000000000 --- a/android/app/src/main/res/layout/list_item_two_action.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - diff --git a/android/app/src/main/res/layout/list_item_widget_image.xml b/android/app/src/main/res/layout/list_item_widget_image.xml deleted file mode 100644 index 95034e46e347..000000000000 --- a/android/app/src/main/res/layout/list_item_widget_image.xml +++ /dev/null @@ -1,10 +0,0 @@ - - diff --git a/android/app/src/main/res/layout/list_item_widget_switch.xml b/android/app/src/main/res/layout/list_item_widget_switch.xml deleted file mode 100644 index 9c4e3426605f..000000000000 --- a/android/app/src/main/res/layout/list_item_widget_switch.xml +++ /dev/null @@ -1,11 +0,0 @@ - -