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
This commit is contained in:
Andreas 2022-08-18 20:06:52 +02:00 committed by GitHub
parent 09abfc7843
commit 4228bbb88e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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()) }

View File

@ -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 {