Rework focus for controller

This commit is contained in:
Willi Ye 2021-04-17 12:41:38 +02:00 committed by ◱ Mark
parent 3c23302b82
commit 7a5684e57f
3 changed files with 12 additions and 8 deletions

View File

@ -203,10 +203,10 @@ class MainActivity : AppCompatActivity() {
// Return candidate when span index matches // Return candidate when span index matches
if (currentSpanIndex == (candidate.layoutParams as LayoutParams).spanIndex) return candidate if (currentSpanIndex == (candidate.layoutParams as LayoutParams).spanIndex) return candidate
} }
if (nextFocus == null) { 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) 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) { if (nextFocus?.isFocusable != true) {
binding.searchBar.requestFocus() binding.searchBar.requestFocus()
binding.appBarLayout.setExpanded(true) binding.appBarLayout.setExpanded(true)
binding.appList.smoothScrollToPosition(0)
return null return null
} }
} }
@ -249,7 +250,7 @@ class MainActivity : AppCompatActivity() {
private fun handleState(state : MainState) = when (state) { private fun handleState(state : MainState) = when (state) {
MainState.Loading -> { MainState.Loading -> {
binding.refreshIcon.animate().rotationBy(-180f) binding.refreshIcon.apply { animate().rotation(rotation - 180f) }
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
} }

View File

@ -7,6 +7,7 @@ package emu.skyline
import android.os.Bundle import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import emu.skyline.databinding.SettingsActivityBinding import emu.skyline.databinding.SettingsActivityBinding
@ -30,6 +31,10 @@ class SettingsActivity : AppCompatActivity() {
setSupportActionBar(binding.titlebar.toolbar) setSupportActionBar(binding.titlebar.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
window.decorView.findViewById<View>(android.R.id.content).viewTreeObserver.addOnTouchModeChangeListener { isInTouchMode ->
if (!isInTouchMode) binding.titlebar.appBarLayout.setExpanded(false)
}
supportFragmentManager supportFragmentManager
.beginTransaction() .beginTransaction()
.replace(R.id.settings, preferenceFragment) .replace(R.id.settings, preferenceFragment)

View File

@ -4,9 +4,7 @@
android:id="@+id/app_bar_layout" android:id="@+id/app_bar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true" android:fitsSystemWindows="true">
android:keyboardNavigationCluster="false"
android:touchscreenBlocksFocus="false">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"