diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-30 11:11:57 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-30 11:11:57 -0300 |
| commit | a75e2052b4525f8879866b1e13a7545dc88d4608 (patch) | |
| tree | 99c240a4f2d6af745de3e2e7f11e10d754fcef4a /android/src | |
| parent | bd1b38845b91541c2f7964ad5eae5b72ff4938fc (diff) | |
| parent | e50709b5472a98ab0461009b0563a7b838300796 (diff) | |
| download | mullvadvpn-a75e2052b4525f8879866b1e13a7545dc88d4608.tar.xz mullvadvpn-a75e2052b4525f8879866b1e13a7545dc88d4608.zip | |
Merge branch 'remove-account-from-history-with-keyboard'
Diffstat (limited to 'android/src')
4 files changed, 25 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/LoginFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/LoginFragment.kt index d713759c3c..fa5df39a0e 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/LoginFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/LoginFragment.kt @@ -95,11 +95,21 @@ class LoginFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) { accountLogin.accountHistory = history } } + + parentActivity.backButtonHandler = { + if (accountLogin.hasFocus) { + background.requestFocus() + true + } else { + false + } + } } override fun onSafelyStop() { jobTracker.cancelJob("advanceToNextScreen") accountCache.onAccountHistoryChange.unsubscribe(this) + parentActivity.backButtonHandler = null } private fun scrollToShow(view: View) { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index a7a6f3dbef..44996b55b8 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -77,6 +77,8 @@ class MainActivity : FragmentActivity() { } } + var backButtonHandler: (() -> Boolean)? = null + override fun onCreate(savedInstanceState: Bundle?) { if (deviceIsTv) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) @@ -122,6 +124,14 @@ class MainActivity : FragmentActivity() { setVpnPermission(resultCode == Activity.RESULT_OK) } + override fun onBackPressed() { + val handled = backButtonHandler?.invoke() ?: false + + if (!handled) { + super.onBackPressed() + } + } + override fun onStop() { android.util.Log.d("mullvad", "Stoping main activity") isUiVisible = false 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 9052a2e63e..58051411ff 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 @@ -95,6 +95,9 @@ class AccountLogin : RelativeLayout { } } + val hasFocus + get() = focused + var accountHistory by observable<ArrayList<String>?>(null) { _, _, history -> val entryCount = history?.size ?: 0 diff --git a/android/src/main/res/layout/account_history_entry.xml b/android/src/main/res/layout/account_history_entry.xml index 746de82d3c..c31782c0bd 100644 --- a/android/src/main/res/layout/account_history_entry.xml +++ b/android/src/main/res/layout/account_history_entry.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" + android:nextFocusRight="@id/remove" android:background="@drawable/account_history_entry_background" android:paddingHorizontal="12dp" android:gravity="center_vertical" @@ -15,6 +16,7 @@ android:layout_width="@dimen/account_history_entry_height" android:layout_height="@dimen/account_history_entry_height" android:layout_gravity="right" + android:nextFocusLeft="@id/remove" android:background="?android:attr/selectableItemBackground" android:src="@drawable/account_history_remove" /> </FrameLayout> |
