Last Commit Merged: 727399611d
This commit is contained in:
LuftVerbot 2023-06-01 22:01:19 +02:00
parent 2fd78fa5d9
commit 76350a4af9
30 changed files with 1088 additions and 1442 deletions

View file

@ -14,7 +14,7 @@ class CreateAnimeCategoryWithName(
private val initialFlags: Long
get() {
val sort = preferences.librarySortingMode().get()
val sort = preferences.libraryAnimeSortingMode().get()
return preferences.libraryDisplayMode().get().flag or
sort.type.flag or
sort.direction.flag

View file

@ -11,7 +11,7 @@ class ResetAnimeCategoryFlags(
suspend fun await() {
val display = preferences.libraryDisplayMode().get()
val sort = preferences.librarySortingMode().get()
val sort = preferences.libraryAnimeSortingMode().get()
categoryRepository.updateAllAnimeCategoryFlags(display + sort.type + sort.direction)
}
}

View file

@ -4,7 +4,7 @@ import eu.kanade.domain.library.service.LibraryPreferences
import tachiyomi.domain.category.anime.repository.AnimeCategoryRepository
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.model.plus
class SetSortModeForAnimeCategory(
@ -12,7 +12,7 @@ class SetSortModeForAnimeCategory(
private val categoryRepository: AnimeCategoryRepository,
) {
suspend fun await(categoryId: Long, type: LibrarySort.Type, direction: LibrarySort.Direction) {
suspend fun await(categoryId: Long, type: AnimeLibrarySort.Type, direction: AnimeLibrarySort.Direction) {
val category = categoryRepository.getAnimeCategory(categoryId) ?: return
val flags = category.flags + type + direction
if (preferences.categorizedDisplaySettings().get()) {
@ -23,12 +23,12 @@ class SetSortModeForAnimeCategory(
),
)
} else {
preferences.librarySortingMode().set(LibrarySort(type, direction))
preferences.libraryAnimeSortingMode().set(AnimeLibrarySort(type, direction))
categoryRepository.updateAllAnimeCategoryFlags(flags)
}
}
suspend fun await(category: Category, type: LibrarySort.Type, direction: LibrarySort.Direction) {
suspend fun await(category: Category, type: AnimeLibrarySort.Type, direction: AnimeLibrarySort.Direction) {
await(category.id, type, direction)
}
}

View file

@ -14,7 +14,7 @@ class CreateMangaCategoryWithName(
private val initialFlags: Long
get() {
val sort = preferences.librarySortingMode().get()
val sort = preferences.libraryMangaSortingMode().get()
return preferences.libraryDisplayMode().get().flag or
sort.type.flag or
sort.direction.flag

View file

@ -11,7 +11,7 @@ class ResetMangaCategoryFlags(
suspend fun await() {
val display = preferences.libraryDisplayMode().get()
val sort = preferences.librarySortingMode().get()
val sort = preferences.libraryMangaSortingMode().get()
categoryRepository.updateAllMangaCategoryFlags(display + sort.type + sort.direction)
}
}

View file

@ -4,7 +4,7 @@ import eu.kanade.domain.library.service.LibraryPreferences
import tachiyomi.domain.category.manga.repository.MangaCategoryRepository
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.manga.model.MangaLibrarySort
import tachiyomi.domain.library.model.plus
class SetSortModeForMangaCategory(
@ -12,7 +12,7 @@ class SetSortModeForMangaCategory(
private val categoryRepository: MangaCategoryRepository,
) {
suspend fun await(categoryId: Long, type: LibrarySort.Type, direction: LibrarySort.Direction) {
suspend fun await(categoryId: Long, type: MangaLibrarySort.Type, direction: MangaLibrarySort.Direction) {
val category = categoryRepository.getMangaCategory(categoryId) ?: return
val flags = category.flags + type + direction
if (preferences.categorizedDisplaySettings().get()) {
@ -23,12 +23,12 @@ class SetSortModeForMangaCategory(
),
)
} else {
preferences.librarySortingMode().set(LibrarySort(type, direction))
preferences.libraryMangaSortingMode().set(MangaLibrarySort(type, direction))
categoryRepository.updateAllMangaCategoryFlags(flags)
}
}
suspend fun await(category: Category, type: LibrarySort.Type, direction: LibrarySort.Direction) {
suspend fun await(category: Category, type: MangaLibrarySort.Type, direction: MangaLibrarySort.Direction) {
await(category.id, type, direction)
}
}

View file

@ -1,6 +1,6 @@
package eu.kanade.domain.entries
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.TriState
enum class TriStateFilter {
DISABLED, // Disable filter
@ -8,10 +8,10 @@ enum class TriStateFilter {
ENABLED_NOT, // Enabled with "not" filter
}
fun TriStateFilter.toTriStateGroupState(): ExtendedNavigationView.Item.TriStateGroup.State {
fun TriStateFilter.toTriStateGroupState(): TriState {
return when (this) {
TriStateFilter.DISABLED -> ExtendedNavigationView.Item.TriStateGroup.State.DISABLED
TriStateFilter.ENABLED_IS -> ExtendedNavigationView.Item.TriStateGroup.State.ENABLED_IS
TriStateFilter.ENABLED_NOT -> ExtendedNavigationView.Item.TriStateGroup.State.ENABLED_NOT
TriStateFilter.DISABLED -> TriState.DISABLED
TriStateFilter.ENABLED_IS -> TriState.ENABLED_IS
TriStateFilter.ENABLED_NOT -> TriState.ENABLED_NOT
}
}

View file

@ -4,12 +4,13 @@ import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
import eu.kanade.tachiyomi.data.preference.MANGA_HAS_UNREAD
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
import eu.kanade.tachiyomi.data.preference.MANGA_NON_READ
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.TriState
import tachiyomi.core.preference.PreferenceStore
import tachiyomi.domain.entries.anime.model.Anime
import tachiyomi.domain.entries.manga.model.Manga
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.manga.model.MangaLibrarySort
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibrarySort
class LibraryPreferences(
private val preferenceStore: PreferenceStore,
@ -23,7 +24,9 @@ class LibraryPreferences(
fun libraryDisplayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize)
fun librarySortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize)
fun libraryMangaSortingMode() = preferenceStore.getObject("library_sorting_mode", MangaLibrarySort.default, MangaLibrarySort.Serializer::serialize, MangaLibrarySort.Serializer::deserialize)
fun libraryAnimeSortingMode() = preferenceStore.getObject("animelib_sorting_mode", AnimeLibrarySort.default, AnimeLibrarySort.Serializer::serialize, AnimeLibrarySort.Serializer::deserialize)
fun libraryUpdateInterval() = preferenceStore.getInt("pref_library_update_interval_key", 24)
@ -71,23 +74,23 @@ class LibraryPreferences(
// Mixture Filter
fun filterDownloadedAnime() = preferenceStore.getInt("pref_filter_animelib_downloaded", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterDownloadedManga() = preferenceStore.getInt("pref_filter_library_downloaded", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterDownloadedAnime() = preferenceStore.getInt("pref_filter_animelib_downloaded", TriState.DISABLED.value)
fun filterDownloadedManga() = preferenceStore.getInt("pref_filter_library_downloaded", TriState.DISABLED.value)
fun filterUnseen() = preferenceStore.getInt("pref_filter_animelib_unread", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterUnread() = preferenceStore.getInt("pref_filter_library_unread", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterUnseen() = preferenceStore.getInt("pref_filter_animelib_unread", TriState.DISABLED.value)
fun filterUnread() = preferenceStore.getInt("pref_filter_library_unread", TriState.DISABLED.value)
fun filterStartedAnime() = preferenceStore.getInt("pref_filter_animelib_started", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterStartedManga() = preferenceStore.getInt("pref_filter_library_started", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterStartedAnime() = preferenceStore.getInt("pref_filter_animelib_started", TriState.DISABLED.value)
fun filterStartedManga() = preferenceStore.getInt("pref_filter_library_started", TriState.DISABLED.value)
fun filterBookmarkedAnime() = preferenceStore.getInt("pref_filter_animelib_bookmarked", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterBookmarkedManga() = preferenceStore.getInt("pref_filter_library_bookmarked", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterBookmarkedAnime() = preferenceStore.getInt("pref_filter_animelib_bookmarked", TriState.DISABLED.value)
fun filterBookmarkedManga() = preferenceStore.getInt("pref_filter_library_bookmarked", TriState.DISABLED.value)
fun filterCompletedAnime() = preferenceStore.getInt("pref_filter_animelib_completed", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterCompletedManga() = preferenceStore.getInt("pref_filter_library_completed", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterCompletedAnime() = preferenceStore.getInt("pref_filter_animelib_completed", TriState.DISABLED.value)
fun filterCompletedManga() = preferenceStore.getInt("pref_filter_library_completed", TriState.DISABLED.value)
fun filterTrackedAnime(name: Int) = preferenceStore.getInt("pref_filter_animelib_tracked_$name", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterTrackedManga(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value)
fun filterTrackedAnime(name: Int) = preferenceStore.getInt("pref_filter_animelib_tracked_$name", TriState.DISABLED.value)
fun filterTrackedManga(name: Int) = preferenceStore.getInt("pref_filter_library_tracked_$name", TriState.DISABLED.value)
// Mixture Update Count

View file

@ -1,5 +1,6 @@
package eu.kanade.presentation.components
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
@ -14,6 +15,7 @@ import androidx.compose.material.icons.filled.ArrowUpward
import androidx.compose.material.icons.rounded.CheckBox
import androidx.compose.material.icons.rounded.CheckBoxOutlineBlank
import androidx.compose.material.icons.rounded.DisabledByDefault
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
@ -21,19 +23,35 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import tachiyomi.domain.entries.TriStateFilter
import tachiyomi.presentation.core.theme.header
@Composable
fun HeadingItem(
@StringRes labelRes: Int,
) {
Text(
text = stringResource(labelRes),
style = MaterialTheme.typography.header,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = TabbedDialogPaddings.Horizontal, vertical = 12.dp),
)
}
@Composable
fun TriStateItem(
label: String,
state: TriStateFilter,
enabled: Boolean = true,
onClick: ((TriStateFilter) -> Unit)?,
) {
Row(
modifier = Modifier
.clickable(
enabled = onClick != null,
enabled = enabled && onClick != null,
onClick = {
when (state) {
TriStateFilter.DISABLED -> onClick?.invoke(TriStateFilter.ENABLED_IS)
@ -47,7 +65,7 @@ fun TriStateItem(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),
) {
val stateAlpha = if (onClick != null) 1f else ContentAlpha.disabled
val stateAlpha = if (enabled && onClick != null) 1f else ContentAlpha.disabled
Icon(
imageVector = when (state) {
@ -56,7 +74,7 @@ fun TriStateItem(
TriStateFilter.ENABLED_NOT -> Icons.Rounded.DisabledByDefault
},
contentDescription = null,
tint = if (state == TriStateFilter.DISABLED) {
tint = if (!enabled || state == TriStateFilter.DISABLED) {
MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = stateAlpha)
} else {
when (onClick) {
@ -109,6 +127,31 @@ fun SortItem(
}
}
@Composable
fun CheckboxItem(
label: String,
checked: Boolean,
onClick: () -> Unit,
) {
Row(
modifier = Modifier
.clickable(onClick = onClick)
.fillMaxWidth()
.padding(horizontal = TabbedDialogPaddings.Horizontal, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),
) {
Checkbox(
checked = checked,
onCheckedChange = null,
)
Text(
text = label,
style = MaterialTheme.typography.bodyMedium,
)
}
}
@Composable
fun RadioItem(
label: String,

View file

@ -1,11 +1,11 @@
package eu.kanade.presentation.components
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
@ -20,12 +20,9 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEachIndexed
@ -85,26 +82,13 @@ fun TabbedDialog(
}
Divider()
val density = LocalDensity.current
var largestHeight by rememberSaveable { mutableStateOf(0f) }
HorizontalPager(
modifier = Modifier.heightIn(min = largestHeight.dp),
modifier = Modifier.animateContentSize(),
count = tabTitles.size,
state = pagerState,
verticalAlignment = Alignment.Top,
) { page ->
Box(
modifier = Modifier.onSizeChanged {
with(density) {
val heightDp = it.height.toDp()
if (heightDp.value > largestHeight) {
largestHeight = heightDp.value
}
}
},
) {
content(contentPadding, page)
}
content(contentPadding, page)
}
}
}

View file

@ -0,0 +1,249 @@
package eu.kanade.presentation.library.anime
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.presentation.components.CheckboxItem
import eu.kanade.presentation.components.HeadingItem
import eu.kanade.presentation.components.RadioItem
import eu.kanade.presentation.components.SortItem
import eu.kanade.presentation.components.TabbedDialog
import eu.kanade.presentation.components.TabbedDialogPaddings
import eu.kanade.presentation.components.TriStateItem
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.library.anime.AnimeLibrarySettingsScreenModel
import eu.kanade.tachiyomi.widget.toTriStateFilter
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.entries.TriStateFilter
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.manga.model.sort
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.display
@Composable
fun AnimeLibrarySettingsDialog(
onDismissRequest: () -> Unit,
screenModel: AnimeLibrarySettingsScreenModel,
activeCategoryIndex: Int,
) {
val state by screenModel.state.collectAsState()
val category by remember(activeCategoryIndex) {
derivedStateOf { state.categories[activeCategoryIndex] }
}
TabbedDialog(
onDismissRequest = onDismissRequest,
tabTitles = listOf(
stringResource(R.string.action_filter),
stringResource(R.string.action_sort),
stringResource(R.string.action_display),
),
) { contentPadding, page ->
Column(
modifier = Modifier
.padding(contentPadding)
.padding(vertical = TabbedDialogPaddings.Vertical)
.verticalScroll(rememberScrollState()),
) {
when (page) {
0 -> FilterPage(
screenModel = screenModel,
)
1 -> SortPage(
category = category,
screenModel = screenModel,
)
2 -> DisplayPage(
category = category,
screenModel = screenModel,
)
}
}
}
}
@Composable
private fun ColumnScope.FilterPage(
screenModel: AnimeLibrarySettingsScreenModel,
) {
val filterDownloaded by screenModel.libraryPreferences.filterDownloadedAnime().collectAsState()
val downloadedOnly by screenModel.preferences.downloadedOnly().collectAsState()
TriStateItem(
label = stringResource(R.string.label_downloaded),
state = if (downloadedOnly) {
TriStateFilter.ENABLED_IS
} else {
filterDownloaded.toTriStateFilter()
},
enabled = !downloadedOnly,
onClick = { screenModel.toggleFilter(LibraryPreferences::filterDownloadedAnime) },
)
val filterUnseen by screenModel.libraryPreferences.filterUnseen().collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_unseen),
state = filterUnseen.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterUnseen) },
)
val filterStarted by screenModel.libraryPreferences.filterStartedAnime().collectAsState()
TriStateItem(
label = stringResource(R.string.label_started),
state = filterStarted.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterStartedAnime) },
)
val filterBookmarked by screenModel.libraryPreferences.filterBookmarkedAnime().collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_bookmarked),
state = filterBookmarked.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterBookmarkedAnime) },
)
val filterCompleted by screenModel.libraryPreferences.filterCompletedAnime().collectAsState()
TriStateItem(
label = stringResource(R.string.completed),
state = filterCompleted.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompletedAnime) },
)
when (screenModel.trackServices.size) {
0 -> {
// No trackers
}
1 -> {
val service = screenModel.trackServices[0]
val filterTracker by screenModel.libraryPreferences.filterTrackedAnime(service.id.toInt()).collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_tracked),
state = filterTracker.toTriStateFilter(),
onClick = { screenModel.toggleTracker(service.id.toInt()) },
)
}
else -> {
HeadingItem(R.string.action_filter_tracked)
screenModel.trackServices.map { service ->
val filterTracker by screenModel.libraryPreferences.filterTrackedAnime(service.id.toInt()).collectAsState()
TriStateItem(
label = stringResource(service.nameRes()),
state = filterTracker.toTriStateFilter(),
onClick = { screenModel.toggleTracker(service.id.toInt()) },
)
}
}
}
}
@Composable
private fun ColumnScope.SortPage(
category: Category,
screenModel: AnimeLibrarySettingsScreenModel,
) {
val sortingMode = category.sort.type
val sortDescending = !category.sort.isAscending
listOf(
R.string.action_sort_alpha to AnimeLibrarySort.Type.Alphabetical,
R.string.action_sort_total_episodes to AnimeLibrarySort.Type.TotalEpisodes,
R.string.action_sort_last_seen to AnimeLibrarySort.Type.LastSeen,
R.string.action_sort_last_anime_update to AnimeLibrarySort.Type.LastUpdate,
R.string.action_sort_unseen_count to AnimeLibrarySort.Type.UnseenCount,
R.string.action_sort_latest_episode to AnimeLibrarySort.Type.LatestEpisode,
R.string.action_sort_episode_fetch_date to AnimeLibrarySort.Type.EpisodeFetchDate,
R.string.action_sort_date_added to AnimeLibrarySort.Type.DateAdded,
).map { (titleRes, mode) ->
SortItem(
label = stringResource(titleRes),
sortDescending = sortDescending.takeIf { sortingMode == mode },
onClick = {
val isTogglingDirection = sortingMode == mode
val direction = when {
isTogglingDirection -> if (sortDescending) AnimeLibrarySort.Direction.Ascending else AnimeLibrarySort.Direction.Descending
else -> if (sortDescending) AnimeLibrarySort.Direction.Descending else AnimeLibrarySort.Direction.Ascending
}
screenModel.setSort(category, mode, direction)
},
)
}
}
@Composable
private fun ColumnScope.DisplayPage(
category: Category,
screenModel: AnimeLibrarySettingsScreenModel,
) {
HeadingItem(R.string.action_display_mode)
listOf(
R.string.action_display_grid to LibraryDisplayMode.CompactGrid,
R.string.action_display_comfortable_grid to LibraryDisplayMode.ComfortableGrid,
R.string.action_display_cover_only_grid to LibraryDisplayMode.CoverOnlyGrid,
R.string.action_display_list to LibraryDisplayMode.List,
).map { (titleRes, mode) ->
RadioItem(
label = stringResource(titleRes),
selected = category.display == mode,
onClick = { screenModel.setDisplayMode(category, mode) },
)
}
HeadingItem(R.string.badges_header)
val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_download_badge_anime),
checked = downloadBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::downloadBadge)
},
)
val localBadge by screenModel.libraryPreferences.localBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_local_badge),
checked = localBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::localBadge)
},
)
val languageBadge by screenModel.libraryPreferences.languageBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_language_badge),
checked = languageBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::languageBadge)
},
)
HeadingItem(R.string.tabs_header)
val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_tabs),
checked = categoryTabs,
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryTabs)
},
)
val categoryNumberOfItems by screenModel.libraryPreferences.categoryNumberOfItems().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_number_of_items),
checked = categoryNumberOfItems,
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems)
},
)
HeadingItem(R.string.other_header)
val showContinueWatchingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueWatchingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)
}

