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
|
||||
get() = prefs.getBoolean(KEY_THEME_AMOLED, false)
|
||||
|
||||
val isFavoritesNavItemFirst: Boolean
|
||||
get() = (prefs.getString(KEY_FIRST_NAV_ITEM, null)?.toIntOrNull() ?: 0) == 1
|
||||
|
||||
var gridSize: Int
|
||||
get() = prefs.getInt(KEY_GRID_SIZE, 100)
|
||||
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_DISABLE_NSFW = "no_nsfw"
|
||||
const val KEY_RELATED_MANGA = "related_manga"
|
||||
const val KEY_FIRST_NAV_ITEM = "nav_first"
|
||||
|
||||
// About
|
||||
const val KEY_APP_UPDATE = "app_update"
|
||||
|
||||
@@ -25,4 +25,9 @@ class ActivityRecreationHandle @Inject constructor() : DefaultActivityLifecycleC
|
||||
val snapshot = activities.keys.toList()
|
||||
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()
|
||||
|
||||
fun Lifecycle.postDelayed(runnable: Runnable, delay: Long) {
|
||||
fun Lifecycle.postDelayed(delay: Long, runnable: Runnable) {
|
||||
coroutineScope.launch {
|
||||
delay(delay)
|
||||
runnable.run()
|
||||
|
||||
@@ -116,9 +116,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), AppBarOwner, BottomNav
|
||||
navigationDelegate = MainNavigationDelegate(
|
||||
navBar = checkNotNull(bottomNav ?: viewBinding.navRail),
|
||||
fragmentManager = supportFragmentManager,
|
||||
settings = settings,
|
||||
)
|
||||
navigationDelegate.addOnFragmentChangedListener(this)
|
||||
navigationDelegate.onCreate()
|
||||
navigationDelegate.onCreate(savedInstanceState)
|
||||
|
||||
appUpdateBadge = OptionsMenuBadgeHelper(viewBinding.toolbar, R.id.action_app_update)
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package org.koitharu.kotatsu.main.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.core.view.isEmpty
|
||||
import androidx.core.view.iterator
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import com.google.android.material.transition.MaterialFadeThrough
|
||||
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.util.ext.firstVisibleItemPosition
|
||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||
@@ -23,7 +26,10 @@ private const val TAG_PRIMARY = "primary"
|
||||
class MainNavigationDelegate(
|
||||
private val navBar: NavigationBarView,
|
||||
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>()
|
||||
|
||||
@@ -56,14 +62,26 @@ class MainNavigationDelegate(
|
||||
navBar.selectedItemId = R.id.nav_history
|
||||
}
|
||||
|
||||
fun onCreate() {
|
||||
primaryFragment?.let {
|
||||
onFragmentChanged(it, fromUser = false)
|
||||
val itemId = getItemId(it)
|
||||
fun onCreate(savedInstanceState: Bundle?) {
|
||||
if (navBar.menu.isEmpty()) {
|
||||
val menuRes = if (settings.isFavoritesNavItemFirst) R.menu.nav_bottom_alt else R.menu.nav_bottom
|
||||
navBar.inflateMenu(menuRes)
|
||||
}
|
||||
val fragment = primaryFragment
|
||||
if (fragment != null) {
|
||||
onFragmentChanged(fragment, fromUser = false)
|
||||
val itemId = getItemId(fragment)
|
||||
if (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) {
|
||||
|
||||
@@ -163,7 +163,7 @@ class ReaderActivity :
|
||||
readerManager.replace(mode)
|
||||
}
|
||||
if (viewBinding.appbarTop.isVisible) {
|
||||
lifecycle.postDelayed(hideUiRunnable, TimeUnit.SECONDS.toMillis(1))
|
||||
lifecycle.postDelayed(TimeUnit.SECONDS.toMillis(1), hideUiRunnable)
|
||||
}
|
||||
viewBinding.slider.isRtl = mode == ReaderMode.REVERSED
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.provider.Settings
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.LocaleManagerCompat
|
||||
import androidx.core.view.postDelayed
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
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.util.ext.getLocalesConfig
|
||||
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.toList
|
||||
import org.koitharu.kotatsu.main.ui.MainActivity
|
||||
import org.koitharu.kotatsu.parsers.util.names
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import org.koitharu.kotatsu.settings.utils.ActivityListPreference
|
||||
@@ -92,11 +93,15 @@ class AppearanceSettingsFragment :
|
||||
AppSettings.KEY_APP_LOCALE -> {
|
||||
AppCompatDelegate.setApplicationLocales(settings.appLocales)
|
||||
}
|
||||
|
||||
AppSettings.KEY_FIRST_NAV_ITEM -> {
|
||||
activityRecreationHandle.recreate(MainActivity::class.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun postRestart() {
|
||||
view?.postDelayed(400) {
|
||||
viewLifecycleOwner.lifecycle.postDelayed(400) {
|
||||
activityRecreationHandle.recreateAll()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
app:headerLayout="@layout/navigation_rail_fab"
|
||||
app:labelVisibilityMode="labeled"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:menu="@menu/nav_bottom" />
|
||||
tools:menu="@menu/nav_bottom" />
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:clickable="true"
|
||||
app:menu="@menu/nav_bottom"
|
||||
tools:ignore="KeyboardInaccessibleWidget" />
|
||||
tools:ignore="KeyboardInaccessibleWidget"
|
||||
tools:menu="@menu/nav_bottom" />
|
||||
|
||||
</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/advanced</item>
|
||||
</string-array>
|
||||
<string name="advanced">Advanced</string>
|
||||
<string-array name="first_nav_item">
|
||||
<item>@string/history</item>
|
||||
<item>@string/favourites</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -60,4 +60,8 @@
|
||||
<item>#21005E</item>
|
||||
<item>#7D5260</item>
|
||||
</string-array>
|
||||
<string-array name="values_first_nav_item" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -475,4 +475,5 @@
|
||||
<string name="disable_nsfw">Disable NSFW</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="advanced">Advanced</string>
|
||||
</resources>
|
||||
|
||||
@@ -55,10 +55,18 @@
|
||||
|
||||
</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
|
||||
android:key="app_locale"
|
||||
android:title="@string/language"
|
||||
app:allowDividerAbove="true" />
|
||||
android:title="@string/language" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
|
||||
Reference in New Issue
Block a user