Add ability to open random manga (#8232)
* Add ability to open random manga * Use `getMangaForCategory` instead * Put it in overflow menu instead of using EFAB * Partial review changes * Merge remote-tracking branch 'refs/remotes/origin/patch-6' into patch-6 # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt * Merge remote-tracking branch 'refs/remotes/origin/patch-6' into patch-6 # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt * Wording changes (cherry picked from commit f5451a68812f56d9427a9b771f6bed00f8fbd7e6) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt # app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt
This commit is contained in:
parent
6c377f23e9
commit
621e9dbc41
@ -36,6 +36,7 @@ fun LibraryScreen(
|
||||
onClickInvertSelection: () -> Unit,
|
||||
onClickFilter: () -> Unit,
|
||||
onClickRefresh: (Category?) -> Boolean,
|
||||
onClickOpenRandomManga: () -> Unit,
|
||||
// SY -->
|
||||
onClickCleanTitles: () -> Unit,
|
||||
onClickMigrate: () -> Unit,
|
||||
@ -58,6 +59,7 @@ fun LibraryScreen(
|
||||
onClickInvertSelection = onClickInvertSelection,
|
||||
onClickFilter = onClickFilter,
|
||||
onClickRefresh = { onClickRefresh(null) },
|
||||
onClickOpenRandomManga = onClickOpenRandomManga,
|
||||
// SY -->
|
||||
onClickSyncExh = onClickSyncExh,
|
||||
// SY <--
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.presentation.library.components
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
@ -8,7 +9,6 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.FilterList
|
||||
import androidx.compose.material.icons.outlined.FlipToBack
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Refresh
|
||||
import androidx.compose.material.icons.outlined.Search
|
||||
import androidx.compose.material.icons.outlined.SelectAll
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
@ -25,7 +25,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@ -39,7 +38,6 @@ import eu.kanade.presentation.components.SearchToolbar
|
||||
import eu.kanade.presentation.library.LibraryState
|
||||
import eu.kanade.presentation.theme.active
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
|
||||
@Composable
|
||||
fun LibraryToolbar(
|
||||
@ -52,6 +50,7 @@ fun LibraryToolbar(
|
||||
onClickInvertSelection: () -> Unit,
|
||||
onClickFilter: () -> Unit,
|
||||
onClickRefresh: () -> Unit,
|
||||
onClickOpenRandomManga: () -> Unit,
|
||||
// SY -->
|
||||
onClickSyncExh: () -> Unit,
|
||||
// SY <--
|
||||
@ -97,9 +96,9 @@ fun LibraryToolbar(
|
||||
onClickSearch = { state.searchQuery = "" },
|
||||
onClickFilter = onClickFilter,
|
||||
onClickRefresh = onClickRefresh,
|
||||
onClickOpenRandomManga = onClickOpenRandomManga,
|
||||
// SY -->
|
||||
showSyncExh = state.showSyncExh,
|
||||
onClickSyncExh = onClickSyncExh,
|
||||
onClickSyncExh = onClickSyncExh.takeIf { state.showSyncExh },
|
||||
// SY <--
|
||||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
@ -114,9 +113,9 @@ fun LibraryRegularToolbar(
|
||||
onClickSearch: () -> Unit,
|
||||
onClickFilter: () -> Unit,
|
||||
onClickRefresh: () -> Unit,
|
||||
onClickOpenRandomManga: () -> Unit,
|
||||
// SY -->
|
||||
showSyncExh: Boolean,
|
||||
onClickSyncExh: () -> Unit,
|
||||
onClickSyncExh: (() -> Unit)?,
|
||||
// SY <--
|
||||
scrollBehavior: TopAppBarScrollBehavior?,
|
||||
) {
|
||||
@ -147,33 +146,46 @@ fun LibraryRegularToolbar(
|
||||
IconButton(onClick = onClickFilter) {
|
||||
Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint)
|
||||
}
|
||||
// SY -->
|
||||
val configuration = LocalConfiguration.current
|
||||
val moveGlobalUpdate = showSyncExh && remember { !configuration.isTabletUi() }
|
||||
if (!moveGlobalUpdate) {
|
||||
IconButton(onClick = onClickRefresh) {
|
||||
Icon(Icons.Outlined.Refresh, contentDescription = stringResource(R.string.pref_category_library_update))
|
||||
}
|
||||
}
|
||||
var showOverflow by remember { mutableStateOf(false) }
|
||||
if (showSyncExh) {
|
||||
IconButton(onClick = { showOverflow = true }) {
|
||||
Icon(Icons.Outlined.MoreVert, contentDescription = "more")
|
||||
}
|
||||
}
|
||||
DropdownMenu(showOverflow, onDismissRequest = { showOverflow = false }) {
|
||||
if (moveGlobalUpdate) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.pref_category_library_update)) },
|
||||
onClick = onClickRefresh,
|
||||
var moreExpanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
IconButton(onClick = { moreExpanded = !moreExpanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.abc_action_menu_overflow_description),
|
||||
)
|
||||
}
|
||||
val onDismissRequest = { moreExpanded = false }
|
||||
DropdownMenu(
|
||||
expanded = moreExpanded,
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.sync_favorites)) },
|
||||
onClick = onClickSyncExh,
|
||||
text = { Text(text = stringResource(R.string.pref_category_library_update)) },
|
||||
onClick = {
|
||||
onClickRefresh()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_open_random_manga)) },
|
||||
onClick = {
|
||||
onClickOpenRandomManga()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
// SY -->
|
||||
if (onClickSyncExh != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.sync_favorites)) },
|
||||
onClick = {
|
||||
onClickSyncExh()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
}
|
||||
},
|
||||
incognitoMode = incognitoMode,
|
||||
downloadedOnlyMode = downloadedOnlyMode,
|
||||
|
@ -76,6 +76,8 @@ class LibraryController(
|
||||
@Composable
|
||||
override fun ComposeContent() {
|
||||
val context = LocalContext.current
|
||||
val getMangaForCategory = presenter.getMangaForCategory(page = presenter.activeCategory)
|
||||
|
||||
LibraryScreen(
|
||||
presenter = presenter,
|
||||
onMangaClicked = ::openManga,
|
||||
@ -106,6 +108,14 @@ class LibraryController(
|
||||
context.toast(if (started) R.string.updating_category else R.string.update_already_running)
|
||||
started
|
||||
},
|
||||
onClickOpenRandomManga = {
|
||||
val items = getMangaForCategory.map { it.libraryManga.manga.id }
|
||||
if (getMangaForCategory.isNotEmpty()) {
|
||||
openManga(items.random())
|
||||
} else {
|
||||
context.toast(R.string.information_no_entries_found)
|
||||
}
|
||||
},
|
||||
onClickInvertSelection = { presenter.invertSelection(presenter.activeCategory) },
|
||||
onClickSelectAll = { presenter.selectAll(presenter.activeCategory) },
|
||||
onClickUnselectAll = ::clearSelection,
|
||||
|
@ -825,7 +825,7 @@ class LibraryPresenter(
|
||||
// SY -->
|
||||
@Composable
|
||||
fun getMangaForCategory(page: Int): List<LibraryItem> {
|
||||
val unfiltered = remember(categories, loadedManga) {
|
||||
val unfiltered = remember(categories, loadedManga, page) {
|
||||
val categoryId = categories.getOrNull(page)?.id ?: -1
|
||||
loadedManga[categoryId] ?: emptyList()
|
||||
}
|
||||
|
@ -72,6 +72,7 @@
|
||||
<string name="action_disable_all">Disable all</string>
|
||||
<string name="action_edit">Edit</string>
|
||||
<string name="action_add">Add</string>
|
||||
<string name="action_open_random_manga">Open random entry</string>
|
||||
<string name="action_add_category">Add category</string>
|
||||
<string name="action_edit_categories">Edit categories</string>
|
||||
<string name="action_rename_category">Rename category</string>
|
||||
@ -842,6 +843,7 @@
|
||||
<string name="information_no_recent">No recent updates</string>
|
||||
<string name="information_no_recent_manga">Nothing read recently</string>
|
||||
<string name="information_empty_library">Your library is empty</string>
|
||||
<string name="information_no_entries_found">No entries found in this category</string>
|
||||
<string name="getting_started_guide">Getting started guide</string>
|
||||
<string name="information_empty_category">You have no categories. Tap the plus button to create one for organizing your library.</string>
|
||||
<string name="information_empty_category_dialog">You don\'t have any categories yet.</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user