From 7a5684e57ff07b9d4f4bc962bb763354cfad7662 Mon Sep 17 00:00:00 2001 From: Willi Ye Date: Sat, 17 Apr 2021 12:41:38 +0200 Subject: [PATCH] Rework focus for controller --- app/src/main/java/emu/skyline/MainActivity.kt | 11 ++++++----- app/src/main/java/emu/skyline/SettingsActivity.kt | 5 +++++ app/src/main/res/layout/titlebar.xml | 4 +--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index e8a14a54..f1b33b93 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -203,10 +203,10 @@ class MainActivity : AppCompatActivity() { // Return candidate when span index matches if (currentSpanIndex == (candidate.layoutParams as LayoutParams).spanIndex) return candidate } - if (nextFocus == null) { - binding.appBarLayout.setExpanded(false) // End of list, hide app bar, so bottom row is fully visible - binding.appList.smoothScrollToPosition(adapter.itemCount) - } + nextFocus?.let { if ((it.layoutParams as LayoutParams).spanIndex == currentSpanIndex) return nextFocus } + + binding.appBarLayout.setExpanded(false) // End of list, hide app bar, so bottom row is fully visible + binding.appList.smoothScrollToPosition(adapter.itemCount) } } @@ -214,6 +214,7 @@ class MainActivity : AppCompatActivity() { if (nextFocus?.isFocusable != true) { binding.searchBar.requestFocus() binding.appBarLayout.setExpanded(true) + binding.appList.smoothScrollToPosition(0) return null } } @@ -249,7 +250,7 @@ class MainActivity : AppCompatActivity() { private fun handleState(state : MainState) = when (state) { MainState.Loading -> { - binding.refreshIcon.animate().rotationBy(-180f) + binding.refreshIcon.apply { animate().rotation(rotation - 180f) } binding.swipeRefreshLayout.isRefreshing = true } diff --git a/app/src/main/java/emu/skyline/SettingsActivity.kt b/app/src/main/java/emu/skyline/SettingsActivity.kt index e6dde61d..5d80bba5 100644 --- a/app/src/main/java/emu/skyline/SettingsActivity.kt +++ b/app/src/main/java/emu/skyline/SettingsActivity.kt @@ -7,6 +7,7 @@ package emu.skyline import android.os.Bundle import android.view.KeyEvent +import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.preference.PreferenceFragmentCompat import emu.skyline.databinding.SettingsActivityBinding @@ -30,6 +31,10 @@ class SettingsActivity : AppCompatActivity() { setSupportActionBar(binding.titlebar.toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) + window.decorView.findViewById(android.R.id.content).viewTreeObserver.addOnTouchModeChangeListener { isInTouchMode -> + if (!isInTouchMode) binding.titlebar.appBarLayout.setExpanded(false) + } + supportFragmentManager .beginTransaction() .replace(R.id.settings, preferenceFragment) diff --git a/app/src/main/res/layout/titlebar.xml b/app/src/main/res/layout/titlebar.xml index 5e35104a..a283a941 100644 --- a/app/src/main/res/layout/titlebar.xml +++ b/app/src/main/res/layout/titlebar.xml @@ -4,9 +4,7 @@ android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true" - android:keyboardNavigationCluster="false" - android:touchscreenBlocksFocus="false"> + android:fitsSystemWindows="true">