From 4228bbb88efc1a2ff62c52d3bf5724150800e39e Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 18 Aug 2022 20:06:52 +0200 Subject: [PATCH] Set initial flag on new categories (#7800) - Use the same flag as other categories - Per-category uses the flag the user used before starting to use per-category --- app/src/main/java/eu/kanade/domain/DomainModule.kt | 2 +- .../category/interactor/CreateCategoryWithName.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 0c2777dbd..3fc504d98 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -79,7 +79,7 @@ class DomainModule : InjektModule { addFactory { ResetCategoryFlags(get(), get()) } addFactory { SetDisplayModeForCategory(get(), get()) } addFactory { SetSortModeForCategory(get(), get()) } - addFactory { CreateCategoryWithName(get()) } + addFactory { CreateCategoryWithName(get(), get()) } addFactory { RenameCategory(get()) } addFactory { ReorderCategory(get()) } addFactory { UpdateCategory(get()) } diff --git a/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt b/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt index b4c035bc4..efd615a7d 100644 --- a/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt +++ b/app/src/main/java/eu/kanade/domain/category/interactor/CreateCategoryWithName.kt @@ -3,6 +3,7 @@ package eu.kanade.domain.category.interactor import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.anyWithName import eu.kanade.domain.category.repository.CategoryRepository +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.withContext @@ -10,8 +11,16 @@ import logcat.LogPriority class CreateCategoryWithName( private val categoryRepository: CategoryRepository, + private val preferences: PreferencesHelper, ) { + private val initialFlags: Long + get() { + return preferences.libraryDisplayMode().get().flag or + preferences.librarySortingMode().get().flag or + preferences.librarySortingAscending().get().flag + } + suspend fun await(name: String): Result = withContext(NonCancellable) { val categories = categoryRepository.getAll() if (categories.anyWithName(name)) { @@ -23,7 +32,7 @@ class CreateCategoryWithName( id = 0, name = name, order = nextOrder, - flags = 0, + flags = initialFlags, ) try {