Remember last opened section
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package org.koitharu.kotatsu.core.prefs
|
||||
|
||||
enum class AppSection {
|
||||
|
||||
LOCAL, FAVOURITES, HISTORY;
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.core.prefs
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Resources
|
||||
import android.os.StatFs
|
||||
import android.provider.Settings
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.content.edit
|
||||
@@ -27,6 +26,12 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
||||
ListMode.DETAILED_LIST
|
||||
)
|
||||
|
||||
var defaultSection by EnumPreferenceDelegate(
|
||||
AppSection::class.java,
|
||||
resources.getString(R.string.key_app_section),
|
||||
AppSection.HISTORY
|
||||
)
|
||||
|
||||
val theme by StringIntPreferenceDelegate(
|
||||
resources.getString(R.string.key_theme),
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
package org.koitharu.kotatsu.core.prefs
|
||||
|
||||
enum class ListMode(val id: Int) {
|
||||
enum class ListMode {
|
||||
|
||||
LIST(0),
|
||||
DETAILED_LIST(1),
|
||||
GRID(2);
|
||||
|
||||
companion object {
|
||||
|
||||
fun valueOf(id: Int) = values().firstOrNull { it.id == id }
|
||||
}
|
||||
LIST, DETAILED_LIST, GRID;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import moxy.ktx.moxyPresenter
|
||||
import org.koin.core.inject
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.prefs.AppSection
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
@@ -65,8 +66,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
supportFragmentManager.findFragmentById(R.id.container)?.let {
|
||||
fab.isVisible = it is HistoryListFragment
|
||||
} ?: run {
|
||||
navigationView.setCheckedItem(R.id.nav_history)
|
||||
setPrimaryFragment(HistoryListFragment.newInstance())
|
||||
openDefaultSection()
|
||||
}
|
||||
drawer.postDelayed(2000) {
|
||||
AppUpdateService.startIfRequired(applicationContext)
|
||||
@@ -106,9 +106,18 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
val source = MangaSource.values().getOrNull(item.itemId) ?: return false
|
||||
setPrimaryFragment(RemoteListFragment.newInstance(source))
|
||||
} else when (item.itemId) {
|
||||
R.id.nav_history -> setPrimaryFragment(HistoryListFragment.newInstance())
|
||||
R.id.nav_favourites -> setPrimaryFragment(FavouritesContainerFragment.newInstance())
|
||||
R.id.nav_local_storage -> setPrimaryFragment(LocalListFragment.newInstance())
|
||||
R.id.nav_history -> {
|
||||
settings.defaultSection = AppSection.HISTORY
|
||||
setPrimaryFragment(HistoryListFragment.newInstance())
|
||||
}
|
||||
R.id.nav_favourites -> {
|
||||
settings.defaultSection = AppSection.FAVOURITES
|
||||
setPrimaryFragment(FavouritesContainerFragment.newInstance())
|
||||
}
|
||||
R.id.nav_local_storage -> {
|
||||
settings.defaultSection = AppSection.LOCAL
|
||||
setPrimaryFragment(LocalListFragment.newInstance())
|
||||
}
|
||||
R.id.nav_action_settings -> {
|
||||
startActivity(SettingsActivity.newIntent(this))
|
||||
return true
|
||||
@@ -167,6 +176,23 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
}
|
||||
}
|
||||
|
||||
private fun openDefaultSection() {
|
||||
when(settings.defaultSection) {
|
||||
AppSection.LOCAL -> {
|
||||
navigationView.setCheckedItem(R.id.nav_local_storage)
|
||||
setPrimaryFragment(LocalListFragment.newInstance())
|
||||
}
|
||||
AppSection.FAVOURITES -> {
|
||||
navigationView.setCheckedItem(R.id.nav_favourites)
|
||||
setPrimaryFragment(FavouritesContainerFragment.newInstance())
|
||||
}
|
||||
AppSection.HISTORY -> {
|
||||
navigationView.setCheckedItem(R.id.nav_history)
|
||||
setPrimaryFragment(HistoryListFragment.newInstance())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setPrimaryFragment(fragment: Fragment) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, fragment)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="key_list_mode">list_mode</string>
|
||||
<string name="key_app_section">app_section</string>
|
||||
<string name="key_theme">theme</string>
|
||||
<string name="key_sources_order">sources_order</string>
|
||||
<string name="key_sources_hidden">sources_hidden</string>
|
||||
|
||||
Reference in New Issue
Block a user