Option to swap first two navigation items
This commit is contained in:
@@ -51,6 +51,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val isAmoledTheme: Boolean
|
val isAmoledTheme: Boolean
|
||||||
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
||||||
|
|
||||||
|
val isFavoritesNavItemFirst: Boolean
|
||||||
|
get() = (prefs.getString(KEY_FIRST_NAV_ITEM, null)?.toIntOrNull() ?: 0) == 1
|
||||||
|
|
||||||
var gridSize: Int
|
var gridSize: Int
|
||||||
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
||||||
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
set(value) = prefs.edit { putInt(KEY_GRID_SIZE, value) }
|
||||||
@@ -452,6 +455,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
const val KEY_LOCAL_MANGA_DIRS = "local_manga_dirs"
|
const val KEY_LOCAL_MANGA_DIRS = "local_manga_dirs"
|
||||||
const val KEY_DISABLE_NSFW = "no_nsfw"
|
const val KEY_DISABLE_NSFW = "no_nsfw"
|
||||||
const val KEY_RELATED_MANGA = "related_manga"
|
const val KEY_RELATED_MANGA = "related_manga"
|
||||||
|
const val KEY_FIRST_NAV_ITEM = "nav_first"
|
||||||
|
|
||||||
// About
|
// About
|
||||||
const val KEY_APP_UPDATE = "app_update"
|
const val KEY_APP_UPDATE = "app_update"
|
||||||
|
|||||||
@@ -25,4 +25,9 @@ class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleC
|
|||||||
val snapshot = activities.keys.toList()
|
val snapshot = activities.keys.toList()
|
||||||
snapshot.forEach { ActivityCompat.recreate(it) }
|
snapshot.forEach { ActivityCompat.recreate(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun recreate(cls: Class<out Activity>) {
|
||||||
|
val activity = activities.keys.find { x -> x.javaClass == cls } ?: return
|
||||||
|
ActivityCompat.recreate(activity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ fun <T> SharedPreferences.observe(key: String, valueProducer: suspend () -> T):
|
|||||||
}
|
}
|
||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
|
|
||||||
fun Lifecycle.postDelayed(runnable: Runnable, delay: Long) {
|
fun Lifecycle.postDelayed(delay: Long, runnable: Runnable) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
delay(delay)
|
delay(delay)
|
||||||
runnable.run()
|
runnable.run()
|
||||||
|
|||||||
@@ -116,9 +116,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
|||||||
navigationDelegate = MainNavigationDelegate(
|
navigationDelegate = MainNavigationDelegate(
|
||||||
navBar = checkNotNull(bottomNav ?: viewBinding.navRail),
|
navBar = checkNotNull(bottomNav ?: viewBinding.navRail),
|
||||||
fragmentManager = supportFragmentManager,
|
fragmentManager = supportFragmentManager,
|
||||||
|
settings = settings,
|
||||||
)
|
)
|
||||||
navigationDelegate.addOnFragmentChangedListener(this)
|
navigationDelegate.addOnFragmentChangedListener(this)
|
||||||
navigationDelegate.onCreate()
|
navigationDelegate.onCreate(savedInstanceState)
|
||||||
|
|
||||||
appUpdateBadge = OptionsMenuBadgeHelper(viewBinding.toolbar, R.id.action_app_update)
|
appUpdateBadge = OptionsMenuBadgeHelper(viewBinding.toolbar, R.id.action_app_update)
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.main.ui
|
package org.koitharu.kotatsu.main.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.core.view.isEmpty
|
||||||
import androidx.core.view.iterator
|
import androidx.core.view.iterator
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.google.android.material.navigation.NavigationBarView
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
import com.google.android.material.transition.MaterialFadeThrough
|
import com.google.android.material.transition.MaterialFadeThrough
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
import org.koitharu.kotatsu.core.ui.util.RecyclerViewOwner
|
||||||
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
@@ -23,7 +26,10 @@ private const val TAG_PRIMARY = "primary"
|
|||||||
class MainNavigationDelegate(
|
class MainNavigationDelegate(
|
||||||
private val navBar: NavigationBarView,
|
private val navBar: NavigationBarView,
|
||||||
private val fragmentManager: FragmentManager,
|
private val fragmentManager: FragmentManager,
|
||||||
) : OnBackPressedCallback(false), NavigationBarView.OnItemSelectedListener, NavigationBarView.OnItemReselectedListener {
|
private val settings: AppSettings,
|
||||||
|
) : OnBackPressedCallback(false),
|
||||||
|
NavigationBarView.OnItemSelectedListener,
|
||||||
|
NavigationBarView.OnItemReselectedListener {
|
||||||
|
|
||||||
private val listeners = LinkedList<OnFragmentChangedListener>()
|
private val listeners = LinkedList<OnFragmentChangedListener>()
|
||||||
|
|
||||||
@@ -56,14 +62,26 @@ class MainNavigationDelegate(
|
|||||||
navBar.selectedItemId = R.id.nav_history
|
navBar.selectedItemId = R.id.nav_history
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCreate() {
|
fun onCreate(savedInstanceState: Bundle?) {
|
||||||
primaryFragment?.let {
|
if (navBar.menu.isEmpty()) {
|
||||||
onFragmentChanged(it, fromUser = false)
|
val menuRes = if (settings.isFavoritesNavItemFirst) R.menu.nav_bottom_alt else R.menu.nav_bottom
|
||||||
val itemId = getItemId(it)
|
navBar.inflateMenu(menuRes)
|
||||||
|
}
|
||||||
|
val fragment = primaryFragment
|
||||||
|
if (fragment != null) {
|
||||||
|
onFragmentChanged(fragment, fromUser = false)
|
||||||
|
val itemId = getItemId(fragment)
|
||||||
if (navBar.selectedItemId != itemId) {
|
if (navBar.selectedItemId != itemId) {
|
||||||
navBar.selectedItemId = itemId
|
navBar.selectedItemId = itemId
|
||||||
}
|
}
|
||||||
} ?: onNavigationItemSelected(navBar.selectedItemId)
|
} else {
|
||||||
|
val itemId = if (savedInstanceState == null) {
|
||||||
|
firstItem()?.itemId ?: navBar.selectedItemId
|
||||||
|
} else {
|
||||||
|
navBar.selectedItemId
|
||||||
|
}
|
||||||
|
onNavigationItemSelected(itemId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCounterAt(position: Int, counter: Int) {
|
fun setCounterAt(position: Int, counter: Int) {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ class ReaderActivity :
|
|||||||
readerManager.replace(mode)
|
readerManager.replace(mode)
|
||||||
}
|
}
|
||||||
if (viewBinding.appbarTop.isVisible) {
|
if (viewBinding.appbarTop.isVisible) {
|
||||||
lifecycle.postDelayed(hideUiRunnable, TimeUnit.SECONDS.toMillis(1))
|
lifecycle.postDelayed(TimeUnit.SECONDS.toMillis(1), hideUiRunnable)
|
||||||
}
|
}
|
||||||
viewBinding.slider.isRtl = mode == ReaderMode.REVERSED
|
viewBinding.slider.isRtl = mode == ReaderMode.REVERSED
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import android.provider.Settings
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.app.LocaleManagerCompat
|
import androidx.core.app.LocaleManagerCompat
|
||||||
import androidx.core.view.postDelayed
|
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
@@ -21,8 +20,10 @@ import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
|||||||
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
import org.koitharu.kotatsu.core.ui.util.ActivityRecreationHandle
|
||||||
import org.koitharu.kotatsu.core.util.ext.getLocalesConfig
|
import org.koitharu.kotatsu.core.util.ext.getLocalesConfig
|
||||||
import org.koitharu.kotatsu.core.util.ext.map
|
import org.koitharu.kotatsu.core.util.ext.map
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.postDelayed
|
||||||
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat
|
||||||
import org.koitharu.kotatsu.core.util.ext.toList
|
import org.koitharu.kotatsu.core.util.ext.toList
|
||||||
|
import org.koitharu.kotatsu.main.ui.MainActivity
|
||||||
import org.koitharu.kotatsu.parsers.util.names
|
import org.koitharu.kotatsu.parsers.util.names
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
||||||
@@ -92,11 +93,15 @@ class AppearanceSettingsFragment :
|
|||||||
AppSettings.KEY_APP_LOCALE -> {
|
AppSettings.KEY_APP_LOCALE -> {
|
||||||
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppSettings.KEY_FIRST_NAV_ITEM -> {
|
||||||
|
activityRecreationHandle.recreate(MainActivity::class.java)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun postRestart() {
|
private fun postRestart() {
|
||||||
view?.postDelayed(400) {
|
viewLifecycleOwner.lifecycle.postDelayed(400) {
|
||||||
activityRecreationHandle.recreateAll()
|
activityRecreationHandle.recreateAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
app:headerLayout="@layout/navigation_rail_fab"
|
app:headerLayout="@layout/navigation_rail_fab"
|
||||||
app:labelVisibilityMode="labeled"
|
app:labelVisibilityMode="labeled"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:menu="@menu/nav_bottom" />
|
tools:menu="@menu/nav_bottom" />
|
||||||
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
app:menu="@menu/nav_bottom"
|
tools:ignore="KeyboardInaccessibleWidget"
|
||||||
tools:ignore="KeyboardInaccessibleWidget" />
|
tools:menu="@menu/nav_bottom" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|||||||
25
app/src/main/res/menu/nav_bottom_alt.xml
Normal file
25
app/src/main/res/menu/nav_bottom_alt.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_favourites"
|
||||||
|
android:icon="@drawable/ic_favourites_selector"
|
||||||
|
android:title="@string/favourites" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_history"
|
||||||
|
android:icon="@drawable/ic_history_selector"
|
||||||
|
android:title="@string/history" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_explore"
|
||||||
|
android:icon="@drawable/ic_explore_selector"
|
||||||
|
android:title="@string/explore" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_feed"
|
||||||
|
android:icon="@drawable/ic_feed_selector"
|
||||||
|
android:title="@string/feed" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
@@ -70,5 +70,8 @@
|
|||||||
<item>@string/system_default</item>
|
<item>@string/system_default</item>
|
||||||
<item>@string/advanced</item>
|
<item>@string/advanced</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string name="advanced">Advanced</string>
|
<string-array name="first_nav_item">
|
||||||
|
<item>@string/history</item>
|
||||||
|
<item>@string/favourites</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -60,4 +60,8 @@
|
|||||||
<item>#21005E</item>
|
<item>#21005E</item>
|
||||||
<item>#7D5260</item>
|
<item>#7D5260</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="values_first_nav_item" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -475,4 +475,5 @@
|
|||||||
<string name="disable_nsfw">Disable NSFW</string>
|
<string name="disable_nsfw">Disable NSFW</string>
|
||||||
<string name="too_many_requests_message">Too many requests. Try again later</string>
|
<string name="too_many_requests_message">Too many requests. Try again later</string>
|
||||||
<string name="related_manga_summary">Show a list of related manga. In some cases it may be inaccurate or missing</string>
|
<string name="related_manga_summary">Show a list of related manga. In some cases it may be inaccurate or missing</string>
|
||||||
|
<string name="advanced">Advanced</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -55,10 +55,18 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/first_nav_item"
|
||||||
|
android:entryValues="@array/values_first_nav_item"
|
||||||
|
android:key="nav_first"
|
||||||
|
android:title="Default section"
|
||||||
|
app:allowDividerAbove="true"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
<org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
||||||
android:key="app_locale"
|
android:key="app_locale"
|
||||||
android:title="@string/language"
|
android:title="@string/language" />
|
||||||
app:allowDividerAbove="true" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
|
|||||||
Reference in New Issue
Block a user