summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-09-15 21:32:41 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-09-23 21:40:50 +0000
commit24f15ef812601188dceb39699df379eccab8a2b6 (patch)
treeddf656c54a4cc3ea25efaead25d96987d97a6ab9 /android/src/main
parent929d420fb70caf624a85475b6337446fb4155ad6 (diff)
downloadmullvadvpn-24f15ef812601188dceb39699df379eccab8a2b6.tar.xz
mullvadvpn-24f15ef812601188dceb39699df379eccab8a2b6.zip
Replace `ListView` with `RecyclerView`
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt39
-rw-r--r--android/src/main/res/layout/account_login.xml9
2 files changed, 20 insertions, 28 deletions
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 ac17ce7956..7996f94285 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
@@ -3,14 +3,14 @@ package net.mullvad.mullvadvpn.ui.widget
import android.animation.ValueAnimator
import android.app.Activity
import android.content.Context
+import android.support.v7.widget.LinearLayoutManager
+import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnLayoutChangeListener
import android.view.ViewGroup.MarginLayoutParams
import android.view.inputmethod.InputMethodManager
-import android.widget.ArrayAdapter
-import android.widget.ListView
import android.widget.RelativeLayout
import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
@@ -26,9 +26,13 @@ class AccountLogin : RelativeLayout {
}
private val border: AccountLoginBorder = container.findViewById(R.id.border)
- private val accountHistoryList: ListView = container.findViewById(R.id.history)
+ private val accountHistoryList: RecyclerView = container.findViewById(R.id.history)
private val input: AccountInput = container.findViewById(R.id.input)
+ private val historyAdapter = AccountHistoryAdapter().apply {
+ onSelectEntry = { account -> input.loginWith(account) }
+ }
+
private val dividerHeight = resources.getDimensionPixelSize(R.dimen.account_history_divider)
private val historyEntryHeight =
resources.getDimensionPixelSize(R.dimen.account_history_entry_height)
@@ -81,7 +85,10 @@ class AccountLogin : RelativeLayout {
val entryCount = history?.size ?: 0
historyHeight = entryCount * (historyEntryHeight + dividerHeight)
- updateAccountHistory()
+
+ if (history != null) {
+ historyAdapter.accountHistory = history
+ }
}
var state: LoginState by observable(LoginState.Initial) { _, _, newState ->
@@ -133,6 +140,11 @@ class AccountLogin : RelativeLayout {
}
)
}
+
+ accountHistoryList.apply {
+ layoutManager = LinearLayoutManager(context)
+ adapter = historyAdapter
+ }
}
fun onDestroy() {
@@ -140,25 +152,6 @@ class AccountLogin : RelativeLayout {
input.onTextChanged.unsubscribe(this)
}
- private fun updateAccountHistory() {
- accountHistory?.let { history ->
- accountHistoryList.apply {
- setAdapter(
- ArrayAdapter(
- context,
- R.layout.account_history_entry,
- R.id.label,
- history
- )
- )
-
- setOnItemClickListener { _, _, idx, _ ->
- input.loginWith(history[idx])
- }
- }
- }
- }
-
private fun updateBorder() {
if (state == LoginState.Failure) {
border.borderState = BorderState.ERROR
diff --git a/android/src/main/res/layout/account_login.xml b/android/src/main/res/layout/account_login.xml
index 7ce8e27113..d91222c73f 100644
--- a/android/src/main/res/layout/account_login.xml
+++ b/android/src/main/res/layout/account_login.xml
@@ -9,9 +9,8 @@
android:layout_height="48dp"
android:layout_alignParentTop="true"
android:orientation="horizontal" />
- <ListView android:id="@+id/history"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/input"
- android:dividerHeight="@dimen/account_history_divider" />
+ <android.support.v7.widget.RecyclerView android:id="@+id/history"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/input" />
</merge>