diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-04 17:37:53 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-10 12:55:06 +0000 |
| commit | b230c0c712aadbffddd225cb0cc5ce77b4346b65 (patch) | |
| tree | 9bee7bf9730b1491aaa725a19e0b8eb7e4d862d5 /android/src/main/kotlin | |
| parent | 38f5b2a84c4c6b31ca51bd6a4c10c63a8bdcdc89 (diff) | |
| download | mullvadvpn-b230c0c712aadbffddd225cb0cc5ce77b4346b65.tar.xz mullvadvpn-b230c0c712aadbffddd225cb0cc5ce77b4346b65.zip | |
Create row to edit custom DNS address
Diffstat (limited to 'android/src/main/kotlin')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt | 30 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt | 5 |
2 files changed, 29 insertions, 6 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt index 5516329f75..7a48b2485b 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/CustomDnsAdapter.kt @@ -11,11 +11,14 @@ import net.mullvad.mullvadvpn.util.JobTracker class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>() { private enum class ViewTypes { ADD_SERVER, + EDIT_SERVER, FOOTER, } private val jobTracker = JobTracker() + private var enteringNewServer = false + private var enabled by observable(false) { _, oldValue, newValue -> if (oldValue != newValue) { notifyDataSetChanged() @@ -30,17 +33,28 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( } } - override fun getItemCount() = if (enabled) { 2 } else { 1 } + override fun getItemCount() = + if (enabled) { + 2 + } else { + 1 + } override fun getItemViewType(position: Int): Int { - if (enabled) { - if (position == 0) { - return ViewTypes.ADD_SERVER.ordinal + val count = getItemCount() + val footer = count - 1 + val addServerOrNewServer = count - 2 + + if (position == footer) { + return ViewTypes.FOOTER.ordinal + } else if (position == addServerOrNewServer) { + if (enteringNewServer) { + return ViewTypes.EDIT_SERVER.ordinal } else { - return ViewTypes.FOOTER.ordinal + return ViewTypes.ADD_SERVER.ordinal } } else { - return ViewTypes.FOOTER.ordinal + throw RuntimeException("Too many items in the custom DNS list") } } @@ -56,6 +70,10 @@ class CustomDnsAdapter(val customDns: CustomDns) : Adapter<CustomDnsItemHolder>( val view = inflater.inflate(R.layout.add_custom_dns_server, parentView, false) return AddCustomDnsServerHolder(view) } + ViewTypes.EDIT_SERVER -> { + val view = inflater.inflate(R.layout.edit_custom_dns_server, parentView, false) + return EditCustomDnsServerHolder(view) + } } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt new file mode 100644 index 0000000000..a55f0b87c2 --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/customdns/EditCustomDnsServerHolder.kt @@ -0,0 +1,5 @@ +package net.mullvad.mullvadvpn.ui.customdns + +import android.view.View + +class EditCustomDnsServerHolder(view: View) : CustomDnsItemHolder(view) |
