This commit is contained in:
jmir1 2022-11-08 09:06:12 +01:00
parent 62b9a10c34
commit 8f097c225b
8 changed files with 56 additions and 27 deletions

View file

@ -35,7 +35,6 @@ import eu.kanade.tachiyomi.data.animedownload.model.AnimeDownload
import eu.kanade.tachiyomi.data.animelib.AnimelibUpdateService
import eu.kanade.tachiyomi.ui.player.PlayerActivity
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.AnimeUpdatesPresenter
import eu.kanade.tachiyomi.ui.recent.animeupdates.AnimeUpdatesPresenter.Dialog
@ -65,8 +64,6 @@ fun AnimeUpdateScreen(
}
BackHandler(onBack = internalOnBackPressed)
isCurrentUpdateTabManga = false
val context = LocalContext.current
val onUpdateLibrary = {
val started = AnimelibUpdateService.start(context)

View file

@ -7,7 +7,9 @@ import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.TabPosition
import androidx.compose.material3.TabRow
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -16,12 +18,13 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView
import kotlinx.coroutines.launch
@Composable
fun TabbedScreen(
@StringRes titleRes: Int,
@StringRes titleRes: Int?,
tabs: List<TabContent>,
startIndex: Int? = null,
searchQuery: String? = null,
@ -29,9 +32,10 @@ fun TabbedScreen(
onChangeSearchQuery: (String?) -> Unit = {},
incognitoMode: Boolean,
downloadedOnlyMode: Boolean,
state: PagerState = rememberPagerState(),
scrollable: Boolean = false,
) {
val scope = rememberCoroutineScope()
val state = rememberPagerState()
LaunchedEffect(startIndex) {
if (startIndex != null) {
@ -42,12 +46,14 @@ fun TabbedScreen(
Scaffold(
topBar = {
if (searchQuery == null) {
if (titleRes != null) {
AppBar(
title = stringResource(titleRes),
actions = {
AppBarActions(tabs[state.currentPage].actions)
},
)
}
} else {
SearchToolbar(
searchQuery = searchQuery,
@ -72,7 +78,8 @@ fun TabbedScreen(
end = contentPadding.calculateEndPadding(LocalLayoutDirection.current),
),
) {
TabRow(
FlexibleTabRow(
scrollable = scrollable,
selectedTabIndex = state.currentPage,
indicator = { TabIndicator(it[state.currentPage]) },
) {
@ -111,3 +118,28 @@ data class TabContent(
val actions: List<AppBar.Action> = emptyList(),
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()
}
}
}

View file

@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
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.UpdatesPresenter
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Dialog
@ -61,8 +60,6 @@ fun UpdateScreen(
}
BackHandler(onBack = internalOnBackPressed)
isCurrentUpdateTabManga = true
val context = LocalContext.current
val onUpdateLibrary = {
val started = LibraryUpdateService.start(context)

View file

@ -54,6 +54,7 @@ class BrowseController : FullComposeController<BrowsePresenter>, RootController
placeholderRes = R.string.action_search_hint,
incognitoMode = presenter.isIncognitoMode,
downloadedOnlyMode = presenter.isDownloadOnly,
scrollable = true,
)
LaunchedEffect(Unit) {

View file

@ -124,7 +124,7 @@ class AnimeDownloadController :
titleContent = {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.label_download_queue),
text = stringResource(R.string.label_anime_download_queue),
maxLines = 1,
modifier = Modifier.weight(1f, false),
overflow = TextOverflow.Ellipsis,

View file

@ -5,7 +5,6 @@ import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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.RootController
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
@ -20,7 +19,7 @@ class HistoryTabsController : FullComposeController<HistoryTabsPresenter>(), Roo
@Composable
override fun ComposeContent() {
TabbedScreen(
titleRes = R.string.browse,
titleRes = null,
tabs = listOf(
animeHistoryTab(router, presenter.animeHistoryPresenter),
historyTab(router, presenter.historyPresenter),

View file

@ -4,8 +4,8 @@ import android.Manifest
import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import eu.kanade.presentation.components.PagerState
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.RootController
import eu.kanade.tachiyomi.ui.base.controller.pushController
@ -20,16 +20,19 @@ class UpdatesTabsController : FullComposeController<UpdatesTabsPresenter>(), Roo
override fun createPresenter() = UpdatesTabsPresenter()
private val state = PagerState(currentPage = TAB_ANIME)
@Composable
override fun ComposeContent() {
TabbedScreen(
titleRes = R.string.browse,
titleRes = null,
tabs = listOf(
animeUpdatesTab(router, presenter.animeUpdatesPresenter, activity),
updatesTab(router, presenter.updatesPresenter, activity),
),
incognitoMode = presenter.isIncognitoMode,
downloadedOnlyMode = presenter.isDownloadOnly,
state = state,
)
LaunchedEffect(Unit) {
@ -43,14 +46,13 @@ class UpdatesTabsController : FullComposeController<UpdatesTabsPresenter>(), Roo
}
fun openDownloadQueue() {
if (isCurrentUpdateTabManga) {
if (state.currentPage == TAB_MANGA) {
router.pushController(DownloadController())
} else {
router.pushController(AnimeDownloadController())
}
}
}
companion object {
var isCurrentUpdateTabManga = true
}
}
private const val TAB_ANIME = 0
private const val TAB_MANGA = 1

View file

@ -187,12 +187,13 @@ class AnimeUpdatesPresenter(
fun downloadEpisodes(items: List<AnimeUpdatesItem>, action: EpisodeDownloadAction) {
if (items.isEmpty()) return
val context = context ?: return
presenterScope.launch {
when (action) {
EpisodeDownloadAction.START -> {
downloadEpisodes(items)
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
AnimeDownloadService.start(context!!)
AnimeDownloadService.start(context)
}
}
EpisodeDownloadAction.START_NOW -> {
@ -209,7 +210,7 @@ class AnimeUpdatesPresenter(
EpisodeDownloadAction.START_ALT -> {
downloadEpisodesAlternatively(items)
if (items.any { it.downloadStateProvider() == AnimeDownload.State.ERROR }) {
AnimeDownloadService.start(context!!)
AnimeDownloadService.start(context)
}
}
}