View file

@ -0,0 +1,249 @@
package eu.kanade.presentation.library.manga
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.presentation.components.CheckboxItem
import eu.kanade.presentation.components.HeadingItem
import eu.kanade.presentation.components.RadioItem
import eu.kanade.presentation.components.SortItem
import eu.kanade.presentation.components.TabbedDialog
import eu.kanade.presentation.components.TabbedDialogPaddings
import eu.kanade.presentation.components.TriStateItem
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.library.manga.MangaLibrarySettingsScreenModel
import eu.kanade.tachiyomi.widget.toTriStateFilter
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.entries.TriStateFilter
import tachiyomi.domain.library.manga.model.MangaLibrarySort
import tachiyomi.domain.library.manga.model.sort
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.display
@Composable
fun MangaLibrarySettingsDialog(
onDismissRequest: () -> Unit,
screenModel: MangaLibrarySettingsScreenModel,
activeCategoryIndex: Int,
) {
val state by screenModel.state.collectAsState()
val category by remember(activeCategoryIndex) {
derivedStateOf { state.categories[activeCategoryIndex] }
}
TabbedDialog(
onDismissRequest = onDismissRequest,
tabTitles = listOf(
stringResource(R.string.action_filter),
stringResource(R.string.action_sort),
stringResource(R.string.action_display),
),
) { contentPadding, page ->
Column(
modifier = Modifier
.padding(contentPadding)
.padding(vertical = TabbedDialogPaddings.Vertical)
.verticalScroll(rememberScrollState()),
) {
when (page) {
0 -> FilterPage(
screenModel = screenModel,
)
1 -> SortPage(
category = category,
screenModel = screenModel,
)
2 -> DisplayPage(
category = category,
screenModel = screenModel,
)
}
}
}
}
@Composable
private fun ColumnScope.FilterPage(
screenModel: MangaLibrarySettingsScreenModel,
) {
val filterDownloaded by screenModel.libraryPreferences.filterDownloadedManga().collectAsState()
val downloadedOnly by screenModel.preferences.downloadedOnly().collectAsState()
TriStateItem(
label = stringResource(R.string.label_downloaded),
state = if (downloadedOnly) {
TriStateFilter.ENABLED_IS
} else {
filterDownloaded.toTriStateFilter()
},
enabled = !downloadedOnly,
onClick = { screenModel.toggleFilter(LibraryPreferences::filterDownloadedManga) },
)
val filterUnread by screenModel.libraryPreferences.filterUnread().collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_unread),
state = filterUnread.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterUnread) },
)
val filterStarted by screenModel.libraryPreferences.filterStartedManga().collectAsState()
TriStateItem(
label = stringResource(R.string.label_started),
state = filterStarted.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterStartedManga) },
)
val filterBookmarked by screenModel.libraryPreferences.filterBookmarkedManga().collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_bookmarked),
state = filterBookmarked.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterBookmarkedManga) },
)
val filterCompleted by screenModel.libraryPreferences.filterCompletedManga().collectAsState()
TriStateItem(
label = stringResource(R.string.completed),
state = filterCompleted.toTriStateFilter(),
onClick = { screenModel.toggleFilter(LibraryPreferences::filterCompletedManga) },
)
when (screenModel.trackServices.size) {
0 -> {
// No trackers
}
1 -> {
val service = screenModel.trackServices[0]
val filterTracker by screenModel.libraryPreferences.filterTrackedManga(service.id.toInt()).collectAsState()
TriStateItem(
label = stringResource(R.string.action_filter_tracked),
state = filterTracker.toTriStateFilter(),
onClick = { screenModel.toggleTracker(service.id.toInt()) },
)
}
else -> {
HeadingItem(R.string.action_filter_tracked)
screenModel.trackServices.map { service ->
val filterTracker by screenModel.libraryPreferences.filterTrackedManga(service.id.toInt()).collectAsState()
TriStateItem(
label = stringResource(service.nameRes()),
state = filterTracker.toTriStateFilter(),
onClick = { screenModel.toggleTracker(service.id.toInt()) },
)
}
}
}
}
@Composable
private fun ColumnScope.SortPage(
category: Category,
screenModel: MangaLibrarySettingsScreenModel,
) {
val sortingMode = category.sort.type
val sortDescending = !category.sort.isAscending
listOf(
R.string.action_sort_alpha to MangaLibrarySort.Type.Alphabetical,
R.string.action_sort_total to MangaLibrarySort.Type.TotalChapters,
R.string.action_sort_last_read to MangaLibrarySort.Type.LastRead,
R.string.action_sort_last_manga_update to MangaLibrarySort.Type.LastUpdate,
R.string.action_sort_unread_count to MangaLibrarySort.Type.UnreadCount,
R.string.action_sort_latest_chapter to MangaLibrarySort.Type.LatestChapter,
R.string.action_sort_chapter_fetch_date to MangaLibrarySort.Type.ChapterFetchDate,
R.string.action_sort_date_added to MangaLibrarySort.Type.DateAdded,
).map { (titleRes, mode) ->
SortItem(
label = stringResource(titleRes),
sortDescending = sortDescending.takeIf { sortingMode == mode },
onClick = {
val isTogglingDirection = sortingMode == mode
val direction = when {
isTogglingDirection -> if (sortDescending) MangaLibrarySort.Direction.Ascending else MangaLibrarySort.Direction.Descending
else -> if (sortDescending) MangaLibrarySort.Direction.Descending else MangaLibrarySort.Direction.Ascending
}
screenModel.setSort(category, mode, direction)
},
)
}
}
@Composable
private fun ColumnScope.DisplayPage(
category: Category,
screenModel: MangaLibrarySettingsScreenModel,
) {
HeadingItem(R.string.action_display_mode)
listOf(
R.string.action_display_grid to LibraryDisplayMode.CompactGrid,
R.string.action_display_comfortable_grid to LibraryDisplayMode.ComfortableGrid,
R.string.action_display_cover_only_grid to LibraryDisplayMode.CoverOnlyGrid,
R.string.action_display_list to LibraryDisplayMode.List,
).map { (titleRes, mode) ->
RadioItem(
label = stringResource(titleRes),
selected = category.display == mode,
onClick = { screenModel.setDisplayMode(category, mode) },
)
}
HeadingItem(R.string.badges_header)
val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_download_badge),
checked = downloadBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::downloadBadge)
},
)
val localBadge by screenModel.libraryPreferences.localBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_local_badge),
checked = localBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::localBadge)
},
)
val languageBadge by screenModel.libraryPreferences.languageBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_language_badge),
checked = languageBadge,
onClick = {
screenModel.togglePreference(LibraryPreferences::languageBadge)
},
)
HeadingItem(R.string.tabs_header)
val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_tabs),
checked = categoryTabs,
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryTabs)
},
)
val categoryNumberOfItems by screenModel.libraryPreferences.categoryNumberOfItems().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_number_of_items),
checked = categoryNumberOfItems,
onClick = {
screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems)
},
)
HeadingItem(R.string.other_header)
val showContinueReadingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueReadingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)
}

View file

