mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 03:18:25 +01:00
parent
38d5fc9160
commit
371c1432e2
@ -11,6 +11,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
- `Other` - for technical stuff.
|
- `Other` - for technical stuff.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fixed
|
||||||
|
- Fixed "currentTab was used multiple times"
|
||||||
|
|
||||||
## [v0.17.0] - 2024-10-26
|
## [v0.17.0] - 2024-10-26
|
||||||
### Added
|
### Added
|
||||||
|
@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.calculateStartPadding
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.PagerState
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.PrimaryTabRow
|
import androidx.compose.material3.PrimaryTabRow
|
||||||
@ -14,7 +15,6 @@ import androidx.compose.material3.SnackbarHost
|
|||||||
import androidx.compose.material3.SnackbarHostState
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.material3.Tab
|
import androidx.compose.material3.Tab
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -33,20 +33,13 @@ import tachiyomi.presentation.core.i18n.stringResource
|
|||||||
fun TabbedScreen(
|
fun TabbedScreen(
|
||||||
titleRes: StringResource,
|
titleRes: StringResource,
|
||||||
tabs: ImmutableList<TabContent>,
|
tabs: ImmutableList<TabContent>,
|
||||||
startIndex: Int? = null,
|
state: PagerState = rememberPagerState { tabs.size },
|
||||||
searchQuery: String? = null,
|
searchQuery: String? = null,
|
||||||
onChangeSearchQuery: (String?) -> Unit = {},
|
onChangeSearchQuery: (String?) -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val state = rememberPagerState { tabs.size }
|
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
|
|
||||||
LaunchedEffect(startIndex) {
|
|
||||||
if (startIndex != null) {
|
|
||||||
state.scrollToPage(startIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
val tab = tabs[state.currentPage]
|
val tab = tabs[state.currentPage]
|
||||||
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.browse
|
|||||||
import androidx.compose.animation.graphics.res.animatedVectorResource
|
import androidx.compose.animation.graphics.res.animatedVectorResource
|
||||||
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
|
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
|
||||||
import androidx.compose.animation.graphics.vector.AnimatedImageVector
|
import androidx.compose.animation.graphics.vector.AnimatedImageVector
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
@ -22,12 +23,14 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchScreen
|
|||||||
import eu.kanade.tachiyomi.ui.browse.source.sourcesTab
|
import eu.kanade.tachiyomi.ui.browse.source.sourcesTab
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
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.i18n.MR
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
|
|
||||||
data class BrowseTab(
|
data object BrowseTab : Tab {
|
||||||
private val toExtensions: Boolean = false,
|
|
||||||
) : Tab {
|
|
||||||
|
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
@ -45,6 +48,12 @@ data class BrowseTab(
|
|||||||
navigator.push(GlobalSearchScreen())
|
navigator.push(GlobalSearchScreen())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val switchToExtensionTabChannel = Channel<Unit>(1, BufferOverflow.DROP_OLDEST)
|
||||||
|
|
||||||
|
fun showExtension() {
|
||||||
|
switchToExtensionTabChannel.trySend(Unit)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@ -53,17 +62,25 @@ data class BrowseTab(
|
|||||||
val extensionsScreenModel = rememberScreenModel { ExtensionsScreenModel() }
|
val extensionsScreenModel = rememberScreenModel { ExtensionsScreenModel() }
|
||||||
val extensionsState by extensionsScreenModel.state.collectAsState()
|
val extensionsState by extensionsScreenModel.state.collectAsState()
|
||||||
|
|
||||||
|
val tabs = persistentListOf(
|
||||||
|
sourcesTab(),
|
||||||
|
extensionsTab(extensionsScreenModel),
|
||||||
|
migrateSourceTab(),
|
||||||
|
)
|
||||||
|
|
||||||
|
val state = rememberPagerState { tabs.size }
|
||||||
|
|
||||||
TabbedScreen(
|
TabbedScreen(
|
||||||
titleRes = MR.strings.browse,
|
titleRes = MR.strings.browse,
|
||||||
tabs = persistentListOf(
|
tabs = tabs,
|
||||||
sourcesTab(),
|
state = state,
|
||||||
extensionsTab(extensionsScreenModel),
|
|
||||||
migrateSourceTab(),
|
|
||||||
),
|
|
||||||
startIndex = 1.takeIf { toExtensions },
|
|
||||||
searchQuery = extensionsState.searchQuery,
|
searchQuery = extensionsState.searchQuery,
|
||||||
onChangeSearchQuery = extensionsScreenModel::search,
|
onChangeSearchQuery = extensionsScreenModel::search,
|
||||||
)
|
)
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
switchToExtensionTabChannel.receiveAsFlow()
|
||||||
|
.collectLatest { state.scrollToPage(1) }
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
(context as? MainActivity)?.ready = true
|
(context as? MainActivity)?.ready = true
|
||||||
|
@ -32,7 +32,7 @@ import tachiyomi.domain.chapter.model.Chapter
|
|||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
|
|
||||||
object HistoryTab : Tab {
|
data object HistoryTab : Tab {
|
||||||
|
|
||||||
private val snackbarHostState = SnackbarHostState()
|
private val snackbarHostState = SnackbarHostState()
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ object HomeScreen : Screen() {
|
|||||||
private const val TAB_FADE_DURATION = 200
|
private const val TAB_FADE_DURATION = 200
|
||||||
private const val TAB_NAVIGATOR_KEY = "HomeTabs"
|
private const val TAB_NAVIGATOR_KEY = "HomeTabs"
|
||||||
|
|
||||||
private val tabs = listOf(
|
private val TABS = listOf(
|
||||||
LibraryTab,
|
LibraryTab,
|
||||||
UpdatesTab,
|
UpdatesTab,
|
||||||
HistoryTab,
|
HistoryTab,
|
||||||
BrowseTab(),
|
BrowseTab,
|
||||||
MoreTab,
|
MoreTab,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ object HomeScreen : Screen() {
|
|||||||
startBar = {
|
startBar = {
|
||||||
if (isTabletUi()) {
|
if (isTabletUi()) {
|
||||||
NavigationRail {
|
NavigationRail {
|
||||||
tabs.fastForEach {
|
TABS.fastForEach {
|
||||||
NavigationRailItem(it)
|
NavigationRailItem(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ object HomeScreen : Screen() {
|
|||||||
exit = shrinkVertically(),
|
exit = shrinkVertically(),
|
||||||
) {
|
) {
|
||||||
NavigationBar {
|
NavigationBar {
|
||||||
tabs.fastForEach {
|
TABS.fastForEach {
|
||||||
NavigationBarItem(it)
|
NavigationBarItem(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +159,12 @@ object HomeScreen : Screen() {
|
|||||||
is Tab.Library -> LibraryTab
|
is Tab.Library -> LibraryTab
|
||||||
Tab.Updates -> UpdatesTab
|
Tab.Updates -> UpdatesTab
|
||||||
Tab.History -> HistoryTab
|
Tab.History -> HistoryTab
|
||||||
is Tab.Browse -> BrowseTab(it.toExtensions)
|
is Tab.Browse -> {
|
||||||
|
if (it.toExtensions) {
|
||||||
|
BrowseTab.showExtension()
|
||||||
|
}
|
||||||
|
BrowseTab
|
||||||
|
}
|
||||||
is Tab.More -> MoreTab
|
is Tab.More -> MoreTab
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ import tachiyomi.presentation.core.screens.EmptyScreenAction
|
|||||||
import tachiyomi.presentation.core.screens.LoadingScreen
|
import tachiyomi.presentation.core.screens.LoadingScreen
|
||||||
import tachiyomi.source.local.isLocal
|
import tachiyomi.source.local.isLocal
|
||||||
|
|
||||||
object LibraryTab : Tab {
|
data object LibraryTab : Tab {
|
||||||
|
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -38,7 +38,7 @@ import tachiyomi.presentation.core.i18n.stringResource
|
|||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
object MoreTab : Tab {
|
data object MoreTab : Tab {
|
||||||
|
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -31,7 +31,7 @@ import tachiyomi.core.common.i18n.stringResource
|
|||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
|
|
||||||
object UpdatesTab : Tab {
|
data object UpdatesTab : Tab {
|
||||||
|
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
Reference in New Issue
Block a user