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,17 +203,18 @@ class MainActivity : AppCompatActivity() {
// Return candidate when span index matches
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)
}
}
}
View.FOCUS_UP -> {
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
}

View File

@ -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<View>(android.R.id.content).viewTreeObserver.addOnTouchModeChangeListener { isInTouchMode ->
if (!isInTouchMode) binding.titlebar.appBarLayout.setExpanded(false)
}
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, preferenceFragment)

View File

@ -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">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"