mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 01:29:02 +03:00
fix tabs
This commit is contained in:
parent
62b9a10c34
commit
8f097c225b
8 changed files with 56 additions and 27 deletions
|
@ -35,7 +35,6 @@ import eu.kanade.tachiyomi.data.animedownload.model.AnimeDownload
|
||||||
import eu.kanade.tachiyomi.data.animelib.AnimelibUpdateService
|
import eu.kanade.tachiyomi.data.animelib.AnimelibUpdateService
|
||||||
import eu.kanade.tachiyomi.ui.player.PlayerActivity
|
import eu.kanade.tachiyomi.ui.player.PlayerActivity
|
||||||
import eu.kanade.tachiyomi.ui.player.setting.PlayerPreferences
|
import eu.kanade.tachiyomi.ui.player.setting.PlayerPreferences
|
||||||
import eu.kanade.tachiyomi.ui.recent.UpdatesTabsController.Companion.isCurrentUpdateTabManga
|
|
||||||
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesItem
|
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesItem
|
||||||
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesPresenter
|
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesPresenter
|
||||||
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesPresenter.Dialog
|
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesPresenter.Dialog
|
||||||
|
@ -65,8 +64,6 @@ fun AnimeUpdateScreen(
|
||||||
}
|
}
|
||||||
BackHandler(onBack = internalOnBackPressed)
|
BackHandler(onBack = internalOnBackPressed)
|
||||||
|
|
||||||
isCurrentUpdateTabManga = false
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val onUpdateLibrary = {
|
val onUpdateLibrary = {
|
||||||
val started = AnimelibUpdateService.start(context)
|
val started = AnimelibUpdateService.start(context)
|
||||||
|
|
|
@ -7,7 +7,9 @@ import androidx.compose.foundation.layout.calculateEndPadding
|
||||||
import androidx.compose.foundation.layout.calculateStartPadding
|
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.material3.ScrollableTabRow
|
||||||
import androidx.compose.material3.Tab
|
import androidx.compose.material3.Tab
|
||||||
|
import androidx.compose.material3.TabPosition
|
||||||
import androidx.compose.material3.TabRow
|
import androidx.compose.material3.TabRow
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
@ -16,12 +18,13 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView
|
import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TabbedScreen(
|
fun TabbedScreen(
|
||||||
@StringRes titleRes: Int,
|
@StringRes titleRes: Int?,
|
||||||
tabs: List<TabContent>,
|
tabs: List<TabContent>,
|
||||||
startIndex: Int? = null,
|
startIndex: Int? = null,
|
||||||
searchQuery: String? = null,
|
searchQuery: String? = null,
|
||||||
|
@ -29,9 +32,10 @@ fun TabbedScreen(
|
||||||
onChangeSearchQuery: (String?) -> Unit = {},
|
onChangeSearchQuery: (String?) -> Unit = {},
|
||||||
incognitoMode: Boolean,
|
incognitoMode: Boolean,
|
||||||
downloadedOnlyMode: Boolean,
|
downloadedOnlyMode: Boolean,
|
||||||
|
state: PagerState = rememberPagerState(),
|
||||||
|
scrollable: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val state = rememberPagerState()
|
|
||||||
|
|
||||||
LaunchedEffect(startIndex) {
|
LaunchedEffect(startIndex) {
|
||||||
if (startIndex != null) {
|
if (startIndex != null) {
|
||||||
|
@ -42,12 +46,14 @@ fun TabbedScreen(
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
if (searchQuery == null) {
|
if (searchQuery == null) {
|
||||||
AppBar(
|
if (titleRes != null) {
|
||||||
title = stringResource(titleRes),
|
AppBar(
|
||||||
actions = {
|
title = stringResource(titleRes),
|
||||||
AppBarActions(tabs[state.currentPage].actions)
|
actions = {
|
||||||
},
|
AppBarActions(tabs[state.currentPage].actions)
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SearchToolbar(
|
SearchToolbar(
|
||||||
searchQuery = searchQuery,
|
searchQuery = searchQuery,
|
||||||
|
@ -72,7 +78,8 @@ fun TabbedScreen(
|
||||||
end = contentPadding.calculateEndPadding(LocalLayoutDirection.current),
|
end = contentPadding.calculateEndPadding(LocalLayoutDirection.current),
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
TabRow(
|
FlexibleTabRow(
|
||||||
|
scrollable = scrollable,
|
||||||
selectedTabIndex = state.currentPage,
|
selectedTabIndex = state.currentPage,
|
||||||
indicator = { TabIndicator(it[state.currentPage]) },
|
indicator = { TabIndicator(it[state.currentPage]) },
|
||||||
) {
|
) {
|
||||||
|
@ -111,3 +118,28 @@ data class TabContent(
|
||||||
val actions: List<AppBar.Action> = emptyList(),
|
val actions: List<AppBar.Action> = emptyList(),
|
||||||
val content: @Composable (contentPadding: PaddingValues) -> Unit,
|
val content: @Composable (contentPadding: PaddingValues) -> Unit,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun FlexibleTabRow(
|
||||||
|
scrollable: Boolean,
|
||||||
|
selectedTabIndex: Int,
|
||||||
|
indicator: @Composable (List<TabPosition>) -> Unit,
|
||||||
|
block: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
return if (scrollable) {
|
||||||
|
ScrollableTabRow(
|
||||||
|
selectedTabIndex = selectedTabIndex,
|
||||||
|
indicator = indicator,
|
||||||
|
edgePadding = 13.dp,
|
||||||
|
) {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TabRow(
|
||||||
|
selectedTabIndex = selectedTabIndex,
|
||||||
|
indicator = indicator,
|
||||||
|
) {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.ui.recent.UpdatesTabsController.Companion.isCurrentUpdateTabManga
|
|
||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem
|
||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter
|
||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Dialog
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Dialog
|
||||||
|
@ -61,8 +60,6 @@ fun UpdateScreen(
|
||||||
}
|
}
|
||||||
BackHandler(onBack = internalOnBackPressed)
|
BackHandler(onBack = internalOnBackPressed)
|
||||||
|
|
||||||
isCurrentUpdateTabManga = true
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val onUpdateLibrary = {
|
val onUpdateLibrary = {
|
||||||
val started = LibraryUpdateService.start(context)
|
val started = LibraryUpdateService.start(context)
|
||||||
|
|
|
@ -54,6 +54,7 @@ class BrowseController : FullComposeController<BrowsePresenter>, RootController
|
||||||
placeholderRes = R.string.action_search_hint,
|
placeholderRes = R.string.action_search_hint,
|
||||||
incognitoMode = presenter.isIncognitoMode,
|
incognitoMode = presenter.isIncognitoMode,
|
||||||
downloadedOnlyMode = presenter.isDownloadOnly,
|
downloadedOnlyMode = presenter.isDownloadOnly,
|
||||||
|
scrollable = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
|
|
@ -124,7 +124,7 @@ class AnimeDownloadController :
|
||||||
titleContent = {
|
titleContent = {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.label_download_queue),
|
text = stringResource(R.string.label_anime_download_queue),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
modifier = Modifier.weight(1f, false),
|
modifier = Modifier.weight(1f, false),
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.View
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import eu.kanade.presentation.components.TabbedScreen
|
import eu.kanade.presentation.components.TabbedScreen
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
|
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
|
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
|
||||||
|
@ -20,7 +19,7 @@ class HistoryTabsController : FullComposeController<HistoryTabsPresenter>(), Roo
|
||||||
@Composable
|
@Composable
|
||||||
override fun ComposeContent() {
|
override fun ComposeContent() {
|
||||||
TabbedScreen(
|
TabbedScreen(
|
||||||
titleRes = R.string.browse,
|
titleRes = null,
|
||||||
tabs = listOf(
|
tabs = listOf(
|
||||||
animeHistoryTab(router, presenter.animeHistoryPresenter),
|
animeHistoryTab(router, presenter.animeHistoryPresenter),
|
||||||
historyTab(router, presenter.historyPresenter),
|
historyTab(router, presenter.historyPresenter),
|
||||||
|
|
|
@ -4,8 +4,8 @@ import android.Manifest
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import eu.kanade.presentation.components.PagerState
|
||||||
import eu.kanade.presentation.components.TabbedScreen
|
import eu.kanade.presentation.components.TabbedScreen
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
|
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.pushController
|
import eu.kanade.tachiyomi.ui.base.controller.pushController
|
||||||
|
@ -20,16 +20,19 @@ class UpdatesTabsController : FullComposeController<UpdatesTabsPresenter>(), Roo
|
||||||
|
|
||||||
override fun createPresenter() = UpdatesTabsPresenter()
|
override fun createPresenter() = UpdatesTabsPresenter()
|
||||||
|
|
||||||
|
private val state = PagerState(currentPage = TAB_ANIME)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun ComposeContent() {
|
override fun ComposeContent() {
|
||||||
TabbedScreen(
|
TabbedScreen(
|
||||||
titleRes = R.string.browse,
|
titleRes = null,
|
||||||
tabs = listOf(
|
tabs = listOf(
|
||||||
animeUpdatesTab(router, presenter.animeUpdatesPresenter, activity),
|
animeUpdatesTab(router, presenter.animeUpdatesPresenter, activity),
|
||||||
updatesTab(router, presenter.updatesPresenter, activity),
|
updatesTab(router, presenter.updatesPresenter, activity),
|
||||||
),
|
),
|
||||||
incognitoMode = presenter.isIncognitoMode,
|
incognitoMode = presenter.isIncognitoMode,
|
||||||
downloadedOnlyMode = presenter.isDownloadOnly,
|
downloadedOnlyMode = presenter.isDownloadOnly,
|
||||||
|
state = state,
|
||||||
)
|
)
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
@ -43,14 +46,13 @@ class UpdatesTabsController : FullComposeController<UpdatesTabsPresenter>(), Roo
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openDownloadQueue() {
|
fun openDownloadQueue() {
|
||||||
if (isCurrentUpdateTabManga) {
|
if (state.currentPage == TAB_MANGA) {
|
||||||
router.pushController(DownloadController())
|
router.pushController(DownloadController())
|
||||||
} else {
|
} else {
|
||||||
router.pushController(AnimeDownloadController())
|
router.pushController(AnimeDownloadController())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
var isCurrentUpdateTabManga = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val TAB_ANIME = 0
|
||||||
|
private const val TAB_MANGA = 1
|
||||||
|
|
|
@ -187,12 +187,13 @@ class AnimeUpdatesPresenter(
|
||||||
|
|
||||||
fun downloadEpisodes(items: List<AnimeUpdatesItem>, action: EpisodeDownloadAction) {
|
fun downloadEpisodes(items: List<AnimeUpdatesItem>, action: EpisodeDownloadAction) {
|
||||||
if (items.isEmpty()) return
|
if (items.isEmpty()) return
|
||||||
|
val context = context ?: return
|
||||||
presenterScope.launch {
|
presenterScope.launch {
|
||||||
when (action) {
|
when (action) {
|
||||||
EpisodeDownloadAction.START -> {
|
EpisodeDownloadAction.START -> {
|
||||||
downloadEpisodes(items)
|
downloadEpisodes(items)
|
||||||
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
|
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
|
||||||
AnimeDownloadService.start(context!!)
|
AnimeDownloadService.start(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EpisodeDownloadAction.START_NOW -> {
|
EpisodeDownloadAction.START_NOW -> {
|
||||||
|
@ -209,7 +210,7 @@ class AnimeUpdatesPresenter(
|
||||||
EpisodeDownloadAction.START_ALT -> {
|
EpisodeDownloadAction.START_ALT -> {
|
||||||
downloadEpisodesAlternatively(items)
|
downloadEpisodesAlternatively(items)
|
||||||
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
|
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
|
||||||
AnimeDownloadService.start(context!!)
|
AnimeDownloadService.start(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue