From cec3dd873eabb8b45901bdde96d5a35142fdf6fd Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:40:39 -0300 Subject: [PATCH] wips --- AnkiDroid/src/main/AndroidManifest.xml | 1 - .../com/ichi2/anki/preferences/Preferences.kt | 20 +++++---------- .../main/res/layout-sw600dp/preferences.xml | 11 +++++--- AnkiDroid/src/main/res/layout/preferences.xml | 25 ++++++++++++++++--- .../src/main/res/values-sw600dp/bools.xml | 4 +++ AnkiDroid/src/main/res/values/bools.xml | 4 +++ 6 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 AnkiDroid/src/main/res/values-sw600dp/bools.xml create mode 100644 AnkiDroid/src/main/res/values/bools.xml diff --git a/AnkiDroid/src/main/AndroidManifest.xml b/AnkiDroid/src/main/AndroidManifest.xml index 2bb50d5a9832..018f9638a43b 100644 --- a/AnkiDroid/src/main/AndroidManifest.xml +++ b/AnkiDroid/src/main/AndroidManifest.xml @@ -344,7 +344,6 @@ diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt index 102b10b54393..a67913153357 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt @@ -28,7 +28,6 @@ import androidx.annotation.VisibleForTesting import androidx.annotation.XmlRes import androidx.core.content.edit import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentContainerView import androidx.fragment.app.commit import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -54,8 +53,8 @@ class Preferences : PreferenceFragmentCompat.OnPreferenceStartFragmentCallback, SearchPreferenceResultListener { - private fun hasLateralNavigation(): Boolean { - return findViewById(R.id.lateral_nav_container) != null + private fun isSw600dp(): Boolean { + return resources.getBoolean(R.bool.is_sw600dp) } override fun onTitleChanged(title: CharSequence?, color: Int) { @@ -96,7 +95,7 @@ class Preferences : private fun loadInitialFragment() { val fragmentClassName = intent?.getStringExtra(INITIAL_FRAGMENT_EXTRA) val initialFragment = if (fragmentClassName == null) { - if (hasLateralNavigation()) GeneralSettingsFragment() else HeaderFragment() + if (isSw600dp()) GeneralSettingsFragment() else HeaderFragment() } else { try { getInstanceFromClassName(fragmentClassName) @@ -105,13 +104,7 @@ class Preferences : } } supportFragmentManager.commit { - // In tablets, show the headers fragment at the lateral navigation container - if (hasLateralNavigation()) { - replace(R.id.lateral_nav_container, HeaderFragment()) - replace(R.id.settings_container, initialFragment, initialFragment::class.java.name) - } else { - replace(R.id.settings_container, initialFragment, initialFragment::class.java.name) - } + replace(R.id.settings_container, initialFragment, initialFragment::class.java.name) } } @@ -121,8 +114,7 @@ class Preferences : ): Boolean { // avoid reopening the same fragment if already active val currentFragment = supportFragmentManager.findFragmentById(R.id.settings_container) - ?: return true - if (pref.fragment == currentFragment::class.jvmName) return true + if (currentFragment != null && pref.fragment == currentFragment::class.jvmName) return true val fragment = supportFragmentManager.fragmentFactory.instantiate( classLoader, @@ -138,7 +130,7 @@ class Preferences : override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - if (hasLateralNavigation()) { + if (isSw600dp()) { finish() } else { onBackPressedDispatcher.onBackPressed() diff --git a/AnkiDroid/src/main/res/layout-sw600dp/preferences.xml b/AnkiDroid/src/main/res/layout-sw600dp/preferences.xml index a9ee452cef6b..545c9b38690d 100644 --- a/AnkiDroid/src/main/res/layout-sw600dp/preferences.xml +++ b/AnkiDroid/src/main/res/layout-sw600dp/preferences.xml @@ -43,7 +43,7 @@ + app:layout_constraintWidth_percent="0.33" + android:name="com.ichi2.anki.preferences.HeaderFragment"/> + app:layout_constraintBottom_toBottomOf="parent" + android:name="com.ichi2.anki.preferences.HeaderFragment" + /> diff --git a/AnkiDroid/src/main/res/layout/preferences.xml b/AnkiDroid/src/main/res/layout/preferences.xml index b443e5a86168..ef22b715c18b 100644 --- a/AnkiDroid/src/main/res/layout/preferences.xml +++ b/AnkiDroid/src/main/res/layout/preferences.xml @@ -51,10 +51,27 @@ - + android:layout_height="match_parent"> + + + + + + diff --git a/AnkiDroid/src/main/res/values-sw600dp/bools.xml b/AnkiDroid/src/main/res/values-sw600dp/bools.xml new file mode 100644 index 000000000000..1acc21e8fa72 --- /dev/null +++ b/AnkiDroid/src/main/res/values-sw600dp/bools.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/AnkiDroid/src/main/res/values/bools.xml b/AnkiDroid/src/main/res/values/bools.xml new file mode 100644 index 000000000000..7ef77206c9d7 --- /dev/null +++ b/AnkiDroid/src/main/res/values/bools.xml @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file