Update settings ui and fix crash

master
Koitharu 2 years ago
parent bbdf1c756e
commit a71e2dd289
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -92,8 +92,7 @@ abstract class BaseActivity<B : ViewBinding> :
} }
override fun onSupportNavigateUp(): Boolean { override fun onSupportNavigateUp(): Boolean {
if (supportFragmentManager.backStackEntryCount > 0) { if (supportFragmentManager.popBackStackImmediate()) {
supportFragmentManager.popBackStack()
return false return false
} }
dispatchNavigateUp() dispatchNavigateUp()

@ -11,7 +11,6 @@ import androidx.core.graphics.Insets
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.FragmentTransaction
import androidx.fragment.app.commit import androidx.fragment.app.commit
import androidx.preference.Preference import androidx.preference.Preference
@ -21,9 +20,7 @@ import dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ui.BaseActivity import org.koitharu.kotatsu.core.ui.BaseActivity
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
import org.koitharu.kotatsu.core.util.ext.getSerializableExtraCompat import org.koitharu.kotatsu.core.util.ext.getSerializableExtraCompat
import org.koitharu.kotatsu.core.util.ext.isScrolledToTop
import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.core.util.ext.textAndVisible
import org.koitharu.kotatsu.databinding.ActivitySettingsBinding import org.koitharu.kotatsu.databinding.ActivitySettingsBinding
import org.koitharu.kotatsu.main.ui.owners.AppBarOwner import org.koitharu.kotatsu.main.ui.owners.AppBarOwner
@ -39,17 +36,18 @@ import org.koitharu.kotatsu.settings.userdata.UserDataSettingsFragment
class SettingsActivity : class SettingsActivity :
BaseActivity<ActivitySettingsBinding>(), BaseActivity<ActivitySettingsBinding>(),
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback, PreferenceFragmentCompat.OnPreferenceStartFragmentCallback,
AppBarOwner, AppBarOwner {
FragmentManager.OnBackStackChangedListener {
override val appBar: AppBarLayout override val appBar: AppBarLayout
get() = viewBinding.appbar get() = viewBinding.appbar
private val isMasterDetails
get() = viewBinding.containerMaster != null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(ActivitySettingsBinding.inflate(layoutInflater)) setContentView(ActivitySettingsBinding.inflate(layoutInflater))
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
val isMasterDetails = viewBinding.containerMaster != null
val fm = supportFragmentManager val fm = supportFragmentManager
val currentFragment = fm.findFragmentById(R.id.container) val currentFragment = fm.findFragmentById(R.id.container)
if (currentFragment == null || (isMasterDetails && currentFragment is RootSettingsFragment)) { if (currentFragment == null || (isMasterDetails && currentFragment is RootSettingsFragment)) {
@ -63,21 +61,6 @@ class SettingsActivity :
} }
} }
override fun onTitleChanged(title: CharSequence?, color: Int) {
super.onTitleChanged(title, color)
viewBinding.collapsingToolbarLayout?.title = title
}
override fun onStart() {
super.onStart()
supportFragmentManager.addOnBackStackChangedListener(this)
}
override fun onStop() {
supportFragmentManager.removeOnBackStackChangedListener(this)
super.onStop()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
super.onCreateOptionsMenu(menu) super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.opt_settings, menu) menuInflater.inflate(R.menu.opt_settings, menu)
@ -110,14 +93,6 @@ class SettingsActivity :
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
override fun onBackStackChanged() {
val fragment = supportFragmentManager.findFragmentById(R.id.container) as? RecyclerViewOwner ?: return
val recyclerView = fragment.recyclerView
recyclerView.post {
viewBinding.appbar.setExpanded(recyclerView.isScrolledToTop, false)
}
}
override fun onPreferenceStartFragment( override fun onPreferenceStartFragment(
caller: PreferenceFragmentCompat, caller: PreferenceFragmentCompat,
pref: Preference, pref: Preference,
@ -147,19 +122,17 @@ class SettingsActivity :
fun openFragment(fragment: Fragment, isFromRoot: Boolean) { fun openFragment(fragment: Fragment, isFromRoot: Boolean) {
val hasFragment = supportFragmentManager.findFragmentById(R.id.container) != null val hasFragment = supportFragmentManager.findFragmentById(R.id.container) != null
val isMasterDetail = viewBinding.containerMaster != null
supportFragmentManager.commit { supportFragmentManager.commit {
setReorderingAllowed(true) setReorderingAllowed(true)
replace(R.id.container, fragment) replace(R.id.container, fragment)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN) setTransition(FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN)
if (!isMasterDetail || (hasFragment && !isFromRoot)) { if (!isMasterDetails || (hasFragment && !isFromRoot)) {
addToBackStack(null) addToBackStack(null)
} }
} }
} }
private fun openDefaultFragment() { private fun openDefaultFragment() {
val hasMaster = viewBinding.containerMaster != null
val fragment = when (intent?.action) { val fragment = when (intent?.action) {
ACTION_READER -> ReaderSettingsFragment() ACTION_READER -> ReaderSettingsFragment()
ACTION_SUGGESTIONS -> SuggestionsSettingsFragment() ACTION_SUGGESTIONS -> SuggestionsSettingsFragment()
@ -181,7 +154,7 @@ class SettingsActivity :
} }
else -> null else -> null
} ?: if (hasMaster) AppearanceSettingsFragment() else RootSettingsFragment() } ?: if (isMasterDetails) AppearanceSettingsFragment() else RootSettingsFragment()
supportFragmentManager.commit { supportFragmentManager.commit {
setReorderingAllowed(true) setReorderingAllowed(true)
replace(R.id.container, fragment) replace(R.id.container, fragment)

@ -11,22 +11,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
style="?collapsingToolbarLayoutMediumStyle"
android:layout_width="match_parent"
android:layout_height="?collapsingToolbarLayoutMediumSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:toolbarId="@id/toolbar">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@id/toolbar" android:id="@id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" /> app:layout_collapseMode="pin" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView

@ -42,6 +42,7 @@
</string-array> </string-array>
<string-array name="sync_host_list" translatable="false"> <string-array name="sync_host_list" translatable="false">
<item>@string/sync_host_default</item> <item>@string/sync_host_default</item>
<item>moe.shirizu.org</item>
<item>86.57.183.214:8081</item> <item>86.57.183.214:8081</item>
</string-array> </string-array>
<string-array name="values_proxy_types" translatable="false"> <string-array name="values_proxy_types" translatable="false">

Loading…
Cancel
Save