summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorAleksandr Granin <aleksandr@mullvad.net>2021-03-22 08:35:47 +0100
committerAleksandr Granin <aleksandr@mullvad.net>2021-03-22 15:04:55 +0100
commit40e58613b972f25940015eb7f26b994f42a07b3e (patch)
treeb4b88b0018c1ec2cb8debcd57c87d6137e038f71 /android/src
parent1d27bd5c314723ae1d5d32676a6132f14c9b37cf (diff)
downloadmullvadvpn-40e58613b972f25940015eb7f26b994f42a07b3e.tar.xz
mullvadvpn-40e58613b972f25940015eb7f26b994f42a07b3e.zip
Simplify ListItemDecoration
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt6
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemDividerDecoration.kt23
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt6
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnelingFragment.kt6
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt6
5 files changed, 14 insertions, 33 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
index c9ba93cd67..671a232220 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
@@ -52,9 +52,9 @@ class AdvancedFragment : ServiceDependentFragment(OnNoService.GoBack) {
}
addItemDecoration(
- ListItemDividerDecoration(parentActivity).apply {
- topOffsetId = R.dimen.list_item_divider
- }
+ ListItemDividerDecoration(
+ topOffset = resources.getDimensionPixelSize(R.dimen.list_item_divider)
+ )
)
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemDividerDecoration.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemDividerDecoration.kt
index 07753a1265..4fcde0e314 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemDividerDecoration.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemDividerDecoration.kt
@@ -1,32 +1,13 @@
package net.mullvad.mullvadvpn.ui
-import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
import androidx.recyclerview.widget.RecyclerView.State
-import kotlin.properties.Delegates.observable
-class ListItemDividerDecoration(context: Context) : ItemDecoration() {
- private var bottomOffset = 0
- private var topOffset = 0
-
- var bottomOffsetId by observable<Int?>(null) { _, _, id ->
- if (id != null) {
- bottomOffset = context.resources.getDimensionPixelSize(id)
- } else {
- bottomOffset = 0
- }
- }
-
- var topOffsetId by observable<Int?>(null) { _, _, id ->
- if (id != null) {
- topOffset = context.resources.getDimensionPixelSize(id)
- } else {
- topOffset = 0
- }
- }
+class ListItemDividerDecoration(private val bottomOffset: Int = 0, private val topOffset: Int = 0) :
+ ItemDecoration() {
override fun getItemOffsets(offsets: Rect, view: View, parent: RecyclerView, state: State) {
offsets.bottom = bottomOffset
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
index 43237dcd25..8d30001f2c 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
@@ -79,9 +79,9 @@ class SelectLocationFragment :
}
addItemDecoration(
- ListItemDividerDecoration(parentActivity).apply {
- bottomOffsetId = R.dimen.list_item_divider
- }
+ ListItemDividerDecoration(
+ bottomOffset = resources.getDimensionPixelSize(R.dimen.list_item_divider)
+ )
)
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnelingFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnelingFragment.kt
index a7b74ddeb0..9750cea495 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnelingFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SplitTunnelingFragment.kt
@@ -76,9 +76,9 @@ class SplitTunnelingFragment : ServiceDependentFragment(OnNoService.GoToLaunchSc
}
addItemDecoration(
- ListItemDividerDecoration(parentActivity).apply {
- bottomOffsetId = R.dimen.list_item_divider
- }
+ ListItemDividerDecoration(
+ bottomOffset = resources.getDimensionPixelSize(R.dimen.list_item_divider)
+ )
)
}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
index 9b2178b0b2..2d608f8c67 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
@@ -168,9 +168,9 @@ class AccountLogin : RelativeLayout {
adapter = historyAdapter
addItemDecoration(
- ListItemDividerDecoration(context).apply {
- topOffsetId = R.dimen.account_history_divider
- }
+ ListItemDividerDecoration(
+ topOffset = resources.getDimensionPixelSize(R.dimen.account_history_divider)
+ )
)
}