Here lies "currentTab was used multiple times"

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Secozzi 2024-10-31 12:42:05 +01:00
parent 9863bdc631
commit 111db99aff
No known key found for this signature in database
GPG key ID: DD93E0B3A962AA86
21 changed files with 118 additions and 77 deletions

View file

@ -25,7 +25,7 @@ enum class NavStyle(
MOVE_MANGA_TO_MORE(titleRes = MR.strings.pref_bottom_nav_no_manga, moreTab = MangaLibraryTab),
MOVE_UPDATES_TO_MORE(titleRes = MR.strings.pref_bottom_nav_no_updates, moreTab = UpdatesTab),
MOVE_HISTORY_TO_MORE(titleRes = MR.strings.pref_bottom_nav_no_history, moreTab = HistoriesTab),
MOVE_BROWSE_TO_MORE(titleRes = MR.strings.pref_bottom_nav_no_browse, moreTab = BrowseTab()),
MOVE_BROWSE_TO_MORE(titleRes = MR.strings.pref_bottom_nav_no_browse, moreTab = BrowseTab),
;
val moreIcon: ImageVector
@ -44,7 +44,7 @@ enum class NavStyle(
MangaLibraryTab,
UpdatesTab,
HistoriesTab,
BrowseTab(),
BrowseTab,
MoreTab,
).apply { remove(this@NavStyle.moreTab) }
}

View file

@ -14,5 +14,5 @@ enum class StartScreen(val titleRes: StringResource, val tab: Tab) {
MANGA(MR.strings.manga, MangaLibraryTab),
UPDATES(MR.strings.label_recent_updates, UpdatesTab),
HISTORY(MR.strings.label_recent_manga, HistoriesTab),
BROWSE(MR.strings.browse, BrowseTab()),
BROWSE(MR.strings.browse, BrowseTab),
}