@ -25,7 +25,7 @@ import eu.kanade.tachiyomi.util.preference.minusAssign
import eu.kanade.tachiyomi.util.preference.plusAssign
import eu.kanade.tachiyomi.util.system.DeviceUtil
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.TriState
import tachiyomi.core.preference.PreferenceStore
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -105,11 +105,19 @@ object Migrations {
}
if (oldVersion < 44) {
// Reset sorting preference if using removed sort by source
val oldSortingMode = prefs.getInt(libraryPreferences.librarySortingMode().key(), 0)
val oldMangaSortingMode = prefs.getInt(libraryPreferences.libraryMangaSortingMode().key(), 0)
if (oldSortingMode == 5) { // SOURCE = 5
if (oldMangaSortingMode == 5) { // SOURCE = 5
prefs.edit {
putInt(libraryPreferences.librarySortingMode().key(), 0) // ALPHABETICAL = 0
putInt(libraryPreferences.libraryMangaSortingMode().key(), 0) // ALPHABETICAL = 0
}
}
val oldAnimeSortingMode = prefs.getInt(libraryPreferences.libraryAnimeSortingMode().key(), 0)
if (oldAnimeSortingMode == 5) { // SOURCE = 5
prefs.edit {
putInt(libraryPreferences.libraryAnimeSortingMode().key(), 0) // ALPHABETICAL = 0
}
}
}
@ -118,9 +126,9 @@ object Migrations {
fun convertBooleanPrefToTriState(key: String): Int {
val oldPrefValue = prefs.getBoolean(key, false)
return if (oldPrefValue) {
ExtendedNavigationView.Item.TriStateGroup.State.ENABLED_IS.value
TriState.ENABLED_IS.value
} else {
ExtendedNavigationView.Item.TriStateGroup.State.DISABLED.value
TriState.DISABLED.value
}
}
prefs.edit {
@ -202,10 +210,11 @@ object Migrations {
AnimeLibraryUpdateJob.setupTask(context)
}
if (oldVersion < 64) {
val oldSortingMode = prefs.getInt(libraryPreferences.librarySortingMode().key(), 0)
val oldMangaSortingMode = prefs.getInt(libraryPreferences.libraryMangaSortingMode().key(), 0)
val oldAnimeSortingMode = prefs.getInt(libraryPreferences.libraryAnimeSortingMode().key(), 0)
val oldSortingDirection = prefs.getBoolean("library_sorting_ascending", true)
val newSortingMode = when (oldSortingMode) {
val newMangaSortingMode = when (oldMangaSortingMode) {
0 -> "ALPHABETICAL"
1 -> "LAST_READ"
2 -> "LAST_CHECKED"
@ -217,18 +226,32 @@ object Migrations {
else -> "ALPHABETICAL"
}
val newAnimeSortingMode = when (oldAnimeSortingMode) {
0 -> "ALPHABETICAL"
1 -> "LAST_SEEN"
2 -> "LAST_CHECKED"
3 -> "UNSEEN"
4 -> "TOTAL_EPISODES"
6 -> "LATEST_EPISODE"
8 -> "DATE_FETCHED"
7 -> "DATE_ADDED"
else -> "ALPHABETICAL"
}
val newSortingDirection = when (oldSortingDirection) {
true -> "ASCENDING"
else -> "DESCENDING"
}
prefs.edit(commit = true) {
remove(libraryPreferences.librarySortingMode().key())
remove(libraryPreferences.libraryMangaSortingMode().key())
remove(libraryPreferences.libraryAnimeSortingMode().key())
remove("library_sorting_ascending")
}
prefs.edit {
putString(libraryPreferences.librarySortingMode().key(), newSortingMode)
putString(libraryPreferences.libraryMangaSortingMode().key(), newMangaSortingMode)
putString(libraryPreferences.libraryAnimeSortingMode().key(), newAnimeSortingMode)
putString("library_sorting_ascending", newSortingDirection)
}
}
@ -274,20 +297,29 @@ object Migrations {
if (oldVersion < 81) {
// Handle renamed enum values
prefs.edit {
val newSortingMode = when (val oldSortingMode = prefs.getString(libraryPreferences.librarySortingMode().key(), "ALPHABETICAL")) {
val newMangaSortingMode = when (val oldSortingMode = prefs.getString(libraryPreferences.libraryMangaSortingMode().key(), "ALPHABETICAL")) {
"LAST_CHECKED" -> "LAST_MANGA_UPDATE"
"UNREAD" -> "UNREAD_COUNT"
"DATE_FETCHED" -> "CHAPTER_FETCH_DATE"
else -> oldSortingMode
}
putString(libraryPreferences.librarySortingMode().key(), newSortingMode)
val newAnimeSortingMode = when (val oldSortingMode = prefs.getString(libraryPreferences.libraryAnimeSortingMode().key(), "ALPHABETICAL")) {
"LAST_CHECKED" -> "LAST_MANGA_UPDATE"
"UNREAD" -> "UNREAD_COUNT"
"DATE_FETCHED" -> "CHAPTER_FETCH_DATE"
else -> oldSortingMode
}
putString(libraryPreferences.libraryMangaSortingMode().key(), newMangaSortingMode)
putString(libraryPreferences.libraryAnimeSortingMode().key(), newAnimeSortingMode)
}
}
if (oldVersion < 82) {
prefs.edit {
val sort = prefs.getString(libraryPreferences.librarySortingMode().key(), null) ?: return@edit
val mangasort = prefs.getString(libraryPreferences.libraryMangaSortingMode().key(), null) ?: return@edit
val animesort = prefs.getString(libraryPreferences.libraryAnimeSortingMode().key(), null) ?: return@edit
val direction = prefs.getString("library_sorting_ascending", "ASCENDING")!!
putString(libraryPreferences.librarySortingMode().key(), "$sort,$direction")
putString(libraryPreferences.libraryMangaSortingMode().key(), "$mangasort,$direction")
putString(libraryPreferences.libraryAnimeSortingMode().key(), "$animesort,$direction")
remove("library_sorting_ascending")
}
}

View file

@ -34,7 +34,7 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.anime.AnimeSourceManager
import eu.kanade.tachiyomi.util.episode.getNextUnseen
import eu.kanade.tachiyomi.util.removeCovers
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup
import eu.kanade.tachiyomi.widget.TriState
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
@ -58,8 +58,8 @@ import tachiyomi.domain.entries.anime.model.AnimeUpdate
import tachiyomi.domain.items.episode.interactor.GetEpisodeByAnimeId
import tachiyomi.domain.items.episode.model.Episode
import tachiyomi.domain.library.anime.LibraryAnime
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.sort
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.anime.model.sort
import tachiyomi.domain.track.anime.interactor.GetTracksPerAnime
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -150,8 +150,8 @@ class AnimeLibraryScreenModel(
prefs.filterStarted or
prefs.filterBookmarked or
prefs.filterCompleted
) != TriStateGroup.State.DISABLED.value
val b = trackFilter.values.any { it != TriStateGroup.State.DISABLED.value }
) != TriState.DISABLED.value
val b = trackFilter.values.any { it != TriState.DISABLED.value }
a || b
}
.distinctUntilChanged()
@ -180,17 +180,17 @@ class AnimeLibraryScreenModel(
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_NOT.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_IS.value) it.key else null }
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_NOT.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_IS.value) it.key else null }
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
val filterFnDownloaded: (AnimeLibraryItem) -> Boolean = downloaded@{
if (!downloadedOnly && filterDownloaded == TriStateGroup.State.DISABLED.value) return@downloaded true
if (!downloadedOnly && filterDownloaded == TriState.DISABLED.value) return@downloaded true
val isDownloaded = it.libraryAnime.anime.isLocal() ||
it.downloadCount > 0 ||
downloadManager.getDownloadCount(it.libraryAnime.anime) > 0
return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.ENABLED_IS.value) {
return@downloaded if (downloadedOnly || filterDownloaded == TriState.ENABLED_IS.value) {
isDownloaded
} else {
!isDownloaded
@ -198,10 +198,10 @@ class AnimeLibraryScreenModel(
}
val filterFnUnread: (AnimeLibraryItem) -> Boolean = unread@{
if (filterUnread == TriStateGroup.State.DISABLED.value) return@unread true
if (filterUnread == TriState.DISABLED.value) return@unread true
val isUnread = it.libraryAnime.unseenCount > 0
return@unread if (filterUnread == TriStateGroup.State.ENABLED_IS.value) {
return@unread if (filterUnread == TriState.ENABLED_IS.value) {
isUnread
} else {
!isUnread
@ -209,10 +209,10 @@ class AnimeLibraryScreenModel(
}
val filterFnStarted: (AnimeLibraryItem) -> Boolean = started@{
if (filterStarted == TriStateGroup.State.DISABLED.value) return@started true
if (filterStarted == TriState.DISABLED.value) return@started true
val hasStarted = it.libraryAnime.hasStarted
return@started if (filterStarted == TriStateGroup.State.ENABLED_IS.value) {
return@started if (filterStarted == TriState.ENABLED_IS.value) {
hasStarted
} else {
!hasStarted
@ -220,10 +220,10 @@ class AnimeLibraryScreenModel(
}
val filterFnBookmarked: (AnimeLibraryItem) -> Boolean = bookmarked@{
if (filterBookmarked == TriStateGroup.State.DISABLED.value) return@bookmarked true
if (filterBookmarked == TriState.DISABLED.value) return@bookmarked true
val hasBookmarks = it.libraryAnime.hasBookmarks
return@bookmarked if (filterBookmarked == TriStateGroup.State.ENABLED_IS.value) {
return@bookmarked if (filterBookmarked == TriState.ENABLED_IS.value) {
hasBookmarks
} else {
!hasBookmarks
@ -231,10 +231,10 @@ class AnimeLibraryScreenModel(
}
val filterFnCompleted: (AnimeLibraryItem) -> Boolean = completed@{
if (filterCompleted == TriStateGroup.State.DISABLED.value) return@completed true
if (filterCompleted == TriState.DISABLED.value) return@completed true
val isCompleted = it.libraryAnime.anime.status.toInt() == SAnime.COMPLETED
return@completed if (filterCompleted == TriStateGroup.State.ENABLED_IS.value) {
return@completed if (filterCompleted == TriState.ENABLED_IS.value) {
isCompleted
} else {
!isCompleted
@ -290,32 +290,32 @@ class AnimeLibraryScreenModel(
val sortFn: (AnimeLibraryItem, AnimeLibraryItem) -> Int = { i1, i2 ->
val sort = keys.find { it.id == i1.libraryAnime.category }!!.sort
when (sort.type) {
LibrarySort.Type.Alphabetical -> {
AnimeLibrarySort.Type.Alphabetical -> {
sortAlphabetically(i1, i2)
}
LibrarySort.Type.LastRead -> {
AnimeLibrarySort.Type.LastSeen -> {
i1.libraryAnime.lastSeen.compareTo(i2.libraryAnime.lastSeen)
}
LibrarySort.Type.LastUpdate -> {
AnimeLibrarySort.Type.LastUpdate -> {
i1.libraryAnime.anime.lastUpdate.compareTo(i2.libraryAnime.anime.lastUpdate)
}
LibrarySort.Type.UnreadCount -> when {
AnimeLibrarySort.Type.UnseenCount -> when {
// Ensure unread content comes first
i1.libraryAnime.unseenCount == i2.libraryAnime.unseenCount -> 0
i1.libraryAnime.unseenCount == 0L -> if (sort.isAscending) 1 else -1
i2.libraryAnime.unseenCount == 0L -> if (sort.isAscending) -1 else 1
else -> i1.libraryAnime.unseenCount.compareTo(i2.libraryAnime.unseenCount)
}
LibrarySort.Type.TotalChapters -> {
AnimeLibrarySort.Type.TotalEpisodes -> {
i1.libraryAnime.totalEpisodes.compareTo(i2.libraryAnime.totalEpisodes)
}
LibrarySort.Type.LatestChapter -> {
AnimeLibrarySort.Type.LatestEpisode -> {
i1.libraryAnime.latestUpload.compareTo(i2.libraryAnime.latestUpload)
}
LibrarySort.Type.ChapterFetchDate -> {
AnimeLibrarySort.Type.EpisodeFetchDate -> {
i1.libraryAnime.episodeFetchedAt.compareTo(i2.libraryAnime.episodeFetchedAt)
}
LibrarySort.Type.DateAdded -> {
AnimeLibrarySort.Type.DateAdded -> {
i1.libraryAnime.anime.dateAdded.compareTo(i2.libraryAnime.anime.dateAdded)
}
}
@ -573,6 +573,10 @@ class AnimeLibraryScreenModel(
}
}
fun showSettingsDialog() {
mutableState.update { it.copy(dialog = Dialog.SettingsSheet) }
}
fun clearSelection() {
mutableState.update { it.copy(selection = emptyList()) }
}
@ -691,6 +695,7 @@ class AnimeLibraryScreenModel(
}
sealed class Dialog {
object SettingsSheet : Dialog()
data class ChangeCategory(val anime: List<Anime>, val initialSelection: List<CheckboxState<Category>>) : Dialog()
data class DeleteAnime(val anime: List<Anime>) : Dialog()
}

View file

@ -0,0 +1,84 @@
package eu.kanade.tachiyomi.ui.library.anime
import androidx.compose.runtime.Immutable
import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.coroutineScope
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.anime.interactor.SetDisplayModeForAnimeCategory
import eu.kanade.domain.category.anime.interactor.SetSortModeForAnimeCategory
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.util.preference.toggle
import eu.kanade.tachiyomi.widget.TriState
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.getAndSet
import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.anime.interactor.GetAnimeCategories
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.model.LibraryDisplayMode
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class AnimeLibrarySettingsScreenModel(
val preferences: BasePreferences = Injekt.get(),
val libraryPreferences: LibraryPreferences = Injekt.get(),
private val getCategories: GetAnimeCategories = Injekt.get(),
private val setDisplayModeForCategory: SetDisplayModeForAnimeCategory = Injekt.get(),
private val setSortModeForCategory: SetSortModeForAnimeCategory = Injekt.get(),
trackManager: TrackManager = Injekt.get(),
) : StateScreenModel<AnimeLibrarySettingsScreenModel.State>(State()) {
val trackServices = trackManager.services.filter { service -> service.isLogged }
init {
coroutineScope.launchIO {
getCategories.subscribe()
.collectLatest {
mutableState.update { state ->
state.copy(
categories = it,
)
}
}
}
}
fun togglePreference(preference: (LibraryPreferences) -> Preference<Boolean>) {
preference(libraryPreferences).toggle()
}
fun toggleFilter(preference: (LibraryPreferences) -> Preference<Int>) {
preference(libraryPreferences).getAndSet {
when (it) {
TriState.DISABLED.value -> TriState.ENABLED_IS.value
TriState.ENABLED_IS.value -> TriState.ENABLED_NOT.value
TriState.ENABLED_NOT.value -> TriState.DISABLED.value
else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
}
}
}
fun toggleTracker(id: Int) {
toggleFilter { libraryPreferences.filterTrackedAnime(id) }
}
fun setDisplayMode(category: Category, mode: LibraryDisplayMode) {
coroutineScope.launchIO {
setDisplayModeForCategory.await(category, mode)
}
}
fun setSort(category: Category, mode: AnimeLibrarySort.Type, direction: AnimeLibrarySort.Direction) {
coroutineScope.launchIO {
setSortModeForCategory.await(category, mode, direction)
}
}
@Immutable
data class State(
val categories: List<Category> = emptyList(),
)
}

View file

@ -1,475 +0,0 @@
package eu.kanade.tachiyomi.ui.library.anime
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.View
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.anime.interactor.SetDisplayModeForAnimeCategory
import eu.kanade.domain.category.anime.interactor.SetSortModeForAnimeCategory
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.AnimeTrackService
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.display
import tachiyomi.domain.library.model.sort
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class AnimeLibrarySettingsSheet(
activity: Activity,
private val trackManager: TrackManager = Injekt.get(),
private val setDisplayModeForCategory: SetDisplayModeForAnimeCategory = Injekt.get(),
private val setSortModeForCategory: SetSortModeForAnimeCategory = Injekt.get(),
) : TabbedBottomSheetDialog(activity) {
val filters: Filter
private val sort: Sort
private val display: Display
val sheetScope = CoroutineScope(Job() + Dispatchers.IO)
init {
filters = Filter(activity)
sort = Sort(activity)
display = Display(activity)
}
/**
* adjusts selected button to match real state.
* @param currentCategory ID of currently shown category
*/
fun show(currentCategory: Category) {
filters.adjustFilterSelection()
sort.currentCategory = currentCategory
sort.adjustDisplaySelection()
display.currentCategory = currentCategory
display.adjustDisplaySelection()
super.show()
}
override fun getTabViews(): List<View> = listOf(
filters,
sort,
display,
)
override fun getTabTitles(): List<Int> = listOf(
R.string.action_filter,
R.string.action_sort,
R.string.action_display,
)
/**
* Filters group (unseen, downloaded, ...).
*/
inner class Filter @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val filterGroup = FilterGroup()
init {
setGroups(listOf(filterGroup))
}
// Refreshes Filter Setting selections
fun adjustFilterSelection() {
filterGroup.initModels()
filterGroup.items.forEach { adapter.notifyItemChanged(it) }
}
/**
* Returns true if there's at least one filter from [FilterGroup] active.
*/
fun hasActiveFilters(): Boolean {
return filterGroup.items.filterIsInstance<Item.TriStateGroup>().any { it.state != State.DISABLED.value }
}
inner class FilterGroup : Group {
private val downloaded = Item.TriStateGroup(R.string.label_downloaded, this)
private val unseen = Item.TriStateGroup(R.string.action_filter_unseen, this)
private val started = Item.TriStateGroup(R.string.label_started, this)
private val bookmarked = Item.TriStateGroup(R.string.action_filter_bookmarked, this)
private val completed = Item.TriStateGroup(R.string.completed, this)
private val trackFilters: Map<Long, Item.TriStateGroup>
override val header = null
override val items: List<Item>
override val footer = null
init {
trackManager.services.filter { service -> service.isLogged && service is AnimeTrackService }
.also { services ->
val size = services.size
trackFilters = services.associate { service ->
Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this))
}
val list: MutableList<Item> = mutableListOf(downloaded, unseen, started, bookmarked, completed)
if (size > 1) list.add(Item.Header(R.string.action_filter_tracked))
list.addAll(trackFilters.values)
items = list
}
}
private fun getServiceResId(service: TrackService, size: Int): Int {
return if (size > 1) service.nameRes() else R.string.action_filter_tracked
}
override fun initModels() {
if (preferences.downloadedOnly().get()) {
downloaded.state = State.ENABLED_IS.value
downloaded.enabled = false
} else {
downloaded.state = libraryPreferences.filterDownloadedAnime().get()
downloaded.enabled = true
}
unseen.state = libraryPreferences.filterUnseen().get()
started.state = libraryPreferences.filterStartedAnime().get()
bookmarked.state = libraryPreferences.filterBookmarkedAnime().get()
completed.state = libraryPreferences.filterCompletedAnime().get()
trackFilters.forEach { trackFilter ->
trackFilter.value.state = libraryPreferences.filterTrackedAnime(trackFilter.key.toInt()).get()
}
}
override fun onItemClicked(item: Item) {
item as Item.TriStateGroup
val newState = when (item.state) {
State.DISABLED.value -> State.ENABLED_IS.value
State.ENABLED_IS.value -> State.ENABLED_NOT.value
State.ENABLED_NOT.value -> State.DISABLED.value
else -> throw Exception("Unknown State")
}
item.state = newState
when (item) {
downloaded -> libraryPreferences.filterDownloadedAnime().set(newState)
unseen -> libraryPreferences.filterUnseen().set(newState)
started -> libraryPreferences.filterStartedAnime().set(newState)
bookmarked -> libraryPreferences.filterBookmarkedAnime().set(newState)
completed -> libraryPreferences.filterCompletedAnime().set(newState)
else -> {
trackFilters.forEach { trackFilter ->
if (trackFilter.value == item) {
libraryPreferences.filterTrackedAnime(trackFilter.key.toInt()).set(newState)
}
}
}
}
adapter.notifyItemChanged(item)
}
}
}
/**
* Sorting group (alphabetically, by last seen, ...) and ascending or descending.
*/
inner class Sort @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val sort = SortGroup()
init {
setGroups(listOf(sort))
}
// Refreshes Display Setting selections
fun adjustDisplaySelection() {
sort.initModels()
sort.items.forEach { adapter.notifyItemChanged(it) }
}
inner class SortGroup : Group {
private val alphabetically = Item.MultiSort(R.string.action_sort_alpha, this)
private val total = Item.MultiSort(R.string.action_sort_total_episodes, this)
private val lastSeen = Item.MultiSort(R.string.action_sort_last_seen, this)
private val lastChecked = Item.MultiSort(R.string.action_sort_last_anime_update, this)
private val unseen = Item.MultiSort(R.string.action_sort_unseen_count, this)
private val latestEpisode = Item.MultiSort(R.string.action_sort_latest_episode, this)
private val episodeFetchDate = Item.MultiSort(R.string.action_sort_episode_fetch_date, this)
private val dateAdded = Item.MultiSort(R.string.action_sort_date_added, this)
override val header = null
override val items =
listOf(alphabetically, lastSeen, lastChecked, unseen, total, latestEpisode, episodeFetchDate, dateAdded)
override val footer = null
override fun initModels() {
val sort = currentCategory.sort
val order = if (sort.isAscending) Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC
alphabetically.state =
if (sort.type == LibrarySort.Type.Alphabetical) order else Item.MultiSort.SORT_NONE
lastSeen.state =
if (sort.type == LibrarySort.Type.LastRead) order else Item.MultiSort.SORT_NONE
lastChecked.state =
if (sort.type == LibrarySort.Type.LastUpdate) order else Item.MultiSort.SORT_NONE
unseen.state =
if (sort.type == LibrarySort.Type.UnreadCount) order else Item.MultiSort.SORT_NONE
total.state =
if (sort.type == LibrarySort.Type.TotalChapters) order else Item.MultiSort.SORT_NONE
latestEpisode.state =
if (sort.type == LibrarySort.Type.LatestChapter) order else Item.MultiSort.SORT_NONE
episodeFetchDate.state =
if (sort.type == LibrarySort.Type.ChapterFetchDate) order else Item.MultiSort.SORT_NONE
dateAdded.state =
if (sort.type == LibrarySort.Type.DateAdded) order else Item.MultiSort.SORT_NONE
}
override fun onItemClicked(item: Item) {
item as Item.MultiStateGroup
val prevState = item.state
item.group.items.forEach {
(it as Item.MultiStateGroup).state =
Item.MultiSort.SORT_NONE
}
item.state = when (prevState) {
Item.MultiSort.SORT_NONE -> Item.MultiSort.SORT_ASC
Item.MultiSort.SORT_ASC -> Item.MultiSort.SORT_DESC
Item.MultiSort.SORT_DESC -> Item.MultiSort.SORT_ASC
else -> throw Exception("Unknown state")
}
setSortPreference(item)
item.group.items.forEach { adapter.notifyItemChanged(it) }
}
private fun setSortPreference(item: Item.MultiStateGroup) {
val mode = when (item) {
alphabetically -> LibrarySort.Type.Alphabetical
lastSeen -> LibrarySort.Type.LastRead
lastChecked -> LibrarySort.Type.LastUpdate
unseen -> LibrarySort.Type.UnreadCount
total -> LibrarySort.Type.TotalChapters
latestEpisode -> LibrarySort.Type.LatestChapter
episodeFetchDate -> LibrarySort.Type.ChapterFetchDate
dateAdded -> LibrarySort.Type.DateAdded
else -> throw NotImplementedError("Unknown display mode")
}
val direction = if (item.state == Item.MultiSort.SORT_ASC) {
LibrarySort.Direction.Ascending
} else {
LibrarySort.Direction.Descending
}
sheetScope.launchIO {
setSortModeForCategory.await(currentCategory!!, mode, direction)
}
}
}
}
/**
* Display group, to show the library as a list or a grid.
*/
inner class Display @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val displayGroup: DisplayGroup
private val badgeGroup: BadgeGroup
private val tabsGroup: TabsGroup
private val otherGroup: OtherGroup
init {
displayGroup = DisplayGroup()
badgeGroup = BadgeGroup()
tabsGroup = TabsGroup()
otherGroup = OtherGroup()
setGroups(listOf(displayGroup, badgeGroup, tabsGroup, otherGroup))
}
// Refreshes Display Setting selections
fun adjustDisplaySelection() {
val mode = getDisplayModePreference()
displayGroup.setGroupSelections(mode)
displayGroup.items.forEach { adapter.notifyItemChanged(it) }
}
// Gets user preference of currently selected display mode at current category
private fun getDisplayModePreference(): LibraryDisplayMode {
return currentCategory.display
}
inner class DisplayGroup : Group {
private val compactGrid = Item.Radio(R.string.action_display_grid, this)
private val comfortableGrid = Item.Radio(R.string.action_display_comfortable_grid, this)
private val coverOnlyGrid = Item.Radio(R.string.action_display_cover_only_grid, this)
private val list = Item.Radio(R.string.action_display_list, this)
override val header = Item.Header(R.string.action_display_mode)
override val items = listOf(compactGrid, comfortableGrid, coverOnlyGrid, list)
override val footer = null
override fun initModels() {
val mode = getDisplayModePreference()
setGroupSelections(mode)
}
override fun onItemClicked(item: Item) {
item as Item.Radio
if (item.checked) return
item.group.items.forEach { (it as Item.Radio).checked = false }
item.checked = true
setDisplayModePreference(item)
item.group.items.forEach { adapter.notifyItemChanged(it) }
}
// Sets display group selections based on given mode
fun setGroupSelections(mode: LibraryDisplayMode) {
compactGrid.checked = mode == LibraryDisplayMode.CompactGrid
comfortableGrid.checked = mode == LibraryDisplayMode.ComfortableGrid
coverOnlyGrid.checked = mode == LibraryDisplayMode.CoverOnlyGrid
list.checked = mode == LibraryDisplayMode.List
}
private fun setDisplayModePreference(item: Item) {
val flag = when (item) {
compactGrid -> LibraryDisplayMode.CompactGrid
comfortableGrid -> LibraryDisplayMode.ComfortableGrid
coverOnlyGrid -> LibraryDisplayMode.CoverOnlyGrid
list -> LibraryDisplayMode.List
else -> throw NotImplementedError("Unknown display mode")
}
sheetScope.launchIO {
setDisplayModeForCategory.await(currentCategory!!, flag)
}
}
}
inner class BadgeGroup : Group {
private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge_anime, this)
private val localBadge = Item.CheckboxGroup(R.string.action_display_local_badge_anime, this)
private val languageBadge = Item.CheckboxGroup(R.string.action_display_language_badge, this)
override val header = Item.Header(R.string.badges_header)
override val items = listOf(downloadBadge, localBadge, languageBadge)
override val footer = null
override fun initModels() {
downloadBadge.checked = libraryPreferences.downloadBadge().get()
localBadge.checked = libraryPreferences.localBadge().get()
languageBadge.checked = libraryPreferences.languageBadge().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
downloadBadge -> libraryPreferences.downloadBadge().set((item.checked))
localBadge -> libraryPreferences.localBadge().set((item.checked))
languageBadge -> libraryPreferences.languageBadge().set((item.checked))
else -> {}
}
adapter.notifyItemChanged(item)
}
}
inner class TabsGroup : Group {
private val showTabs = Item.CheckboxGroup(R.string.action_display_show_tabs, this)
private val showNumberOfItems = Item.CheckboxGroup(R.string.action_display_show_number_of_items, this)
override val header = Item.Header(R.string.tabs_header)
override val items = listOf(showTabs, showNumberOfItems)
override val footer = null
override fun initModels() {
showTabs.checked = libraryPreferences.categoryTabs().get()
showNumberOfItems.checked = libraryPreferences.categoryNumberOfItems().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
showTabs -> libraryPreferences.categoryTabs().set(item.checked)
showNumberOfItems -> libraryPreferences.categoryNumberOfItems().set(item.checked)
else -> {}
}
adapter.notifyItemChanged(item)
}
}
inner class OtherGroup : Group {
private val showContinueWatchingButton = Item.CheckboxGroup(R.string.action_display_show_continue_reading_button, this)
override val header = Item.Header(R.string.other_header)
override val items = listOf(showContinueWatchingButton)
override val footer = null
override fun initModels() {
showContinueWatchingButton.checked = libraryPreferences.showContinueViewingButton().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
showContinueWatchingButton -> libraryPreferences.showContinueViewingButton().set(item.checked)
else -> {}
}
adapter.notifyItemChanged(item)
}
}
}
open inner class Settings(context: Context, attrs: AttributeSet?) :
ExtendedNavigationView(context, attrs) {
val preferences: BasePreferences by injectLazy()
val libraryPreferences: LibraryPreferences by injectLazy()
lateinit var adapter: Adapter
/**
* Click listener to notify the parent fragment when an item from a group is clicked.
*/
var onGroupClicked: (Group) -> Unit = {}
var currentCategory: Category? = null
fun setGroups(groups: List<Group>) {
adapter = Adapter(groups.map { it.createItems() }.flatten())
recycler.adapter = adapter
groups.forEach { it.initModels() }
addView(recycler)
}
/**
* Adapter of the recycler view.
*/
inner class Adapter(items: List<Item>) : ExtendedNavigationView.Adapter(items) {
override fun onItemClicked(item: Item) {
if (item is GroupedItem) {
item.group.onItemClicked(item)
onGroupClicked(item.group)
}
}
}
}
}

View file

@ -40,6 +40,7 @@ import eu.kanade.presentation.entries.LibraryBottomActionMenu
import eu.kanade.presentation.library.DeleteLibraryEntryDialog
import eu.kanade.presentation.library.LibraryToolbar
import eu.kanade.presentation.library.anime.AnimeLibraryContent
import eu.kanade.presentation.library.anime.AnimeLibrarySettingsDialog
import eu.kanade.presentation.util.Tab
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.library.anime.AnimeLibraryUpdateJob
@ -101,6 +102,7 @@ object AnimeLibraryTab : Tab {
val haptic = LocalHapticFeedback.current
val screenModel = rememberScreenModel { AnimeLibraryScreenModel() }
val settingsScreenModel = rememberScreenModel { AnimeLibrarySettingsScreenModel() }
val state by screenModel.state.collectAsState()
val snackbarHostState = remember { SnackbarHostState() }
@ -113,9 +115,6 @@ object AnimeLibraryTab : Tab {
}
started
}
val onClickFilter: () -> Unit = {
scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategoryIndex]) }
}
fun openEpisodeInternal(context: Context, animeId: Long, episodeId: Long) {
context.startActivity(PlayerActivity.newIntent(context, animeId, episodeId))
@ -151,7 +150,7 @@ object AnimeLibraryTab : Tab {
onClickUnselectAll = screenModel::clearSelection,
onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) },
onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) },
onClickFilter = onClickFilter,
onClickFilter = { screenModel.showSettingsDialog() },
onClickRefresh = { onClickRefresh(null) },
onClickOpenRandomEntry = {
scope.launch {
@ -235,6 +234,11 @@ object AnimeLibraryTab : Tab {
val onDismissRequest = screenModel::closeDialog
when (val dialog = state.dialog) {
is AnimeLibraryScreenModel.Dialog.SettingsSheet -> AnimeLibrarySettingsDialog(
onDismissRequest = onDismissRequest,
screenModel = settingsScreenModel,
activeCategoryIndex = screenModel.activeCategoryIndex,
)
is AnimeLibraryScreenModel.Dialog.ChangeCategory -> {
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
@ -270,8 +274,8 @@ object AnimeLibraryTab : Tab {
}
}
LaunchedEffect(state.selectionMode) {
HomeScreen.showBottomNav(!state.selectionMode)
LaunchedEffect(state.selectionMode, state.dialog) {
HomeScreen.showBottomNav(!state.selectionMode && state.dialog !is AnimeLibraryScreenModel.Dialog.SettingsSheet)
}
LaunchedEffect(state.isLoading) {
@ -282,7 +286,7 @@ object AnimeLibraryTab : Tab {
LaunchedEffect(Unit) {
launch { queryEvent.receiveAsFlow().collect(screenModel::search) }
launch { requestSettingsSheetEvent.receiveAsFlow().collectLatest { onClickFilter() } }
launch { requestSettingsSheetEvent.receiveAsFlow().collectLatest { screenModel.showSettingsDialog() } }
}
}
@ -292,8 +296,5 @@ object AnimeLibraryTab : Tab {
// For opening settings sheet in LibraryController
private val requestSettingsSheetEvent = Channel<Unit>()
private val openSettingsSheetEvent_ = Channel<Category>()
val openSettingsSheetEvent = openSettingsSheetEvent_.receiveAsFlow()
private suspend fun sendSettingsSheetIntent(category: Category) = openSettingsSheetEvent_.send(category)
suspend fun requestOpenSettingsSheet() = requestSettingsSheetEvent.send(Unit)
private suspend fun requestOpenSettingsSheet() = requestSettingsSheetEvent.send(Unit)
}

View file

@ -34,7 +34,7 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.chapter.getNextUnread
import eu.kanade.tachiyomi.util.removeCovers
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup
import eu.kanade.tachiyomi.widget.TriState
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
@ -58,8 +58,8 @@ import tachiyomi.domain.entries.manga.model.MangaUpdate
import tachiyomi.domain.items.chapter.interactor.GetChapterByMangaId
import tachiyomi.domain.items.chapter.model.Chapter
import tachiyomi.domain.library.manga.LibraryManga
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.sort
import tachiyomi.domain.library.manga.model.MangaLibrarySort
import tachiyomi.domain.library.manga.model.sort
import tachiyomi.domain.track.manga.interactor.GetTracksPerManga
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -150,8 +150,8 @@ class MangaLibraryScreenModel(
prefs.filterStarted or
prefs.filterBookmarked or
prefs.filterCompleted
) != TriStateGroup.State.DISABLED.value
val b = trackFilter.values.any { it != TriStateGroup.State.DISABLED.value }
) != TriState.DISABLED.value
val b = trackFilter.values.any { it != TriState.DISABLED.value }
a || b
}
.distinctUntilChanged()
@ -180,17 +180,17 @@ class MangaLibraryScreenModel(
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_NOT.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.ENABLED_IS.value) it.key else null }
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_NOT.value) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_IS.value) it.key else null }
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
val filterFnDownloaded: (MangaLibraryItem) -> Boolean = downloaded@{
if (!downloadedOnly && filterDownloaded == TriStateGroup.State.DISABLED.value) return@downloaded true
if (!downloadedOnly && filterDownloaded == TriState.DISABLED.value) return@downloaded true
val isDownloaded = it.libraryManga.manga.isLocal() ||
it.downloadCount > 0 ||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.ENABLED_IS.value) {
return@downloaded if (downloadedOnly || filterDownloaded == TriState.ENABLED_IS.value) {
isDownloaded
} else {
!isDownloaded
@ -198,10 +198,10 @@ class MangaLibraryScreenModel(
}
val filterFnUnread: (MangaLibraryItem) -> Boolean = unread@{
if (filterUnread == TriStateGroup.State.DISABLED.value) return@unread true
if (filterUnread == TriState.DISABLED.value) return@unread true
val isUnread = it.libraryManga.unreadCount > 0
return@unread if (filterUnread == TriStateGroup.State.ENABLED_IS.value) {
return@unread if (filterUnread == TriState.ENABLED_IS.value) {
isUnread
} else {
!isUnread
@ -209,10 +209,10 @@ class MangaLibraryScreenModel(
}
val filterFnStarted: (MangaLibraryItem) -> Boolean = started@{
if (filterStarted == TriStateGroup.State.DISABLED.value) return@started true
if (filterStarted == TriState.DISABLED.value) return@started true
val hasStarted = it.libraryManga.hasStarted
return@started if (filterStarted == TriStateGroup.State.ENABLED_IS.value) {
return@started if (filterStarted == TriState.ENABLED_IS.value) {
hasStarted
} else {
!hasStarted
@ -220,10 +220,10 @@ class MangaLibraryScreenModel(
}
val filterFnBookmarked: (MangaLibraryItem) -> Boolean = bookmarked@{
if (filterBookmarked == TriStateGroup.State.DISABLED.value) return@bookmarked true
if (filterBookmarked == TriState.DISABLED.value) return@bookmarked true
val hasBookmarks = it.libraryManga.hasBookmarks
return@bookmarked if (filterBookmarked == TriStateGroup.State.ENABLED_IS.value) {
return@bookmarked if (filterBookmarked == TriState.ENABLED_IS.value) {
hasBookmarks
} else {
!hasBookmarks
@ -231,10 +231,10 @@ class MangaLibraryScreenModel(
}
val filterFnCompleted: (MangaLibraryItem) -> Boolean = completed@{
if (filterCompleted == TriStateGroup.State.DISABLED.value) return@completed true
if (filterCompleted == TriState.DISABLED.value) return@completed true
val isCompleted = it.libraryManga.manga.status.toInt() == SManga.COMPLETED
return@completed if (filterCompleted == TriStateGroup.State.ENABLED_IS.value) {
return@completed if (filterCompleted == TriState.ENABLED_IS.value) {
isCompleted
} else {
!isCompleted
@ -290,32 +290,32 @@ class MangaLibraryScreenModel(
val sortFn: (MangaLibraryItem, MangaLibraryItem) -> Int = { i1, i2 ->
val sort = keys.find { it.id == i1.libraryManga.category }!!.sort
when (sort.type) {
LibrarySort.Type.Alphabetical -> {
MangaLibrarySort.Type.Alphabetical -> {
sortAlphabetically(i1, i2)
}
LibrarySort.Type.LastRead -> {
MangaLibrarySort.Type.LastRead -> {
i1.libraryManga.lastRead.compareTo(i2.libraryManga.lastRead)
}
LibrarySort.Type.LastUpdate -> {
MangaLibrarySort.Type.LastUpdate -> {
i1.libraryManga.manga.lastUpdate.compareTo(i2.libraryManga.manga.lastUpdate)
}
LibrarySort.Type.UnreadCount -> when {
MangaLibrarySort.Type.UnreadCount -> when {
// Ensure unread content comes first
i1.libraryManga.unreadCount == i2.libraryManga.unreadCount -> 0
i1.libraryManga.unreadCount == 0L -> if (sort.isAscending) 1 else -1
i2.libraryManga.unreadCount == 0L -> if (sort.isAscending) -1 else 1
else -> i1.libraryManga.unreadCount.compareTo(i2.libraryManga.unreadCount)
}
LibrarySort.Type.TotalChapters -> {
MangaLibrarySort.Type.TotalChapters -> {
i1.libraryManga.totalChapters.compareTo(i2.libraryManga.totalChapters)
}
LibrarySort.Type.LatestChapter -> {
MangaLibrarySort.Type.LatestChapter -> {
i1.libraryManga.latestUpload.compareTo(i2.libraryManga.latestUpload)
}
LibrarySort.Type.ChapterFetchDate -> {
MangaLibrarySort.Type.ChapterFetchDate -> {
i1.libraryManga.chapterFetchedAt.compareTo(i2.libraryManga.chapterFetchedAt)
}
LibrarySort.Type.DateAdded -> {
MangaLibrarySort.Type.DateAdded -> {
i1.libraryManga.manga.dateAdded.compareTo(i2.libraryManga.manga.dateAdded)
}
}
@ -573,6 +573,10 @@ class MangaLibraryScreenModel(
}
}
fun showSettingsDialog() {
mutableState.update { it.copy(dialog = Dialog.SettingsSheet) }
}
fun clearSelection() {
mutableState.update { it.copy(selection = emptyList()) }
}
@ -691,6 +695,7 @@ class MangaLibraryScreenModel(
}
sealed class Dialog {
object SettingsSheet : Dialog()
data class ChangeCategory(val manga: List<Manga>, val initialSelection: List<CheckboxState<Category>>) : Dialog()
data class DeleteManga(val manga: List<Manga>) : Dialog()
}

View file

@ -0,0 +1,84 @@
package eu.kanade.tachiyomi.ui.library.manga
import androidx.compose.runtime.Immutable
import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.coroutineScope
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.manga.interactor.SetDisplayModeForMangaCategory
import eu.kanade.domain.category.manga.interactor.SetSortModeForMangaCategory
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.util.preference.toggle
import eu.kanade.tachiyomi.widget.TriState
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.getAndSet
import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.manga.interactor.GetMangaCategories
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.manga.model.MangaLibrarySort
import tachiyomi.domain.library.model.LibraryDisplayMode
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class MangaLibrarySettingsScreenModel(
val preferences: BasePreferences = Injekt.get(),
val libraryPreferences: LibraryPreferences = Injekt.get(),
private val getCategories: GetMangaCategories = Injekt.get(),
private val setDisplayModeForCategory: SetDisplayModeForMangaCategory = Injekt.get(),
private val setSortModeForCategory: SetSortModeForMangaCategory = Injekt.get(),
trackManager: TrackManager = Injekt.get(),
) : StateScreenModel<MangaLibrarySettingsScreenModel.State>(State()) {
val trackServices = trackManager.services.filter { service -> service.isLogged }
init {
coroutineScope.launchIO {
getCategories.subscribe()
.collectLatest {
mutableState.update { state ->
state.copy(
categories = it,
)
}
}
}
}
fun togglePreference(preference: (LibraryPreferences) -> Preference<Boolean>) {
preference(libraryPreferences).toggle()
}
fun toggleFilter(preference: (LibraryPreferences) -> Preference<Int>) {
preference(libraryPreferences).getAndSet {
when (it) {
TriState.DISABLED.value -> TriState.ENABLED_IS.value
TriState.ENABLED_IS.value -> TriState.ENABLED_NOT.value
TriState.ENABLED_NOT.value -> TriState.DISABLED.value
else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
}
}
}
fun toggleTracker(id: Int) {
toggleFilter { libraryPreferences.filterTrackedManga(id) }
}
fun setDisplayMode(category: Category, mode: LibraryDisplayMode) {
coroutineScope.launchIO {
setDisplayModeForCategory.await(category, mode)
}
}
fun setSort(category: Category, mode: MangaLibrarySort.Type, direction: MangaLibrarySort.Direction) {
coroutineScope.launchIO {
setSortModeForCategory.await(category, mode, direction)
}
}
@Immutable
data class State(
val categories: List<Category> = emptyList(),
)
}

View file

@ -1,475 +0,0 @@
package eu.kanade.tachiyomi.ui.library.manga
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.View
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.manga.interactor.SetDisplayModeForMangaCategory
import eu.kanade.domain.category.manga.interactor.SetSortModeForMangaCategory
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.MangaTrackService
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
import eu.kanade.tachiyomi.widget.sheet.TabbedBottomSheetDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.display
import tachiyomi.domain.library.model.sort
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class MangaLibrarySettingsSheet(
activity: Activity,
private val trackManager: TrackManager = Injekt.get(),
private val setDisplayModeForCategory: SetDisplayModeForMangaCategory = Injekt.get(),
private val setSortModeForCategory: SetSortModeForMangaCategory = Injekt.get(),
) : TabbedBottomSheetDialog(activity) {
val filters: Filter
private val sort: Sort
private val display: Display
val sheetScope = CoroutineScope(Job() + Dispatchers.IO)
init {
filters = Filter(activity)
sort = Sort(activity)
display = Display(activity)
}
/**
* adjusts selected button to match real state.
* @param currentCategory ID of currently shown category
*/
fun show(currentCategory: Category) {
filters.adjustFilterSelection()
sort.currentCategory = currentCategory
sort.adjustDisplaySelection()
display.currentCategory = currentCategory
display.adjustDisplaySelection()
super.show()
}
override fun getTabViews(): List<View> = listOf(
filters,
sort,
display,
)
override fun getTabTitles(): List<Int> = listOf(
R.string.action_filter,
R.string.action_sort,
R.string.action_display,
)
/**
* Filters group (unread, downloaded, ...).
*/
inner class Filter @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val filterGroup = FilterGroup()
init {
setGroups(listOf(filterGroup))
}
// Refreshes Filter Setting selections
fun adjustFilterSelection() {
filterGroup.initModels()
filterGroup.items.forEach { adapter.notifyItemChanged(it) }
}
/**
* Returns true if there's at least one filter from [FilterGroup] active.
*/
fun hasActiveFilters(): Boolean {
return filterGroup.items.filterIsInstance<Item.TriStateGroup>().any { it.state != State.DISABLED.value }
}
inner class FilterGroup : Group {
private val downloaded = Item.TriStateGroup(R.string.label_downloaded, this)
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
private val started = Item.TriStateGroup(R.string.label_started, this)
private val bookmarked = Item.TriStateGroup(R.string.action_filter_bookmarked, this)
private val completed = Item.TriStateGroup(R.string.completed, this)
private val trackFilters: Map<Long, Item.TriStateGroup>
override val header = null
override val items: List<Item>
override val footer = null
init {
trackManager.services.filter { service -> service.isLogged && service is MangaTrackService }
.also { services ->
val size = services.size
trackFilters = services.associate { service ->
Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this))
}
val list: MutableList<Item> = mutableListOf(downloaded, unread, started, bookmarked, completed)
if (size > 1) list.add(Item.Header(R.string.action_filter_tracked))
list.addAll(trackFilters.values)
items = list
}
}
private fun getServiceResId(service: TrackService, size: Int): Int {
return if (size > 1) service.nameRes() else R.string.action_filter_tracked
}
override fun initModels() {
if (preferences.downloadedOnly().get()) {
downloaded.state = State.ENABLED_IS.value
downloaded.enabled = false
} else {
downloaded.state = libraryPreferences.filterDownloadedManga().get()
downloaded.enabled = true
}
unread.state = libraryPreferences.filterUnread().get()
started.state = libraryPreferences.filterStartedManga().get()
bookmarked.state = libraryPreferences.filterBookmarkedManga().get()
completed.state = libraryPreferences.filterCompletedManga().get()
trackFilters.forEach { trackFilter ->
trackFilter.value.state = libraryPreferences.filterTrackedManga(trackFilter.key.toInt()).get()
}
}
override fun onItemClicked(item: Item) {
item as Item.TriStateGroup
val newState = when (item.state) {
State.DISABLED.value -> State.ENABLED_IS.value
State.ENABLED_IS.value -> State.ENABLED_NOT.value
State.ENABLED_NOT.value -> State.DISABLED.value
else -> throw Exception("Unknown State")
}
item.state = newState
when (item) {
downloaded -> libraryPreferences.filterDownloadedManga().set(newState)
unread -> libraryPreferences.filterUnread().set(newState)
started -> libraryPreferences.filterStartedManga().set(newState)
bookmarked -> libraryPreferences.filterBookmarkedManga().set(newState)
completed -> libraryPreferences.filterCompletedManga().set(newState)
else -> {
trackFilters.forEach { trackFilter ->
if (trackFilter.value == item) {
libraryPreferences.filterTrackedManga(trackFilter.key.toInt()).set(newState)
}
}
}
}
adapter.notifyItemChanged(item)
}
}
}
/**
* Sorting group (alphabetically, by last read, ...) and ascending or descending.
*/
inner class Sort @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val sort = SortGroup()
init {
setGroups(listOf(sort))
}
// Refreshes Display Setting selections
fun adjustDisplaySelection() {
sort.initModels()
sort.items.forEach { adapter.notifyItemChanged(it) }
}
inner class SortGroup : Group {
private val alphabetically = Item.MultiSort(R.string.action_sort_alpha, this)
private val total = Item.MultiSort(R.string.action_sort_total, this)
private val lastRead = Item.MultiSort(R.string.action_sort_last_read, this)
private val lastChecked = Item.MultiSort(R.string.action_sort_last_manga_update, this)
private val unread = Item.MultiSort(R.string.action_sort_unread_count, this)
private val latestChapter = Item.MultiSort(R.string.action_sort_latest_chapter, this)
private val chapterFetchDate = Item.MultiSort(R.string.action_sort_chapter_fetch_date, this)
private val dateAdded = Item.MultiSort(R.string.action_sort_date_added, this)
override val header = null
override val items =
listOf(alphabetically, lastRead, lastChecked, unread, total, latestChapter, chapterFetchDate, dateAdded)
override val footer = null
override fun initModels() {
val sort = currentCategory.sort
val order = if (sort.isAscending) Item.MultiSort.SORT_ASC else Item.MultiSort.SORT_DESC
alphabetically.state =
if (sort.type == LibrarySort.Type.Alphabetical) order else Item.MultiSort.SORT_NONE
lastRead.state =
if (sort.type == LibrarySort.Type.LastRead) order else Item.MultiSort.SORT_NONE
lastChecked.state =
if (sort.type == LibrarySort.Type.LastUpdate) order else Item.MultiSort.SORT_NONE
unread.state =
if (sort.type == LibrarySort.Type.UnreadCount) order else Item.MultiSort.SORT_NONE
total.state =
if (sort.type == LibrarySort.Type.TotalChapters) order else Item.MultiSort.SORT_NONE
latestChapter.state =
if (sort.type == LibrarySort.Type.LatestChapter) order else Item.MultiSort.SORT_NONE
chapterFetchDate.state =
if (sort.type == LibrarySort.Type.ChapterFetchDate) order else Item.MultiSort.SORT_NONE
dateAdded.state =
if (sort.type == LibrarySort.Type.DateAdded) order else Item.MultiSort.SORT_NONE
}
override fun onItemClicked(item: Item) {
item as Item.MultiStateGroup
val prevState = item.state
item.group.items.forEach {
(it as Item.MultiStateGroup).state =
Item.MultiSort.SORT_NONE
}
item.state = when (prevState) {
Item.MultiSort.SORT_NONE -> Item.MultiSort.SORT_ASC
Item.MultiSort.SORT_ASC -> Item.MultiSort.SORT_DESC
Item.MultiSort.SORT_DESC -> Item.MultiSort.SORT_ASC
else -> throw Exception("Unknown state")
}
setSortPreference(item)
item.group.items.forEach { adapter.notifyItemChanged(it) }
}
private fun setSortPreference(item: Item.MultiStateGroup) {
val mode = when (item) {
alphabetically -> LibrarySort.Type.Alphabetical
lastRead -> LibrarySort.Type.LastRead
lastChecked -> LibrarySort.Type.LastUpdate
unread -> LibrarySort.Type.UnreadCount
total -> LibrarySort.Type.TotalChapters
latestChapter -> LibrarySort.Type.LatestChapter
chapterFetchDate -> LibrarySort.Type.ChapterFetchDate
dateAdded -> LibrarySort.Type.DateAdded
else -> throw NotImplementedError("Unknown display mode")
}
val direction = if (item.state == Item.MultiSort.SORT_ASC) {
LibrarySort.Direction.Ascending
} else {
LibrarySort.Direction.Descending
}
sheetScope.launchIO {
setSortModeForCategory.await(currentCategory!!, mode, direction)
}
}
}
}
/**
* Display group, to show the library as a list or a grid.
*/
inner class Display @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Settings(context, attrs) {
private val displayGroup: DisplayGroup
private val badgeGroup: BadgeGroup
private val tabsGroup: TabsGroup
private val otherGroup: OtherGroup
init {
displayGroup = DisplayGroup()
badgeGroup = BadgeGroup()
tabsGroup = TabsGroup()
otherGroup = OtherGroup()
setGroups(listOf(displayGroup, badgeGroup, tabsGroup, otherGroup))
}
// Refreshes Display Setting selections
fun adjustDisplaySelection() {
val mode = getDisplayModePreference()
displayGroup.setGroupSelections(mode)
displayGroup.items.forEach { adapter.notifyItemChanged(it) }
}
// Gets user preference of currently selected display mode at current category
private fun getDisplayModePreference(): LibraryDisplayMode {
return currentCategory.display
}
inner class DisplayGroup : Group {
private val compactGrid = Item.Radio(R.string.action_display_grid, this)
private val comfortableGrid = Item.Radio(R.string.action_display_comfortable_grid, this)
private val coverOnlyGrid = Item.Radio(R.string.action_display_cover_only_grid, this)
private val list = Item.Radio(R.string.action_display_list, this)
override val header = Item.Header(R.string.action_display_mode)
override val items = listOf(compactGrid, comfortableGrid, coverOnlyGrid, list)
override val footer = null
override fun initModels() {
val mode = getDisplayModePreference()
setGroupSelections(mode)
}
override fun onItemClicked(item: Item) {
item as Item.Radio
if (item.checked) return
item.group.items.forEach { (it as Item.Radio).checked = false }
item.checked = true
setDisplayModePreference(item)
item.group.items.forEach { adapter.notifyItemChanged(it) }
}
// Sets display group selections based on given mode
fun setGroupSelections(mode: LibraryDisplayMode) {
compactGrid.checked = mode == LibraryDisplayMode.CompactGrid
comfortableGrid.checked = mode == LibraryDisplayMode.ComfortableGrid
coverOnlyGrid.checked = mode == LibraryDisplayMode.CoverOnlyGrid
list.checked = mode == LibraryDisplayMode.List
}
private fun setDisplayModePreference(item: Item) {
val flag = when (item) {
compactGrid -> LibraryDisplayMode.CompactGrid
comfortableGrid -> LibraryDisplayMode.ComfortableGrid
coverOnlyGrid -> LibraryDisplayMode.CoverOnlyGrid
list -> LibraryDisplayMode.List
else -> throw NotImplementedError("Unknown display mode")
}
sheetScope.launchIO {
setDisplayModeForCategory.await(currentCategory!!, flag)
}
}
}
inner class BadgeGroup : Group {
private val downloadBadge = Item.CheckboxGroup(R.string.action_display_download_badge, this)
private val localBadge = Item.CheckboxGroup(R.string.action_display_local_badge_manga, this)
private val languageBadge = Item.CheckboxGroup(R.string.action_display_language_badge, this)
override val header = Item.Header(R.string.badges_header)
override val items = listOf(downloadBadge, localBadge, languageBadge)
override val footer = null
override fun initModels() {
downloadBadge.checked = libraryPreferences.downloadBadge().get()
localBadge.checked = libraryPreferences.localBadge().get()
languageBadge.checked = libraryPreferences.languageBadge().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
downloadBadge -> libraryPreferences.downloadBadge().set((item.checked))
localBadge -> libraryPreferences.localBadge().set((item.checked))
languageBadge -> libraryPreferences.languageBadge().set((item.checked))
else -> {}
}
adapter.notifyItemChanged(item)
}
}
inner class TabsGroup : Group {
private val showTabs = Item.CheckboxGroup(R.string.action_display_show_tabs, this)
private val showNumberOfItems = Item.CheckboxGroup(R.string.action_display_show_number_of_items, this)
override val header = Item.Header(R.string.tabs_header)
override val items = listOf(showTabs, showNumberOfItems)
override val footer = null
override fun initModels() {
showTabs.checked = libraryPreferences.categoryTabs().get()
showNumberOfItems.checked = libraryPreferences.categoryNumberOfItems().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
showTabs -> libraryPreferences.categoryTabs().set(item.checked)
showNumberOfItems -> libraryPreferences.categoryNumberOfItems().set(item.checked)
else -> {}
}
adapter.notifyItemChanged(item)
}
}
inner class OtherGroup : Group {
private val showContinueReadingButton = Item.CheckboxGroup(R.string.action_display_show_continue_reading_button, this)
override val header = Item.Header(R.string.other_header)
override val items = listOf(showContinueReadingButton)
override val footer = null
override fun initModels() {
showContinueReadingButton.checked = libraryPreferences.showContinueViewingButton().get()
}
override fun onItemClicked(item: Item) {
item as Item.CheckboxGroup
item.checked = !item.checked
when (item) {
showContinueReadingButton -> libraryPreferences.showContinueViewingButton().set(item.checked)
else -> {}
}
adapter.notifyItemChanged(item)
}
}
}
open inner class Settings(context: Context, attrs: AttributeSet?) :
ExtendedNavigationView(context, attrs) {
val preferences: BasePreferences by injectLazy()
val libraryPreferences: LibraryPreferences by injectLazy()
lateinit var adapter: Adapter
/**
* Click listener to notify the parent fragment when an item from a group is clicked.
*/
var onGroupClicked: (Group) -> Unit = {}
var currentCategory: Category? = null
fun setGroups(groups: List<Group>) {
adapter = Adapter(groups.map { it.createItems() }.flatten())
recycler.adapter = adapter
groups.forEach { it.initModels() }
addView(recycler)
}
/**
* Adapter of the recycler view.
*/
inner class Adapter(items: List<Item>) : ExtendedNavigationView.Adapter(items) {
override fun onItemClicked(item: Item) {
if (item is GroupedItem) {
item.group.onItemClicked(item)
onGroupClicked(item.group)
}
}
}
}
}

View file

@ -39,6 +39,7 @@ import eu.kanade.presentation.entries.LibraryBottomActionMenu
import eu.kanade.presentation.library.DeleteLibraryEntryDialog
import eu.kanade.presentation.library.LibraryToolbar
import eu.kanade.presentation.library.manga.MangaLibraryContent
import eu.kanade.presentation.library.manga.MangaLibrarySettingsDialog
import eu.kanade.presentation.util.Tab
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.library.manga.MangaLibraryUpdateJob
@ -98,6 +99,7 @@ object MangaLibraryTab : Tab {
val haptic = LocalHapticFeedback.current
val screenModel = rememberScreenModel { MangaLibraryScreenModel() }
val settingsScreenModel = rememberScreenModel { MangaLibrarySettingsScreenModel() }
val state by screenModel.state.collectAsState()
val snackbarHostState = remember { SnackbarHostState() }
@ -110,9 +112,6 @@ object MangaLibraryTab : Tab {
}
started
}
val onClickFilter: () -> Unit = {
scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategoryIndex]) }
}
val navigateUp: (() -> Unit)? = if (fromMore) navigator::pop else null
@ -133,7 +132,7 @@ object MangaLibraryTab : Tab {
onClickUnselectAll = screenModel::clearSelection,
onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) },
onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) },
onClickFilter = onClickFilter,
onClickFilter = { screenModel.showSettingsDialog() },
onClickRefresh = { onClickRefresh(null) },
onClickOpenRandomEntry = {
scope.launch {
@ -222,6 +221,11 @@ object MangaLibraryTab : Tab {
val onDismissRequest = screenModel::closeDialog
when (val dialog = state.dialog) {
is MangaLibraryScreenModel.Dialog.SettingsSheet -> MangaLibrarySettingsDialog(
onDismissRequest = onDismissRequest,
screenModel = settingsScreenModel,
activeCategoryIndex = screenModel.activeCategoryIndex,
)
is MangaLibraryScreenModel.Dialog.ChangeCategory -> {
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,
@ -257,8 +261,8 @@ object MangaLibraryTab : Tab {
}
}
LaunchedEffect(state.selectionMode) {
HomeScreen.showBottomNav(!state.selectionMode)
LaunchedEffect(state.selectionMode, state.dialog) {
HomeScreen.showBottomNav(!state.selectionMode && state.dialog !is MangaLibraryScreenModel.Dialog.SettingsSheet)
}
LaunchedEffect(state.isLoading) {
@ -269,7 +273,7 @@ object MangaLibraryTab : Tab {
LaunchedEffect(Unit) {
launch { queryEvent.receiveAsFlow().collect(screenModel::search) }
launch { requestSettingsSheetEvent.receiveAsFlow().collectLatest { onClickFilter() } }
launch { requestSettingsSheetEvent.receiveAsFlow().collectLatest { screenModel.showSettingsDialog() } }
}
}
@ -279,8 +283,5 @@ object MangaLibraryTab : Tab {
// For opening settings sheet in LibraryController
private val requestSettingsSheetEvent = Channel<Unit>()
private val openSettingsSheetEvent_ = Channel<Category>()
val openSettingsSheetEvent = openSettingsSheetEvent_.receiveAsFlow()
private suspend fun sendSettingsSheetIntent(category: Category) = openSettingsSheetEvent_.send(category)
suspend fun requestOpenSettingsSheet() = requestSettingsSheetEvent.send(Unit)
private suspend fun requestOpenSettingsSheet() = requestSettingsSheetEvent.send(Unit)
}

View file

@ -86,10 +86,6 @@ import eu.kanade.tachiyomi.ui.browse.manga.source.globalsearch.GlobalMangaSearch
import eu.kanade.tachiyomi.ui.entries.anime.AnimeScreen
import eu.kanade.tachiyomi.ui.entries.manga.MangaScreen
import eu.kanade.tachiyomi.ui.home.HomeScreen
import eu.kanade.tachiyomi.ui.library.anime.AnimeLibrarySettingsSheet
import eu.kanade.tachiyomi.ui.library.anime.AnimeLibraryTab
import eu.kanade.tachiyomi.ui.library.manga.MangaLibrarySettingsSheet
import eu.kanade.tachiyomi.ui.library.manga.MangaLibraryTab
import eu.kanade.tachiyomi.ui.more.NewUpdateScreen
import eu.kanade.tachiyomi.ui.player.ExternalIntents
import eu.kanade.tachiyomi.util.system.dpToPx
@ -111,7 +107,6 @@ import kotlinx.coroutines.launch
import logcat.LogPriority
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.category.model.Category
import tachiyomi.presentation.core.components.material.Scaffold
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -137,12 +132,6 @@ class MainActivity : BaseActivity() {
// To be checked by splash screen. If true then splash screen will be removed.
var ready = false
/**
* Sheet containing filter/sort/display items.
*/
private var animeSettingsSheet: AnimeLibrarySettingsSheet? = null
private var mangaSettingsSheet: MangaLibrarySettingsSheet? = null
private var navigator: Navigator? = null
override fun onCreate(savedInstanceState: Bundle?) {
@ -178,16 +167,6 @@ class MainActivity : BaseActivity() {
// Draw edge-to-edge
WindowCompat.setDecorFitsSystemWindows(window, false)
animeSettingsSheet = AnimeLibrarySettingsSheet(this)
AnimeLibraryTab.openSettingsSheetEvent
.onEach(::showAnimeSettingsSheet)
.launchIn(lifecycleScope)
mangaSettingsSheet = MangaLibrarySettingsSheet(this)
MangaLibraryTab.openSettingsSheetEvent
.onEach(::showMangaSettingsSheet)
.launchIn(lifecycleScope)
setComposeContent {
val incognito by preferences.incognitoMode().collectAsState()
val downloadOnly by preferences.downloadedOnly().collectAsState()
@ -327,26 +306,6 @@ class MainActivity : BaseActivity() {
}
}
private fun showAnimeSettingsSheet(category: Category? = null) {
if (category != null) {
animeSettingsSheet?.show(category)
} else {
lifecycleScope.launch {
AnimeLibraryTab.requestOpenSettingsSheet()
}
}
}
private fun showMangaSettingsSheet(category: Category? = null) {
if (category != null) {
mangaSettingsSheet?.show(category)
} else {
lifecycleScope.launch {
MangaLibraryTab.requestOpenSettingsSheet()
}
}
}
@Composable
private fun ConfirmExit() {
val scope = rememberCoroutineScope()
@ -526,14 +485,6 @@ class MainActivity : BaseActivity() {
return true
}
override fun onDestroy() {
animeSettingsSheet?.sheetScope?.cancel()
mangaSettingsSheet?.sheetScope?.cancel()
animeSettingsSheet = null
mangaSettingsSheet = null
super.onDestroy()
}
override fun onBackPressed() {
if (navigator?.size == 1 &&
!onBackPressedDispatcher.hasEnabledCallbacks() &&

View file

@ -1,270 +0,0 @@
package eu.kanade.tachiyomi.widget
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View.OnClickListener
import android.view.ViewGroup
import androidx.annotation.AttrRes
import androidx.annotation.CallSuper
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.recyclerview.widget.RecyclerView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.getResourceColor
/**
* An alternative implementation of [com.google.android.material.navigation.NavigationView], without menu
* inflation and allowing customizable items (multiple selections, custom views, etc).
*/
open class ExtendedNavigationView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : SimpleNavigationView(context, attrs, defStyleAttr) {
/**
* Every item of the nav view. Generic items must belong to this list, custom items could be
* implemented by an abstract class. If more customization is needed in the future, this can be
* changed to an interface instead of sealed class.
*/
sealed class Item {
/**
* A view separator.
*/
class Separator(val paddingTop: Int = 0, val paddingBottom: Int = 0) : Item()
/**
* A header with a title.
*/
class Header(val resTitle: Int) : Item()
/**
* A checkbox.
*/
open class Checkbox(val resTitle: Int, var checked: Boolean = false, var enabled: Boolean = true) : Item()
/**
* A checkbox belonging to a group. The group must handle selections and restrictions.
*/
class CheckboxGroup(resTitle: Int, override val group: Group, checked: Boolean = false, enabled: Boolean = true) :
Checkbox(resTitle, checked, enabled), GroupedItem
/**
* A radio belonging to a group (a sole radio makes no sense). The group must handle
* selections and restrictions.
*/
class Radio(val resTitle: Int, override val group: Group, var checked: Boolean = false, var enabled: Boolean = true) :
Item(), GroupedItem
/**
* An item with which needs more than two states (selected/deselected).
*/
abstract class MultiState(val resTitle: Int, var state: Int = 0, var enabled: Boolean = true, var isVisible: Boolean = true) : Item() {
/**
* Returns the drawable associated to every possible each state.
*/
abstract fun getStateDrawable(context: Context): Drawable?
/**
* Creates a vector tinted with the accent color.
*
* @param context any context.
* @param resId the vector resource to load and tint
*/
fun tintVector(context: Context, resId: Int, @AttrRes colorAttrRes: Int = R.attr.colorPrimary): Drawable {
return AppCompatResources.getDrawable(context, resId)!!.apply {
setTint(context.getResourceColor(if (enabled) colorAttrRes else R.attr.colorControlNormal))
}
}
}
/**
* An item with which needs more than two states (selected/deselected) belonging to a group.
* The group must handle selections and restrictions.
*/
abstract class MultiStateGroup(resTitle: Int, override val group: Group, state: Int = 0, enabled: Boolean = true) :
MultiState(resTitle, state, enabled), GroupedItem
/**
* A multistate item for sorting lists (unselected, ascending, descending).
*/
class MultiSort(resId: Int, group: Group) : MultiStateGroup(resId, group) {
companion object {
const val SORT_NONE = 0
const val SORT_ASC = 1
const val SORT_DESC = 2
}
override fun getStateDrawable(context: Context): Drawable? {
return when (state) {
SORT_ASC -> tintVector(context, R.drawable.ic_arrow_up_white_32dp)
SORT_DESC -> tintVector(context, R.drawable.ic_arrow_down_white_32dp)
SORT_NONE -> AppCompatResources.getDrawable(context, R.drawable.empty_drawable_32dp)
else -> null
}
}
}
/**
* A checkbox with 3 states (unselected, checked, explicitly unchecked).
*/
class TriStateGroup(resId: Int, group: Group) : MultiStateGroup(resId, group) {
enum class State(val value: Int) {
DISABLED(0),
ENABLED_IS(1),
ENABLED_NOT(2),
}
override fun getStateDrawable(context: Context): Drawable? {
return when (state) {
State.DISABLED.value -> tintVector(context, R.drawable.ic_check_box_outline_blank_24dp, R.attr.colorControlNormal)
State.ENABLED_IS.value -> tintVector(context, R.drawable.ic_check_box_24dp)
State.ENABLED_NOT.value -> tintVector(context, R.drawable.ic_check_box_x_24dp)
else -> throw Exception("Unknown state")
}
}
}
}
/**
* Interface for an item belonging to a group.
*/
interface GroupedItem {
val group: Group
}
/**
* A group containing a list of items.
*/
interface Group {
/**
* An optional header for the group, typically a [Item.Header].
*/
val header: Item?
/**
* An optional footer for the group, typically a [Item.Separator].
*/
val footer: Item?
/**
* The items of the group, excluding header and footer.
*/
val items: List<Item>
/**
* Creates all the elements of this group. Implementations can override this method for more
* customization.
*/
fun createItems() = (mutableListOf<Item>() + header + items + footer).filterNotNull()
/**
* Called after creating the list of items. Implementations should load the current values
* into the models.
*/
fun initModels()
/**
* Called when an item of this group is clicked. The group is responsible for all the
* selections of its items.
*/
fun onItemClicked(item: Item)
}
/**
* Base adapter for the navigation view. It knows how to create and render every subclass of
* [Item].
*/
abstract inner class Adapter(private val items: List<Item>) : RecyclerView.Adapter<Holder>() {
private val onClick = OnClickListener {
val pos = recycler.getChildAdapterPosition(it)
val item = items[pos]
onItemClicked(item)
}
fun notifyItemChanged(item: Item) {
val pos = items.indexOf(item)
if (pos != -1) notifyItemChanged(pos)
}
override fun getItemCount(): Int {
return items.size
}
@CallSuper
override fun getItemViewType(position: Int): Int {
return when (items[position]) {
is Item.Header -> VIEW_TYPE_HEADER
is Item.Separator -> VIEW_TYPE_SEPARATOR
is Item.Radio -> VIEW_TYPE_RADIO
is Item.Checkbox -> VIEW_TYPE_CHECKBOX
is Item.MultiState -> VIEW_TYPE_MULTISTATE
}
}
@CallSuper
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
return when (viewType) {
VIEW_TYPE_HEADER -> HeaderHolder(parent)
VIEW_TYPE_SEPARATOR -> SeparatorHolder(parent)
VIEW_TYPE_RADIO -> RadioHolder(parent, onClick)
VIEW_TYPE_CHECKBOX -> CheckboxHolder(parent, onClick)
VIEW_TYPE_MULTISTATE -> MultiStateHolder(parent, onClick)
else -> throw Exception("Unknown view type")
}
}
@CallSuper
override fun onBindViewHolder(holder: Holder, position: Int) {
when (holder) {
is HeaderHolder -> {
val item = items[position] as Item.Header
holder.title.setText(item.resTitle)
}
is SeparatorHolder -> {
val view = holder.itemView
val item = items[position] as Item.Separator
view.updatePadding(top = item.paddingTop, bottom = item.paddingBottom)
}
is RadioHolder -> {
val item = items[position] as Item.Radio
holder.radio.setText(item.resTitle)
holder.radio.isChecked = item.checked
holder.itemView.isClickable = item.enabled
holder.radio.isEnabled = item.enabled
}
is CheckboxHolder -> {
val item = items[position] as Item.CheckboxGroup
holder.check.setText(item.resTitle)
holder.check.isChecked = item.checked
holder.itemView.isClickable = item.enabled
holder.check.isEnabled = item.enabled
}
is MultiStateHolder -> {
val item = items[position] as Item.MultiStateGroup
val drawable = item.getStateDrawable(context)
holder.text.setText(item.resTitle)
holder.text.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
holder.itemView.isClickable = item.enabled
holder.text.isEnabled = item.enabled
// Mimics checkbox/radio button
holder.text.alpha = if (item.enabled) 1f else 0.4f
holder.itemView.isVisible = item.isVisible
}
}
}
abstract fun onItemClicked(item: Item)
}
}

View file

@ -0,0 +1,19 @@
package eu.kanade.tachiyomi.widget
import tachiyomi.domain.entries.TriStateFilter
// TODO: replace this with TriStateFilter entirely
enum class TriState(val value: Int) {
DISABLED(0),
ENABLED_IS(1),
ENABLED_NOT(2),
}
fun Int.toTriStateFilter(): TriStateFilter {
return when (this) {
TriState.DISABLED.value -> TriStateFilter.DISABLED
TriState.ENABLED_IS.value -> TriStateFilter.ENABLED_IS
TriState.ENABLED_NOT.value -> TriStateFilter.ENABLED_NOT
else -> throw IllegalStateException("Unknown TriStateGroup state: $this")
}
}

View file

@ -0,0 +1,131 @@
package tachiyomi.domain.library.anime.model
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.FlagWithMask
import tachiyomi.domain.library.model.plus
data class AnimeLibrarySort(
val type: Type,
val direction: Direction,
) : FlagWithMask {
override val flag: Long
get() = type + direction
override val mask: Long
get() = type.mask or direction.mask
val isAscending: Boolean
get() = direction == Direction.Ascending
sealed class Type(
override val flag: Long,
) : FlagWithMask {
override val mask: Long = 0b00111100L
object Alphabetical : Type(0b00000000)
object LastSeen : Type(0b00000100)
object LastUpdate : Type(0b00001000)
object UnseenCount : Type(0b00001100)
object TotalEpisodes : Type(0b00010000)
object LatestEpisode : Type(0b00010100)
object EpisodeFetchDate : Type(0b00011000)
object DateAdded : Type(0b00011100)
companion object {
fun valueOf(flag: Long): Type {
return types.find { type -> type.flag == flag and type.mask } ?: default.type
}
}
}
sealed class Direction(
override val flag: Long,
) : FlagWithMask {
override val mask: Long = 0b01000000L
object Ascending : Direction(0b01000000)
object Descending : Direction(0b00000000)
companion object {
fun valueOf(flag: Long): Direction {
return directions.find { direction -> direction.flag == flag and direction.mask } ?: default.direction
}
}
}
object Serializer {
fun deserialize(serialized: String): AnimeLibrarySort {
return Companion.deserialize(serialized)
}
fun serialize(value: AnimeLibrarySort): String {
return value.serialize()
}
}
companion object {
val types = setOf(
Type.Alphabetical,
Type.LastSeen,
Type.LastUpdate,
Type.UnseenCount,
Type.TotalEpisodes,
Type.LatestEpisode,
Type.EpisodeFetchDate,
Type.DateAdded,
)
val directions = setOf(Direction.Ascending, Direction.Descending)
val default = AnimeLibrarySort(Type.Alphabetical, Direction.Ascending)
fun valueOf(flag: Long?): AnimeLibrarySort {
if (flag == null) return default
return AnimeLibrarySort(
Type.valueOf(flag),
Direction.valueOf(flag),
)
}
fun deserialize(serialized: String): AnimeLibrarySort {
if (serialized.isEmpty()) return default
return try {
val values = serialized.split(",")
val type = when (values[0]) {
"ALPHABETICAL" -> Type.Alphabetical
"LAST_SEEN" -> Type.LastSeen
"LAST_ANIME_UPDATE" -> Type.LastUpdate
"UNSEEN_COUNT" -> Type.UnseenCount
"TOTAL_EPISODES" -> Type.TotalEpisodes
"LATEST_EPISODE" -> Type.LatestEpisode
"EPISODE_FETCH_DATE" -> Type.EpisodeFetchDate
"DATE_ADDED" -> Type.DateAdded
else -> Type.Alphabetical
}
val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending
AnimeLibrarySort(type, ascending)
} catch (e: Exception) {
default
}
}
}
fun serialize(): String {
val type = when (type) {
Type.Alphabetical -> "ALPHABETICAL"
Type.LastSeen -> "LAST_SEEN"
Type.LastUpdate -> "LAST_ANIME_UPDATE"
Type.UnseenCount -> "UNSEEN_COUNT"
Type.TotalEpisodes -> "TOTAL_EPISODES"
Type.LatestEpisode -> "LATEST_EPISODE"
Type.EpisodeFetchDate -> "EPISODE_FETCH_DATE"
Type.DateAdded -> "DATE_ADDED"
}
val direction = if (direction == Direction.Ascending) "ASCENDING" else "DESCENDING"
return "$type,$direction"
}
}
val Category?.sort: AnimeLibrarySort
get() = AnimeLibrarySort.valueOf(this?.flags)

View file

@ -1,8 +1,10 @@
package tachiyomi.domain.library.model
package tachiyomi.domain.library.manga.model
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.FlagWithMask
import tachiyomi.domain.library.model.plus
data class LibrarySort(
data class MangaLibrarySort(
val type: Type,
val direction: Direction,
) : FlagWithMask {
@ -55,11 +57,11 @@ data class LibrarySort(
}
object Serializer {
fun deserialize(serialized: String): LibrarySort {
fun deserialize(serialized: String): MangaLibrarySort {
return Companion.deserialize(serialized)
}
fun serialize(value: LibrarySort): String {
fun serialize(value: MangaLibrarySort): String {
return value.serialize()
}
}
@ -76,17 +78,17 @@ data class LibrarySort(
Type.DateAdded,
)
val directions = setOf(Direction.Ascending, Direction.Descending)
val default = LibrarySort(Type.Alphabetical, Direction.Ascending)
val default = MangaLibrarySort(Type.Alphabetical, Direction.Ascending)
fun valueOf(flag: Long?): LibrarySort {
fun valueOf(flag: Long?): MangaLibrarySort {
if (flag == null) return default
return LibrarySort(
return MangaLibrarySort(
Type.valueOf(flag),
Direction.valueOf(flag),
)
}
fun deserialize(serialized: String): LibrarySort {
fun deserialize(serialized: String): MangaLibrarySort {
if (serialized.isEmpty()) return default
return try {
val values = serialized.split(",")
@ -102,7 +104,7 @@ data class LibrarySort(
else -> Type.Alphabetical
}
val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending
LibrarySort(type, ascending)
MangaLibrarySort(type, ascending)
} catch (e: Exception) {
default
}
@ -125,5 +127,5 @@ data class LibrarySort(
}
}
val Category?.sort: LibrarySort
get() = LibrarySort.valueOf(this?.flags)
val Category?.sort: MangaLibrarySort
get() = MangaLibrarySort.valueOf(this?.flags)

View file

@ -3,14 +3,18 @@ package tachiyomi.domain.library.model
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test
import tachiyomi.domain.library.anime.model.AnimeLibrarySort
import tachiyomi.domain.library.manga.model.MangaLibrarySort
class LibraryFlagsTest {
@Test
fun `Check the amount of flags`() {
assertEquals(4, LibraryDisplayMode.values.size)
assertEquals(8, LibrarySort.types.size)
assertEquals(2, LibrarySort.directions.size)
assertEquals(8, MangaLibrarySort.types.size)
assertEquals(2, MangaLibrarySort.directions.size)
assertEquals(8, AnimeLibrarySort.types.size)
assertEquals(2, AnimeLibrarySort.directions.size)
}
@Test
@ -24,43 +28,60 @@ class LibraryFlagsTest {
@Test
fun `Test Flag plus operator (LibrarySort)`() {
val current = LibrarySort(LibrarySort.Type.LastRead, LibrarySort.Direction.Ascending)
val new = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
val flag = current + new
val mangacurrent = MangaLibrarySort(MangaLibrarySort.Type.LastRead, MangaLibrarySort.Direction.Ascending)
val animecurrent = AnimeLibrarySort(AnimeLibrarySort.Type.LastSeen, AnimeLibrarySort.Direction.Ascending)
val newmanga = MangaLibrarySort(MangaLibrarySort.Type.DateAdded, MangaLibrarySort.Direction.Ascending)
val newanime = AnimeLibrarySort(AnimeLibrarySort.Type.DateAdded, AnimeLibrarySort.Direction.Ascending)
val mangaflag = mangacurrent + newmanga
val animeflag = animecurrent + newanime
assertEquals(0b01011100, flag)
assertEquals(0b01011100, mangaflag)
assertEquals(0b01011100, animeflag)
}
@Test
fun `Test Flag plus operator`() {
val display = LibraryDisplayMode.CoverOnlyGrid
val sort = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
val flag = display + sort
val mangasort = MangaLibrarySort(MangaLibrarySort.Type.DateAdded, MangaLibrarySort.Direction.Ascending)
val animesort = AnimeLibrarySort(AnimeLibrarySort.Type.DateAdded, AnimeLibrarySort.Direction.Ascending)
val mangaflag = display + mangasort
val animeflag = display + animesort
assertEquals(0b01011111, flag)
assertEquals(0b01011111, mangaflag)
assertEquals(0b01011111, animeflag)
}
@Test
fun `Test Flag plus operator with old flag as base`() {
val currentDisplay = LibraryDisplayMode.List
val currentSort = LibrarySort(LibrarySort.Type.UnreadCount, LibrarySort.Direction.Descending)
val currentFlag = currentDisplay + currentSort
val currentmangaSort = MangaLibrarySort(MangaLibrarySort.Type.UnreadCount, MangaLibrarySort.Direction.Descending)
val currentmangaFlag = currentDisplay + currentmangaSort
val currentanimeSort = AnimeLibrarySort(AnimeLibrarySort.Type.UnseenCount, AnimeLibrarySort.Direction.Descending)
val currentanimeFlag = currentDisplay + currentanimeSort
val display = LibraryDisplayMode.CoverOnlyGrid
val sort = LibrarySort(LibrarySort.Type.DateAdded, LibrarySort.Direction.Ascending)
val flag = currentFlag + display + sort
val mangasort = MangaLibrarySort(MangaLibrarySort.Type.DateAdded, MangaLibrarySort.Direction.Ascending)
val mangaflag = currentmangaFlag + display + mangasort
val animesort = AnimeLibrarySort(AnimeLibrarySort.Type.DateAdded, AnimeLibrarySort.Direction.Ascending)
val animeflag = currentanimeFlag + display + animesort
assertEquals(0b00001110, currentFlag)
assertEquals(0b01011111, flag)
assertNotEquals(currentFlag, flag)
assertEquals(0b00001110, currentmangaFlag)
assertEquals(0b01011111, mangaflag)
assertNotEquals(currentmangaFlag, mangaflag)
assertEquals(0b00001110, currentanimeFlag)
assertEquals(0b01011111, animeflag)
assertNotEquals(currentanimeFlag, animeflag)
}
@Test
fun `Test default flags`() {
val sort = LibrarySort.default
val mangasort = MangaLibrarySort.default
val animesort = AnimeLibrarySort.default
val display = LibraryDisplayMode.default
val flag = display + sort.type + sort.direction
val mangaflag = display + mangasort.type + mangasort.direction
val animeflag = display + animesort.type + animesort.direction
assertEquals(0b01000000, flag)
assertEquals(0b01000000, mangaflag)
assertEquals(0b01000000, animeflag)
}
}

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

4
gradlew vendored
View file

@ -144,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac

View file

@ -38,6 +38,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.InternalCoroutinesApi
import tachiyomi.presentation.core.util.animateElevation
import androidx.compose.material3.ButtonDefaults as M3ButtonDefaults
@ -235,6 +236,7 @@ class ButtonElevation internal constructor(
return animateElevation(enabled = enabled, interactionSource = interactionSource)
}
@OptIn(InternalCoroutinesApi::class)
@Composable
private fun animateElevation(
enabled: Boolean,