mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-21 20:27:06 +03:00
fix(storage-viewer): Don't show hidden categories in all view (#1193)
This commit is contained in:
parent
5fd00d4a1c
commit
fd83a7e141
5 changed files with 75 additions and 32 deletions
|
@ -31,15 +31,14 @@ fun CumulativeStorage(
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = Modifier.aspectRatio(1f),
|
modifier = Modifier.aspectRatio(1f),
|
||||||
onDraw = {
|
onDraw = {
|
||||||
|
// don't bother drawing if there's no data
|
||||||
|
if (totalSize == 0f) return@Canvas
|
||||||
|
|
||||||
val totalAngle = 180f
|
val totalAngle = 180f
|
||||||
var currentAngle = 0f
|
var currentAngle = 0f
|
||||||
rotate(180f) {
|
rotate(180f) {
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
val itemAngle = if (totalSize > 0f) {
|
val itemAngle = (item.size / totalSize) * totalAngle
|
||||||
(item.size / totalSize) * totalAngle
|
|
||||||
} else {
|
|
||||||
0f
|
|
||||||
}
|
|
||||||
drawArc(
|
drawArc(
|
||||||
color = item.color,
|
color = item.color,
|
||||||
startAngle = currentAngle,
|
startAngle = currentAngle,
|
||||||
|
|
|
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.storage
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||||
import cafe.adriel.voyager.core.model.coroutineScope
|
import cafe.adriel.voyager.core.model.coroutineScope
|
||||||
import eu.kanade.core.util.fastDistinctBy
|
|
||||||
import eu.kanade.presentation.more.storage.StorageItem
|
import eu.kanade.presentation.more.storage.StorageItem
|
||||||
import eu.kanade.presentation.more.storage.StorageScreenState
|
import eu.kanade.presentation.more.storage.StorageScreenState
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
@ -15,59 +14,88 @@ import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import tachiyomi.core.util.lang.launchIO
|
import tachiyomi.core.util.lang.launchIO
|
||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
abstract class CommonStorageScreenModel<T>(
|
abstract class CommonStorageScreenModel<T>(
|
||||||
private val downloadCacheChanges: SharedFlow<Unit>,
|
private val downloadCacheChanges: SharedFlow<Unit>,
|
||||||
private val downloadCacheIsInitializing: StateFlow<Boolean>,
|
private val downloadCacheIsInitializing: StateFlow<Boolean>,
|
||||||
private val libraries: Flow<List<T>>,
|
private val libraries: Flow<List<T>>,
|
||||||
private val categories: Flow<List<Category>>,
|
private val categories: (Boolean) -> Flow<List<Category>>,
|
||||||
private val getDownloadSize: T.() -> Long,
|
private val getDownloadSize: T.() -> Long,
|
||||||
private val getDownloadCount: T.() -> Int,
|
private val getDownloadCount: T.() -> Int,
|
||||||
private val getId: T.() -> Long,
|
private val getId: T.() -> Long,
|
||||||
private val getCategoryId: T.() -> Long,
|
private val getCategoryId: T.() -> Long,
|
||||||
private val getTitle: T.() -> String,
|
private val getTitle: T.() -> String,
|
||||||
private val getThumbnail: T.() -> String?,
|
private val getThumbnail: T.() -> String?,
|
||||||
|
private val libraryPreferences: LibraryPreferences = Injekt.get(),
|
||||||
) : StateScreenModel<StorageScreenState>(StorageScreenState.Loading) {
|
) : StateScreenModel<StorageScreenState>(StorageScreenState.Loading) {
|
||||||
|
|
||||||
private val selectedCategory = MutableStateFlow(AllCategory)
|
private val selectedCategory = MutableStateFlow(AllCategory)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
coroutineScope.launchIO {
|
coroutineScope.launchIO {
|
||||||
|
val hideHiddenCategories = libraryPreferences.hideHiddenCategoriesSettings().get()
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
flow = downloadCacheChanges,
|
flow = downloadCacheChanges,
|
||||||
flow2 = downloadCacheIsInitializing,
|
flow2 = downloadCacheIsInitializing,
|
||||||
flow3 = libraries,
|
flow3 = libraries,
|
||||||
flow4 = categories,
|
flow4 = categories(hideHiddenCategories),
|
||||||
flow5 = selectedCategory,
|
flow5 = selectedCategory,
|
||||||
transform = { _, _, libraries, categories, selectedCategory ->
|
transform = { _, _, libraries, categories, selectedCategory ->
|
||||||
val distinctLibraries = libraries.fastDistinctBy {
|
// initialize the screen with an empty state
|
||||||
it.getId()
|
|
||||||
}.filter {
|
|
||||||
selectedCategory == AllCategory || it.getCategoryId() == selectedCategory.id
|
|
||||||
}
|
|
||||||
|
|
||||||
mutableState.update {
|
mutableState.update {
|
||||||
StorageScreenState.Success(
|
StorageScreenState.Success(
|
||||||
selectedCategory = selectedCategory,
|
selectedCategory = selectedCategory,
|
||||||
categories = listOf(AllCategory, *categories.toTypedArray()),
|
categories = listOf(AllCategory, *categories.toTypedArray()),
|
||||||
items = distinctLibraries.map {
|
items = emptyList(),
|
||||||
val random = Random(it.getId())
|
|
||||||
StorageItem(
|
|
||||||
id = it.getId(),
|
|
||||||
title = it.getTitle(),
|
|
||||||
size = it.getDownloadSize(),
|
|
||||||
thumbnail = it.getThumbnail(),
|
|
||||||
entriesCount = it.getDownloadCount(),
|
|
||||||
color = Color(
|
|
||||||
random.nextInt(255),
|
|
||||||
random.nextInt(255),
|
|
||||||
random.nextInt(255),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}.sortedByDescending { it.size },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val distinctLibraries = libraries.distinctBy {
|
||||||
|
it.getId()
|
||||||
|
}.filter { item ->
|
||||||
|
val categoryId = item.getCategoryId()
|
||||||
|
when {
|
||||||
|
// if all is selected, we want to make sure to include all entries
|
||||||
|
// from only visible categories
|
||||||
|
selectedCategory == AllCategory -> categories.find {
|
||||||
|
it.id == categoryId
|
||||||
|
} != null
|
||||||
|
|
||||||
|
// else include only entries from the selected category
|
||||||
|
else -> categoryId == selectedCategory.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
distinctLibraries.forEach { library ->
|
||||||
|
val random = Random(library.getId())
|
||||||
|
val item = StorageItem(
|
||||||
|
id = library.getId(),
|
||||||
|
title = library.getTitle(),
|
||||||
|
size = library.getDownloadSize(),
|
||||||
|
thumbnail = library.getThumbnail(),
|
||||||
|
entriesCount = library.getDownloadCount(),
|
||||||
|
color = Color(
|
||||||
|
random.nextInt(255),
|
||||||
|
random.nextInt(255),
|
||||||
|
random.nextInt(255),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
mutableState.update { state ->
|
||||||
|
when (state) {
|
||||||
|
is StorageScreenState.Success -> state.copy(
|
||||||
|
items = (state.items + item).sortedByDescending { it.size },
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
).collectLatest {}
|
).collectLatest {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.data.download.anime.AnimeDownloadCache
|
||||||
import eu.kanade.tachiyomi.data.download.anime.AnimeDownloadManager
|
import eu.kanade.tachiyomi.data.download.anime.AnimeDownloadManager
|
||||||
import eu.kanade.tachiyomi.ui.storage.CommonStorageScreenModel
|
import eu.kanade.tachiyomi.ui.storage.CommonStorageScreenModel
|
||||||
import tachiyomi.core.util.lang.launchNonCancellable
|
import tachiyomi.core.util.lang.launchNonCancellable
|
||||||
|
import tachiyomi.domain.category.anime.interactor.GetAnimeCategories
|
||||||
import tachiyomi.domain.category.anime.interactor.GetVisibleAnimeCategories
|
import tachiyomi.domain.category.anime.interactor.GetVisibleAnimeCategories
|
||||||
import tachiyomi.domain.entries.anime.interactor.GetLibraryAnime
|
import tachiyomi.domain.entries.anime.interactor.GetLibraryAnime
|
||||||
import tachiyomi.domain.library.anime.LibraryAnime
|
import tachiyomi.domain.library.anime.LibraryAnime
|
||||||
|
@ -15,6 +16,7 @@ import uy.kohesive.injekt.api.get
|
||||||
class AnimeStorageScreenModel(
|
class AnimeStorageScreenModel(
|
||||||
downloadCache: AnimeDownloadCache = Injekt.get(),
|
downloadCache: AnimeDownloadCache = Injekt.get(),
|
||||||
private val getLibraries: GetLibraryAnime = Injekt.get(),
|
private val getLibraries: GetLibraryAnime = Injekt.get(),
|
||||||
|
getCategories: GetAnimeCategories = Injekt.get(),
|
||||||
getVisibleCategories: GetVisibleAnimeCategories = Injekt.get(),
|
getVisibleCategories: GetVisibleAnimeCategories = Injekt.get(),
|
||||||
private val downloadManager: AnimeDownloadManager = Injekt.get(),
|
private val downloadManager: AnimeDownloadManager = Injekt.get(),
|
||||||
private val sourceManager: AnimeSourceManager = Injekt.get(),
|
private val sourceManager: AnimeSourceManager = Injekt.get(),
|
||||||
|
@ -22,7 +24,13 @@ class AnimeStorageScreenModel(
|
||||||
downloadCacheChanges = downloadCache.changes,
|
downloadCacheChanges = downloadCache.changes,
|
||||||
downloadCacheIsInitializing = downloadCache.isInitializing,
|
downloadCacheIsInitializing = downloadCache.isInitializing,
|
||||||
libraries = getLibraries.subscribe(),
|
libraries = getLibraries.subscribe(),
|
||||||
categories = getVisibleCategories.subscribe(),
|
categories = { hideHiddenCategories ->
|
||||||
|
if (hideHiddenCategories) {
|
||||||
|
getVisibleCategories.subscribe()
|
||||||
|
} else {
|
||||||
|
getCategories.subscribe()
|
||||||
|
}
|
||||||
|
},
|
||||||
getDownloadSize = { downloadManager.getDownloadSize(anime) },
|
getDownloadSize = { downloadManager.getDownloadSize(anime) },
|
||||||
getDownloadCount = { downloadManager.getDownloadCount(anime) },
|
getDownloadCount = { downloadManager.getDownloadCount(anime) },
|
||||||
getId = { id },
|
getId = { id },
|
||||||
|
|
|
@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.data.download.manga.MangaDownloadCache
|
||||||
import eu.kanade.tachiyomi.data.download.manga.MangaDownloadManager
|
import eu.kanade.tachiyomi.data.download.manga.MangaDownloadManager
|
||||||
import eu.kanade.tachiyomi.ui.storage.CommonStorageScreenModel
|
import eu.kanade.tachiyomi.ui.storage.CommonStorageScreenModel
|
||||||
import tachiyomi.core.util.lang.launchNonCancellable
|
import tachiyomi.core.util.lang.launchNonCancellable
|
||||||
|
import tachiyomi.domain.category.manga.interactor.GetMangaCategories
|
||||||
import tachiyomi.domain.category.manga.interactor.GetVisibleMangaCategories
|
import tachiyomi.domain.category.manga.interactor.GetVisibleMangaCategories
|
||||||
import tachiyomi.domain.entries.manga.interactor.GetLibraryManga
|
import tachiyomi.domain.entries.manga.interactor.GetLibraryManga
|
||||||
import tachiyomi.domain.library.manga.LibraryManga
|
import tachiyomi.domain.library.manga.LibraryManga
|
||||||
|
@ -15,6 +16,7 @@ import uy.kohesive.injekt.api.get
|
||||||
class MangaStorageScreenModel(
|
class MangaStorageScreenModel(
|
||||||
downloadCache: MangaDownloadCache = Injekt.get(),
|
downloadCache: MangaDownloadCache = Injekt.get(),
|
||||||
private val getLibraries: GetLibraryManga = Injekt.get(),
|
private val getLibraries: GetLibraryManga = Injekt.get(),
|
||||||
|
getCategories: GetMangaCategories = Injekt.get(),
|
||||||
getVisibleCategories: GetVisibleMangaCategories = Injekt.get(),
|
getVisibleCategories: GetVisibleMangaCategories = Injekt.get(),
|
||||||
private val downloadManager: MangaDownloadManager = Injekt.get(),
|
private val downloadManager: MangaDownloadManager = Injekt.get(),
|
||||||
private val sourceManager: MangaSourceManager = Injekt.get(),
|
private val sourceManager: MangaSourceManager = Injekt.get(),
|
||||||
|
@ -22,7 +24,13 @@ class MangaStorageScreenModel(
|
||||||
downloadCacheChanges = downloadCache.changes,
|
downloadCacheChanges = downloadCache.changes,
|
||||||
downloadCacheIsInitializing = downloadCache.isInitializing,
|
downloadCacheIsInitializing = downloadCache.isInitializing,
|
||||||
libraries = getLibraries.subscribe(),
|
libraries = getLibraries.subscribe(),
|
||||||
categories = getVisibleCategories.subscribe(),
|
categories = { hideHiddenCategories ->
|
||||||
|
if (hideHiddenCategories) {
|
||||||
|
getVisibleCategories.subscribe()
|
||||||
|
} else {
|
||||||
|
getCategories.subscribe()
|
||||||
|
}
|
||||||
|
},
|
||||||
getDownloadSize = { downloadManager.getDownloadSize(manga) },
|
getDownloadSize = { downloadManager.getDownloadSize(manga) },
|
||||||
getDownloadCount = { downloadManager.getDownloadCount(manga) },
|
getDownloadCount = { downloadManager.getDownloadCount(manga) },
|
||||||
getId = { id },
|
getId = { id },
|
||||||
|
|
|
@ -324,7 +324,7 @@
|
||||||
<string name="pref_episode_swipe_end">Swipe to right action</string>
|
<string name="pref_episode_swipe_end">Swipe to right action</string>
|
||||||
<string name="pref_episode_swipe_start">Swipe to left action</string>
|
<string name="pref_episode_swipe_start">Swipe to left action</string>
|
||||||
|
|
||||||
<string name="pref_category_hide_hidden">Hide hidden categories from categories screen</string>
|
<string name="pref_category_hide_hidden">Hide hidden categories from categories and storage screen</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Subtitle settings -->
|
<!-- Subtitle settings -->
|
||||||
|
|
Loading…
Reference in a new issue