Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows the user to hide categories. #1125

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/java/eu/kanade/domain/DomainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import tachiyomi.data.updates.manga.MangaUpdatesRepositoryImpl
import tachiyomi.domain.category.anime.interactor.CreateAnimeCategoryWithName
import tachiyomi.domain.category.anime.interactor.DeleteAnimeCategory
import tachiyomi.domain.category.anime.interactor.GetAnimeCategories
import tachiyomi.domain.category.anime.interactor.GetVisibleAnimeCategories
import tachiyomi.domain.category.anime.interactor.HideAnimeCategory
import tachiyomi.domain.category.anime.interactor.RenameAnimeCategory
import tachiyomi.domain.category.anime.interactor.ReorderAnimeCategory
import tachiyomi.domain.category.anime.interactor.ResetAnimeCategoryFlags
Expand All @@ -60,6 +62,8 @@ import tachiyomi.domain.category.anime.repository.AnimeCategoryRepository
import tachiyomi.domain.category.manga.interactor.CreateMangaCategoryWithName
import tachiyomi.domain.category.manga.interactor.DeleteMangaCategory
import tachiyomi.domain.category.manga.interactor.GetMangaCategories
import tachiyomi.domain.category.manga.interactor.GetVisibleMangaCategories
import tachiyomi.domain.category.manga.interactor.HideMangaCategory
import tachiyomi.domain.category.manga.interactor.RenameMangaCategory
import tachiyomi.domain.category.manga.interactor.ReorderMangaCategory
import tachiyomi.domain.category.manga.interactor.ResetMangaCategoryFlags
Expand Down Expand Up @@ -142,24 +146,28 @@ class DomainModule : InjektModule {
override fun InjektRegistrar.registerInjectables() {
addSingletonFactory<AnimeCategoryRepository> { AnimeCategoryRepositoryImpl(get()) }
addFactory { GetAnimeCategories(get()) }
addFactory { GetVisibleAnimeCategories(get()) }
addFactory { ResetAnimeCategoryFlags(get(), get()) }
addFactory { SetDisplayModeForAnimeCategory(get(), get()) }
addFactory { SetSortModeForAnimeCategory(get(), get()) }
addFactory { CreateAnimeCategoryWithName(get(), get()) }
addFactory { RenameAnimeCategory(get()) }
addFactory { ReorderAnimeCategory(get()) }
addFactory { UpdateAnimeCategory(get()) }
addFactory { HideAnimeCategory(get()) }
addFactory { DeleteAnimeCategory(get()) }

addSingletonFactory<MangaCategoryRepository> { MangaCategoryRepositoryImpl(get()) }
addFactory { GetMangaCategories(get()) }
addFactory { GetVisibleMangaCategories(get()) }
addFactory { ResetMangaCategoryFlags(get(), get()) }
addFactory { SetDisplayModeForMangaCategory(get(), get()) }
addFactory { SetSortModeForMangaCategory(get(), get()) }
addFactory { CreateMangaCategoryWithName(get(), get()) }
addFactory { RenameMangaCategory(get()) }
addFactory { ReorderMangaCategory(get()) }
addFactory { UpdateMangaCategory(get()) }
addFactory { HideMangaCategory(get()) }
addFactory { DeleteMangaCategory(get()) }

addSingletonFactory<AnimeRepository> { AnimeRepositoryImpl(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fun AnimeCategoryScreen(
contentPadding: PaddingValues,
onClickCreate: () -> Unit,
onClickRename: (Category) -> Unit,
onClickHide: (Category) -> Unit,
onClickDelete: (Category) -> Unit,
onClickMoveUp: (Category) -> Unit,
onClickMoveDown: (Category) -> Unit,
Expand All @@ -49,6 +50,7 @@ fun AnimeCategoryScreen(
lazyListState = lazyListState,
paddingValues = contentPadding + topSmallPaddingValues + PaddingValues(horizontal = MaterialTheme.padding.medium),
onClickRename = onClickRename,
onClickHide = onClickHide,
onClickDelete = onClickDelete,
onMoveUp = onClickMoveUp,
onMoveDown = onClickMoveDown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fun MangaCategoryScreen(
contentPadding: PaddingValues,
onClickCreate: () -> Unit,
onClickRename: (Category) -> Unit,
onClickHide: (Category) -> Unit,
onClickDelete: (Category) -> Unit,
onClickMoveUp: (Category) -> Unit,
onClickMoveDown: (Category) -> Unit,
Expand All @@ -49,6 +50,7 @@ fun MangaCategoryScreen(
lazyListState = lazyListState,
paddingValues = contentPadding + topSmallPaddingValues + PaddingValues(horizontal = MaterialTheme.padding.medium),
onClickRename = onClickRename,
onClickHide = onClickHide,
onClickDelete = onClickDelete,
onMoveUp = onClickMoveUp,
onMoveDown = onClickMoveDown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fun CategoryContent(
lazyListState: LazyListState,
paddingValues: PaddingValues,
onClickRename: (Category) -> Unit,
onClickHide: (Category) -> Unit,
onClickDelete: (Category) -> Unit,
onMoveUp: (Category) -> Unit,
onMoveDown: (Category) -> Unit,
Expand All @@ -38,6 +39,7 @@ fun CategoryContent(
onMoveUp = onMoveUp,
onMoveDown = onMoveDown,
onRename = { onClickRename(category) },
onHide = { onClickHide(category) },
onDelete = { onClickDelete(category) },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.compose.material.icons.outlined.ArrowDropUp
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material.icons.outlined.Label
import androidx.compose.material.icons.outlined.Visibility
import androidx.compose.material.icons.outlined.VisibilityOff
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -33,6 +35,7 @@ fun CategoryListItem(
onMoveUp: (Category) -> Unit,
onMoveDown: (Category) -> Unit,
onRename: () -> Unit,
onHide: () -> Unit,
onDelete: () -> Unit,
) {
ElevatedCard(
Expand Down Expand Up @@ -71,10 +74,29 @@ fun CategoryListItem(
}
Spacer(modifier = Modifier.weight(1f))
IconButton(onClick = onRename) {
Icon(imageVector = Icons.Outlined.Edit, contentDescription = stringResource(R.string.action_rename_category))
Icon(
imageVector = Icons.Outlined.Edit,
contentDescription = stringResource(R.string.action_rename_category),
)
}
IconButton(
onClick = onHide,
content = {
Icon(
imageVector = if (category.hidden) {
Icons.Outlined.Visibility
} else {
Icons.Outlined.VisibilityOff
},
contentDescription = stringResource(R.string.action_hide),
)
},
)
IconButton(onClick = onDelete) {
Icon(imageVector = Icons.Outlined.Delete, contentDescription = stringResource(R.string.action_delete))
Icon(
imageVector = Icons.Outlined.Delete,
contentDescription = stringResource(R.string.action_delete),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ object SettingsLibraryScreen : SearchableSettings {
@Composable
override fun getPreferences(): List<Preference> {
val getCategories = remember { Injekt.get<GetMangaCategories>() }
val allCategories by getCategories.subscribe().collectAsState(initial = runBlocking { getCategories.await() })
val allCategories by getCategories.subscribe()
.collectAsState(initial = runBlocking { getCategories.await() })
val getAnimeCategories = remember { Injekt.get<GetAnimeCategories>() }
val allAnimeCategories by getAnimeCategories.subscribe().collectAsState(initial = runBlocking { getAnimeCategories.await() })
val allAnimeCategories by getAnimeCategories.subscribe()
.collectAsState(initial = runBlocking { getAnimeCategories.await() })
val libraryPreferences = remember { Injekt.get<LibraryPreferences>() }

return listOf(
getCategoriesGroup(LocalNavigator.currentOrThrow, allCategories, allAnimeCategories, libraryPreferences),
getCategoriesGroup(
LocalNavigator.currentOrThrow,
allCategories,
allAnimeCategories,
libraryPreferences,
),
getGlobalUpdateGroup(allCategories, allAnimeCategories, libraryPreferences),
getChapterSwipeActionsGroup(libraryPreferences),
getEpisodeSwipeActionsGroup(libraryPreferences),
Expand All @@ -82,7 +89,8 @@ object SettingsLibraryScreen : SearchableSettings {
val defaultCategory by libraryPreferences.defaultMangaCategory().collectAsState()
val selectedCategory = allCategories.find { it.id == defaultCategory.toLong() }
val defaultAnimeCategory by libraryPreferences.defaultAnimeCategory().collectAsState()
val selectedAnimeCategory = allAnimeCategories.find { it.id == defaultAnimeCategory.toLong() }
val selectedAnimeCategory =
allAnimeCategories.find { it.id == defaultAnimeCategory.toLong() }

// For default category
val mangaIds = listOf(libraryPreferences.defaultMangaCategory().defaultValue()) +
Expand Down Expand Up @@ -110,7 +118,8 @@ object SettingsLibraryScreen : SearchableSettings {
Preference.PreferenceItem.ListPreference(
pref = libraryPreferences.defaultAnimeCategory(),
title = stringResource(R.string.default_anime_category),
subtitle = selectedAnimeCategory?.visualName ?: stringResource(R.string.default_category_summary),
subtitle = selectedAnimeCategory?.visualName
?: stringResource(R.string.default_category_summary),
entries = animeIds.zip(animeLabels).toMap(),
),
Preference.PreferenceItem.TextPreference(
Expand All @@ -125,7 +134,8 @@ object SettingsLibraryScreen : SearchableSettings {
Preference.PreferenceItem.ListPreference(
pref = libraryPreferences.defaultMangaCategory(),
title = stringResource(R.string.default_manga_category),
subtitle = selectedCategory?.visualName ?: stringResource(R.string.default_category_summary),
subtitle = selectedCategory?.visualName
?: stringResource(R.string.default_category_summary),
entries = mangaIds.zip(mangaLabels).toMap(),
),
Preference.PreferenceItem.SwitchPreference(
Expand All @@ -140,6 +150,10 @@ object SettingsLibraryScreen : SearchableSettings {
true
},
),
Preference.PreferenceItem.SwitchPreference(
pref = libraryPreferences.hideHiddenCategoriesSettings(),
title = stringResource(R.string.pref_category_hide_hidden),
),
),
)
}
Expand All @@ -158,7 +172,8 @@ object SettingsLibraryScreen : SearchableSettings {
val libraryUpdateMangaRestrictionPref = libraryPreferences.libraryUpdateItemRestriction()

val animelibUpdateCategoriesPref = libraryPreferences.animeLibraryUpdateCategories()
val animelibUpdateCategoriesExcludePref = libraryPreferences.animeLibraryUpdateCategoriesExclude()
val animelibUpdateCategoriesExcludePref =
libraryPreferences.animeLibraryUpdateCategoriesExclude()

val includedAnime by animelibUpdateCategoriesPref.collectAsState()
val excludedAnime by animelibUpdateCategoriesExcludePref.collectAsState()
Expand All @@ -174,14 +189,18 @@ object SettingsLibraryScreen : SearchableSettings {
onDismissRequest = { showAnimeDialog = false },
onValueChanged = { newIncluded, newExcluded ->
animelibUpdateCategoriesPref.set(newIncluded.map { it.id.toString() }.toSet())
animelibUpdateCategoriesExcludePref.set(newExcluded.map { it.id.toString() }.toSet())
animelibUpdateCategoriesExcludePref.set(
newExcluded.map { it.id.toString() }
.toSet(),
)
showAnimeDialog = false
},
)
}

val libraryUpdateCategoriesPref = libraryPreferences.mangaLibraryUpdateCategories()
val libraryUpdateCategoriesExcludePref = libraryPreferences.mangaLibraryUpdateCategoriesExclude()
val libraryUpdateCategoriesExcludePref =
libraryPreferences.mangaLibraryUpdateCategoriesExclude()

val includedManga by libraryUpdateCategoriesPref.collectAsState()
val excludedManga by libraryUpdateCategoriesExcludePref.collectAsState()
Expand All @@ -197,7 +216,10 @@ object SettingsLibraryScreen : SearchableSettings {
onDismissRequest = { showMangaDialog = false },
onValueChanged = { newIncluded, newExcluded ->
libraryUpdateCategoriesPref.set(newIncluded.map { it.id.toString() }.toSet())
libraryUpdateCategoriesExcludePref.set(newExcluded.map { it.id.toString() }.toSet())
libraryUpdateCategoriesExcludePref.set(
newExcluded.map { it.id.toString() }
.toSet(),
)
showMangaDialog = false
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BackupCategory(
name = [email protected],
flags = [email protected],
order = [email protected],
hidden = false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,63 @@ import kotlinx.coroutines.launch
import tachiyomi.domain.category.anime.interactor.CreateAnimeCategoryWithName
import tachiyomi.domain.category.anime.interactor.DeleteAnimeCategory
import tachiyomi.domain.category.anime.interactor.GetAnimeCategories
import tachiyomi.domain.category.anime.interactor.GetVisibleAnimeCategories
import tachiyomi.domain.category.anime.interactor.HideAnimeCategory
import tachiyomi.domain.category.anime.interactor.RenameAnimeCategory
import tachiyomi.domain.category.anime.interactor.ReorderAnimeCategory
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.service.LibraryPreferences
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

class AnimeCategoryScreenModel(
private val getCategories: GetAnimeCategories = Injekt.get(),
private val getAllCategories: GetAnimeCategories = Injekt.get(),
private val getVisibleCategories: GetVisibleAnimeCategories = Injekt.get(),
private val createCategoryWithName: CreateAnimeCategoryWithName = Injekt.get(),
private val hideCategory: HideAnimeCategory = Injekt.get(),
private val deleteCategory: DeleteAnimeCategory = Injekt.get(),
private val reorderCategory: ReorderAnimeCategory = Injekt.get(),
private val renameCategory: RenameAnimeCategory = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
) : StateScreenModel<AnimeCategoryScreenState>(AnimeCategoryScreenState.Loading) {

private val _events: Channel<AnimeCategoryEvent> = Channel()
val events = _events.receiveAsFlow()

init {
coroutineScope.launch {
getCategories.subscribe()
.collectLatest { categories ->
mutableState.update {
AnimeCategoryScreenState.Success(
categories = categories.filterNot(Category::isSystemCategory),
)
}
val allCategories = if (libraryPreferences.hideHiddenCategoriesSettings().get()) {
getVisibleCategories.subscribe()
} else {
getAllCategories.subscribe()
}

allCategories.collectLatest { categories ->
mutableState.update {
AnimeCategoryScreenState.Success(
categories = categories.filterNot(Category::isSystemCategory),
)
}
}
}
}

fun createCategory(name: String) {
coroutineScope.launch {
when (createCategoryWithName.await(name)) {
is CreateAnimeCategoryWithName.Result.InternalError -> _events.send(AnimeCategoryEvent.InternalError)
is CreateAnimeCategoryWithName.Result.InternalError -> _events.send(
AnimeCategoryEvent.InternalError,
)

else -> {}
}
}
}

fun hideCategory(category: Category) {
coroutineScope.launch {
when (hideCategory.await(category)) {
is HideAnimeCategory.Result.InternalError -> _events.send(AnimeCategoryEvent.InternalError)
else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fun Screen.animeCategoryTab(): TabContent {
contentPadding = contentPadding,
onClickCreate = { screenModel.showDialog(AnimeCategoryDialog.Create) },
onClickRename = { screenModel.showDialog(AnimeCategoryDialog.Rename(it)) },
onClickHide = screenModel::hideCategory,
onClickDelete = { screenModel.showDialog(AnimeCategoryDialog.Delete(it)) },
onClickMoveUp = screenModel::moveUp,
onClickMoveDown = screenModel::moveDown,
Expand Down
Loading