Skip to content

Commit

Permalink
wips
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Apr 26, 2024
1 parent b1b3ee8 commit cec3dd8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
1 change: 0 additions & 1 deletion AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@
<activity
android:name="com.ichi2.anki.preferences.Preferences"
android:exported="false"
android:configChanges="screenSize"
>
<intent-filter>
<category android:name="android.intent.category.MONKEY" />
Expand Down
20 changes: 6 additions & 14 deletions AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,8 +53,8 @@ class Preferences :
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback,
SearchPreferenceResultListener {

private fun hasLateralNavigation(): Boolean {
return findViewById<FragmentContainerView>(R.id.lateral_nav_container) != null
private fun isSw600dp(): Boolean {
return resources.getBoolean(R.bool.is_sw600dp)
}

override fun onTitleChanged(title: CharSequence?, color: Int) {
Expand Down Expand Up @@ -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<Fragment>(fragmentClassName)
Expand All @@ -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)
}
}

Expand All @@ -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,
Expand All @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions AnkiDroid/src/main/res/layout-sw600dp/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</com.google.android.material.appbar.AppBarLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/lateral_nav_container"
android:id="@+id/header_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -52,16 +52,19 @@
app:layout_constraintTop_toBottomOf="@id/appbar"
app:layout_constraintWidth_max="400dp"
app:layout_constraintWidth_min="320dp"
app:layout_constraintWidth_percent="0.33"/>
app:layout_constraintWidth_percent="0.33"
android:name="com.ichi2.anki.preferences.HeaderFragment"/>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/settings_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toEndOf="@id/lateral_nav_container"
app:layout_constraintStart_toEndOf="@id/header_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toBottomOf="parent"
android:name="com.ichi2.anki.preferences.HeaderFragment"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
25 changes: 21 additions & 4 deletions AnkiDroid/src/main/res/layout/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,27 @@

</com.google.android.material.appbar.AppBarLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/settings_container"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
android:layout_height="match_parent">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:name="com.ichi2.anki.preferences.HeaderFragment"
android:background="@color/flag_red"
/>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:background="@color/flag_pink"
/>

</RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
4 changes: 4 additions & 0 deletions AnkiDroid/src/main/res/values-sw600dp/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_sw600dp">true</bool>
</resources>
4 changes: 4 additions & 0 deletions AnkiDroid/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_sw600dp">false</bool>
</resources>

0 comments on commit cec3dd8

Please sign in to comment.