View file

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryTabRow
@ -36,24 +37,17 @@ fun TabbedScreen(
titleRes: StringResource?,
tabs: ImmutableList<TabContent>,
modifier: Modifier = Modifier,
startIndex: Int? = null,
state: PagerState = rememberPagerState { tabs.size },
mangaSearchQuery: String? = null,
onChangeMangaSearchQuery: (String?) -> Unit = {},
scrollable: Boolean = false,
animeSearchQuery: String? = null,
onChangeAnimeSearchQuery: (String?) -> Unit = {},
) {
) {
val scope = rememberCoroutineScope()
val state = rememberPagerState { tabs.size }
val snackbarHostState = remember { SnackbarHostState() }
LaunchedEffect(startIndex) {
if (startIndex != null) {
state.scrollToPage(startIndex)
}
}
Scaffold(
topBar = {
if (titleRes != null) {

View file

@ -295,7 +295,7 @@ object SettingsDataScreen : SearchableSettings {
title = stringResource(MR.strings.label_storage),
icon = Icons.Outlined.Storage,
onClick = {
navigator.push(StorageTab())
navigator.push(StorageTab)
},
),

View file

@ -103,7 +103,7 @@ object SettingsLibraryScreen : SearchableSettings {
count = userAnimeCategoriesCount,
userAnimeCategoriesCount,
),
onClick = { navigator.push(CategoriesTab(false)) },
onClick = { navigator.push(CategoriesTab) },
),
Preference.PreferenceItem.ListPreference(
pref = libraryPreferences.defaultAnimeCategory(),
@ -117,7 +117,10 @@ object SettingsLibraryScreen : SearchableSettings {
count = userCategoriesCount,
userCategoriesCount,
),
onClick = { navigator.push(CategoriesTab(true)) },
onClick = {
navigator.push(CategoriesTab)
CategoriesTab.showMangaCategory()
},
),
Preference.PreferenceItem.ListPreference(
pref = libraryPreferences.defaultMangaCategory(),

View file

@ -36,10 +36,8 @@ val LocalBackPress: ProvidableCompositionLocal<(() -> Unit)?> = staticCompositio
private val uiPreferences: UiPreferences = Injekt.get()
abstract class Tab : cafe.adriel.voyager.navigator.tab.Tab {
override val key: ScreenKey = uniqueScreenKey
open suspend fun onReselect(navigator: Navigator) {}
interface Tab : cafe.adriel.voyager.navigator.tab.Tab {
suspend fun onReselect(navigator: Navigator) {}
@Composable
fun currentNavigationStyle(): NavStyle = uiPreferences.navStyle().collectAsState().value

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.browse
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
@ -26,12 +27,14 @@ import eu.kanade.tachiyomi.ui.browse.manga.migration.sources.migrateMangaSourceT
import eu.kanade.tachiyomi.ui.browse.manga.source.mangaSourcesTab
import eu.kanade.tachiyomi.ui.main.MainActivity
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
data class BrowseTab(
private val toExtensions: Boolean = false,
) : Tab() {
data object BrowseTab : Tab {
override val options: TabOptions
@Composable
@ -50,6 +53,12 @@ data class BrowseTab(
navigator.push(GlobalAnimeSearchScreen())
}
private val switchToExtensionTabChannel = Channel<Unit>(1, BufferOverflow.DROP_OLDEST)
fun showExtension() {
switchToExtensionTabChannel.trySend(Unit)
}
@Composable
override fun Content() {
val context = LocalContext.current
@ -61,23 +70,31 @@ data class BrowseTab(
val animeExtensionsScreenModel = rememberScreenModel { AnimeExtensionsScreenModel() }
val animeExtensionsState by animeExtensionsScreenModel.state.collectAsState()
val tabs = persistentListOf(
animeSourcesTab(),
mangaSourcesTab(),
animeExtensionsTab(animeExtensionsScreenModel),
mangaExtensionsTab(mangaExtensionsScreenModel),
migrateAnimeSourceTab(),
migrateMangaSourceTab(),
)
val state = rememberPagerState { tabs.size }
TabbedScreen(
titleRes = MR.strings.browse,
tabs = persistentListOf(
animeSourcesTab(),
mangaSourcesTab(),
animeExtensionsTab(animeExtensionsScreenModel),
mangaExtensionsTab(mangaExtensionsScreenModel),
migrateAnimeSourceTab(),
migrateMangaSourceTab(),
),
startIndex = 2.takeIf { toExtensions },
tabs = tabs,
state = state,
mangaSearchQuery = mangaExtensionsState.searchQuery,
onChangeMangaSearchQuery = mangaExtensionsScreenModel::search,
animeSearchQuery = animeExtensionsState.searchQuery,
onChangeAnimeSearchQuery = animeExtensionsScreenModel::search,
scrollable = true,
)
LaunchedEffect(Unit) {
switchToExtensionTabChannel.receiveAsFlow()
.collectLatest { state.scrollToPage(1) }
}
LaunchedEffect(Unit) {
(context as? MainActivity)?.ready = true

View file

@ -291,7 +291,7 @@ data class BrowseAnimeSourceScreen(
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
onDismissRequest = onDismissRequest,
onEditCategories = { navigator.push(CategoriesTab(false)) },
onEditCategories = { navigator.push(CategoriesTab) },
onConfirm = { include, _ ->
screenModel.changeAnimeFavorite(dialog.anime)
screenModel.moveAnimeToCategories(dialog.anime, include)

View file

@ -291,7 +291,10 @@ data class BrowseMangaSourceScreen(
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
onDismissRequest = onDismissRequest,
onEditCategories = { navigator.push(CategoriesTab(true)) },
onEditCategories = {
navigator.push(CategoriesTab)
CategoriesTab.showMangaCategory()
},
onConfirm = { include, _ ->
screenModel.changeMangaFavorite(dialog.manga)
screenModel.moveMangaToCategories(dialog.manga, include)

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.category
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
@ -21,13 +22,14 @@ import eu.kanade.tachiyomi.ui.category.manga.mangaCategoryTab
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
data class CategoriesTab(
private val isManga: Boolean = false,
) : Tab() {
data object CategoriesTab : Tab {
override val options: TabOptions
@Composable
@ -41,6 +43,12 @@ data class CategoriesTab(
)
}
private val switchToMangaCategoryTabChannel = Channel<Unit>(1, BufferOverflow.DROP_OLDEST)
fun showMangaCategory() {
switchToMangaCategoryTabChannel.trySend(Unit)
}
@Composable
override fun Content() {
val context = LocalContext.current
@ -48,14 +56,22 @@ data class CategoriesTab(
val animeCategoryScreenModel = rememberScreenModel { AnimeCategoryScreenModel() }
val mangaCategoryScreenModel = rememberScreenModel { MangaCategoryScreenModel() }
val tabs = persistentListOf(
animeCategoryTab(),
mangaCategoryTab(),
)
val state = rememberPagerState { tabs.size }
TabbedScreen(
titleRes = MR.strings.general_categories,
tabs = persistentListOf(
animeCategoryTab(),
mangaCategoryTab(),
),
startIndex = 1.takeIf { isManga },
tabs = tabs,
state = state,
)
LaunchedEffect(Unit) {
switchToMangaCategoryTabChannel.receiveAsFlow()
.collectLatest { state.scrollToPage(1) }
}
LaunchedEffect(Unit) {
(context as? MainActivity)?.ready = true

View file

@ -74,9 +74,7 @@ import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.components.material.TabText
import tachiyomi.presentation.core.i18n.stringResource
data class DownloadsTab(
private val isManga: Boolean = false,
) : Tab() {
data object DownloadsTab : Tab {
override val options: TabOptions
@Composable

View file

@ -208,7 +208,7 @@ class AnimeScreen(
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
onDismissRequest = onDismissRequest,
onEditCategories = { navigator.push(CategoriesTab(false)) },
onEditCategories = { navigator.push(CategoriesTab) },
onConfirm = { include, _ ->
screenModel.moveAnimeToCategoriesAndAddToLibrary(dialog.anime, include)
},

View file

@ -189,7 +189,10 @@ class MangaScreen(
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
onDismissRequest = onDismissRequest,
onEditCategories = { navigator.push(CategoriesTab(true)) },
onEditCategories = {
navigator.push(CategoriesTab)
CategoriesTab.showMangaCategory()
},
onConfirm = { include, _ ->
screenModel.moveMangaToCategoriesAndAddToLibrary(dialog.manga, include)
},

View file

@ -26,7 +26,7 @@ import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
object HistoriesTab : Tab() {
data object HistoriesTab : Tab {
override val options: TabOptions
@Composable

View file

@ -173,7 +173,12 @@ object HomeScreen : Screen() {
is Tab.Library -> MangaLibraryTab
is Tab.Updates -> UpdatesTab
is Tab.History -> HistoriesTab
is Tab.Browse -> BrowseTab(it.toExtensions)
is Tab.Browse -> {
if (it.toExtensions) {
BrowseTab.showExtension()
}
BrowseTab
}
is Tab.More -> MoreTab
}
@ -184,7 +189,7 @@ object HomeScreen : Screen() {
navigator.push(MangaScreen(it.mangaIdToOpen))
}
if (it is Tab.More && it.toDownloads) {
navigator.push(DownloadsTab())
navigator.push(DownloadsTab)
}
}
}

View file

@ -65,7 +65,7 @@ import tachiyomi.presentation.core.screens.LoadingScreen
import tachiyomi.source.local.entries.anime.isLocal
import uy.kohesive.injekt.injectLazy
object AnimeLibraryTab : Tab() {
data object AnimeLibraryTab : Tab {
@OptIn(ExperimentalAnimationGraphicsApi::class)
override val options: TabOptions
@ -252,7 +252,7 @@ object AnimeLibraryTab : Tab() {
onDismissRequest = onDismissRequest,
onEditCategories = {
screenModel.clearSelection()
navigator.push(CategoriesTab(false))
navigator.push(CategoriesTab)
},
onConfirm = { include, exclude ->
screenModel.clearSelection()

View file

@ -64,7 +64,7 @@ import tachiyomi.presentation.core.screens.EmptyScreenAction
import tachiyomi.presentation.core.screens.LoadingScreen
import tachiyomi.source.local.entries.manga.isLocal
object MangaLibraryTab : Tab() {
data object MangaLibraryTab : Tab {
@OptIn(ExperimentalAnimationGraphicsApi::class)
override val options: TabOptions
@ -272,7 +272,8 @@ object MangaLibraryTab : Tab() {
onDismissRequest = onDismissRequest,
onEditCategories = {
screenModel.clearSelection()
navigator.push(CategoriesTab(true))
navigator.push(CategoriesTab)
CategoriesTab.showMangaCategory()
},
onConfirm = { include, exclude ->
screenModel.clearSelection()

View file

@ -40,7 +40,7 @@ import tachiyomi.presentation.core.i18n.stringResource
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
object MoreTab : Tab() {
data object MoreTab : Tab {
override val options: TabOptions
@Composable
@ -74,10 +74,10 @@ object MoreTab : Tab() {
isFDroid = context.isInstalledFromFDroid(),
navStyle = navStyle,
onClickAlt = { navigator.push(navStyle.moreTab) },
onClickDownloadQueue = { navigator.push(DownloadsTab()) },
onClickCategories = { navigator.push(CategoriesTab()) },
onClickStats = { navigator.push(StatsTab()) },
onClickStorage = { navigator.push(StorageTab()) },
onClickDownloadQueue = { navigator.push(DownloadsTab) },
onClickCategories = { navigator.push(CategoriesTab) },
onClickStats = { navigator.push(StatsTab) },
onClickStorage = { navigator.push(StorageTab) },
onClickDataAndStorage = { navigator.push(SettingsScreen(SettingsScreen.Destination.DataAndStorage)) },
onClickSettings = { navigator.push(SettingsScreen()) },
onClickAbout = { navigator.push(SettingsScreen(SettingsScreen.Destination.About)) },

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.stats
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
@ -18,9 +19,7 @@ import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
data class StatsTab(
private val isManga: Boolean = false,
) : Tab() {
data object StatsTab : Tab {
override val options: TabOptions
@Composable
@ -38,14 +37,16 @@ data class StatsTab(
override fun Content() {
val context = LocalContext.current
val tabs = persistentListOf(
animeStatsTab(),
mangaStatsTab(),
)
val state = rememberPagerState { tabs.size }
TabbedScreen(
titleRes = MR.strings.label_stats,
tabs = persistentListOf(
animeStatsTab(),
mangaStatsTab(),
),
startIndex = 1.takeIf { isManga },
tabs = tabs,
state = state,
)
LaunchedEffect(Unit) {

View file

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.storage
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
@ -18,9 +19,7 @@ import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
data class StorageTab(
private val isManga: Boolean = false,
) : Tab() {
data object StorageTab : Tab {
override val options: TabOptions
@Composable
@ -38,13 +37,16 @@ data class StorageTab(
override fun Content() {
val context = LocalContext.current
val tabs = persistentListOf(
animeStorageTab(),
mangaStorageTab(),
)
val state = rememberPagerState { tabs.size }
TabbedScreen(
titleRes = MR.strings.label_storage,
tabs = persistentListOf(
animeStorageTab(),
mangaStorageTab(),
),
startIndex = 1.takeIf { isManga },
tabs = tabs,
state = state,
)
LaunchedEffect(Unit) {

View file

@ -21,7 +21,7 @@ import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
object UpdatesTab : Tab() {
data object UpdatesTab : Tab {
override val options: TabOptions
@Composable
@ -41,7 +41,7 @@ object UpdatesTab : Tab() {
)
}
override suspend fun onReselect(navigator: Navigator) {
navigator.push(DownloadsTab())
navigator.push(DownloadsTab)
}
@Composable