diff --git a/app/src/main/java/eu/kanade/presentation/animeupdates/AnimeUpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/animeupdates/AnimeUpdatesScreen.kt index 071e5c4f1..0b1926532 100644 --- a/app/src/main/java/eu/kanade/presentation/animeupdates/AnimeUpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/animeupdates/AnimeUpdatesScreen.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt index e7354d11e..15e8baf88 100644 --- a/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt @@ -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, 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) { - AppBar( - title = stringResource(titleRes), - actions = { - AppBarActions(tabs[state.currentPage].actions) - }, - ) + 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 = emptyList(), val content: @Composable (contentPadding: PaddingValues) -> Unit, ) + +@Composable +private fun FlexibleTabRow( + scrollable: Boolean, + selectedTabIndex: Int, + indicator: @Composable (List) -> Unit, + block: @Composable () -> Unit, +) { + return if (scrollable) { + ScrollableTabRow( + selectedTabIndex = selectedTabIndex, + indicator = indicator, + edgePadding = 13.dp, + ) { + block() + } + } else { + TabRow( + selectedTabIndex = selectedTabIndex, + indicator = indicator, + ) { + block() + } + } +} diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt index 4b2c3dcd5..dc54ff111 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index fe1fb735c..e201fe350 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -54,6 +54,7 @@ class BrowseController : FullComposeController, RootController placeholderRes = R.string.action_search_hint, incognitoMode = presenter.isIncognitoMode, downloadedOnlyMode = presenter.isDownloadOnly, + scrollable = true, ) LaunchedEffect(Unit) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/AnimeDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/AnimeDownloadController.kt index 6eaefbc09..24d5661bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/AnimeDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/AnimeDownloadController.kt @@ -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, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/HistoryTabsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/HistoryTabsController.kt index 13de80333..93d23e4bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/HistoryTabsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/HistoryTabsController.kt @@ -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(), Roo @Composable override fun ComposeContent() { TabbedScreen( - titleRes = R.string.browse, + titleRes = null, tabs = listOf( animeHistoryTab(router, presenter.animeHistoryPresenter), historyTab(router, presenter.historyPresenter), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/UpdatesTabsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/UpdatesTabsController.kt index a9a76987c..b279b712a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/UpdatesTabsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/UpdatesTabsController.kt @@ -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(), 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(), 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/animeupdates/AnimeUpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/animeupdates/AnimeUpdatesPresenter.kt index 2982c3c67..025d96c6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/animeupdates/AnimeUpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/animeupdates/AnimeUpdatesPresenter.kt @@ -187,12 +187,13 @@ class AnimeUpdatesPresenter( fun downloadEpisodes(items: List, 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) } } }