fix(storage stats): Don't render arc for categories with 0 size + calculate local source sizes

This commit is contained in:
jmir1 2023-11-02 23:19:54 +01:00
parent efd42131e7
commit e012f220d8
No known key found for this signature in database
GPG key ID: 7B3B624787A072BD
6 changed files with 46 additions and 14 deletions

View file

@ -35,7 +35,11 @@ fun CumulativeStorage(
var currentAngle = 0f var currentAngle = 0f
rotate(180f) { rotate(180f) {
for (item in items) { for (item in items) {
val itemAngle = (item.size / totalSize) * totalAngle val itemAngle = if (totalSize > 0f) {
(item.size / totalSize) * totalAngle
} else {
0f
}
drawArc( drawArc(
color = item.color, color = item.color,
startAngle = currentAngle, startAngle = currentAngle,

View file

@ -1,10 +1,12 @@
package eu.kanade.tachiyomi.data.download.anime package eu.kanade.tachiyomi.data.download.anime
import android.content.Context import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.AnimeSource import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.model.Video import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.data.download.anime.model.AnimeDownload import eu.kanade.tachiyomi.data.download.anime.model.AnimeDownload
import eu.kanade.tachiyomi.util.size
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
@ -23,6 +25,9 @@ import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.entries.anime.model.Anime import tachiyomi.domain.entries.anime.model.Anime
import tachiyomi.domain.items.episode.model.Episode import tachiyomi.domain.items.episode.model.Episode
import tachiyomi.domain.source.anime.service.AnimeSourceManager import tachiyomi.domain.source.anime.service.AnimeSourceManager
import tachiyomi.source.local.entries.anime.LocalAnimeSource
import tachiyomi.source.local.io.ArchiveAnime
import tachiyomi.source.local.io.anime.LocalAnimeSourceFileSystem
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -214,12 +219,18 @@ class AnimeDownloadManager(
} }
/** /**
* Returns the amount of downloaded episodes for an anime. * Returns the amount of downloaded/local episodes for an anime.
* *
* @param anime the anime to check. * @param anime the anime to check.
*/ */
fun getDownloadCount(anime: Anime): Int { fun getDownloadCount(anime: Anime): Int {
return cache.getDownloadCount(anime) return if (anime.source == LocalAnimeSource.ID) {
LocalAnimeSourceFileSystem(context).getFilesInAnimeDirectory(anime.url)
.filter { ArchiveAnime.isSupported(it) }
.count()
} else {
cache.getDownloadCount(anime)
}
} }
/** /**
@ -230,12 +241,17 @@ class AnimeDownloadManager(
} }
/** /**
* Returns the size of downloaded episodes for an anime. * Returns the size of downloaded/local episodes for an anime.
* *
* @param anime the anime to check. * @param anime the anime to check.
*/ */
fun getDownloadSize(anime: Anime): Long { fun getDownloadSize(anime: Anime): Long {
return cache.getDownloadSize(anime) return if (anime.source == LocalAnimeSource.ID) {
LocalAnimeSourceFileSystem(context).getAnimeDirectory(anime.url)
.let { UniFile.fromFile(it) }?.size() ?: 0L
} else {
cache.getDownloadSize(anime)
}
} }
fun cancelQueuedDownloads(downloads: List<AnimeDownload>) { fun cancelQueuedDownloads(downloads: List<AnimeDownload>) {

View file

@ -1,10 +1,12 @@
package eu.kanade.tachiyomi.data.download.manga package eu.kanade.tachiyomi.data.download.manga
import android.content.Context import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.manga.model.MangaDownload import eu.kanade.tachiyomi.data.download.manga.model.MangaDownload
import eu.kanade.tachiyomi.source.MangaSource import eu.kanade.tachiyomi.source.MangaSource
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.util.size
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
@ -22,6 +24,9 @@ import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.entries.manga.model.Manga import tachiyomi.domain.entries.manga.model.Manga
import tachiyomi.domain.items.chapter.model.Chapter import tachiyomi.domain.items.chapter.model.Chapter
import tachiyomi.domain.source.manga.service.MangaSourceManager import tachiyomi.domain.source.manga.service.MangaSourceManager
import tachiyomi.source.local.entries.manga.LocalMangaSource
import tachiyomi.source.local.io.ArchiveManga
import tachiyomi.source.local.io.manga.LocalMangaSourceFileSystem
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -193,12 +198,18 @@ class MangaDownloadManager(
} }
/** /**
* Returns the amount of downloaded chapters for a manga. * Returns the amount of downloaded/local chapters for a manga.
* *
* @param manga the manga to check. * @param manga the manga to check.
*/ */
fun getDownloadCount(manga: Manga): Int { fun getDownloadCount(manga: Manga): Int {
return cache.getDownloadCount(manga) return if (manga.source == LocalMangaSource.ID) {
LocalMangaSourceFileSystem(context).getFilesInMangaDirectory(manga.url)
.filter { it.isDirectory || ArchiveManga.isSupported(it) }
.count()
} else {
cache.getDownloadCount(manga)
}
} }
/** /**
@ -209,12 +220,17 @@ class MangaDownloadManager(
} }
/** /**
* Returns the size of downloaded chapters for a manga. * Returns the size of downloaded/local episodes for an manga.
* *
* @param manga the manga to check. * @param manga the manga to check.
*/ */
fun getDownloadSize(manga: Manga): Long { fun getDownloadSize(manga: Manga): Long {
return cache.getDownloadSize(manga) return if (manga.source == LocalMangaSource.ID) {
LocalMangaSourceFileSystem(context).getMangaDirectory(manga.url)
.let { UniFile.fromFile(it) }?.size() ?: 0L
} else {
cache.getDownloadSize(manga)
}
} }
fun cancelQueuedDownloads(downloads: List<MangaDownload>) { fun cancelQueuedDownloads(downloads: List<MangaDownload>) {

View file

@ -22,7 +22,6 @@ abstract class CommonStorageScreenModel<T>(
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: Flow<List<Category>>,
private val getTotalDownloadSize: () -> Long,
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,
@ -47,14 +46,13 @@ abstract class CommonStorageScreenModel<T>(
}.filter { }.filter {
selectedCategory == AllCategory || it.getCategoryId() == selectedCategory.id selectedCategory == AllCategory || it.getCategoryId() == selectedCategory.id
} }
val size = getTotalDownloadSize()
val random = Random(size + distinctLibraries.size)
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 = distinctLibraries.map {
val random = Random(it.getId())
StorageItem( StorageItem(
id = it.getId(), id = it.getId(),
title = it.getTitle(), title = it.getTitle(),

View file

@ -23,7 +23,6 @@ class AnimeStorageScreenModel(
downloadCacheIsInitializing = downloadCache.isInitializing, downloadCacheIsInitializing = downloadCache.isInitializing,
libraries = getLibraries.subscribe(), libraries = getLibraries.subscribe(),
categories = getVisibleCategories.subscribe(), categories = getVisibleCategories.subscribe(),
getTotalDownloadSize = { downloadManager.getDownloadSize() },
getDownloadSize = { downloadManager.getDownloadSize(anime) }, getDownloadSize = { downloadManager.getDownloadSize(anime) },
getDownloadCount = { downloadManager.getDownloadCount(anime) }, getDownloadCount = { downloadManager.getDownloadCount(anime) },
getId = { id }, getId = { id },

View file

@ -23,7 +23,6 @@ class MangaStorageScreenModel(
downloadCacheIsInitializing = downloadCache.isInitializing, downloadCacheIsInitializing = downloadCache.isInitializing,
libraries = getLibraries.subscribe(), libraries = getLibraries.subscribe(),
categories = getVisibleCategories.subscribe(), categories = getVisibleCategories.subscribe(),
getTotalDownloadSize = { downloadManager.getDownloadSize() },
getDownloadSize = { downloadManager.getDownloadSize(manga) }, getDownloadSize = { downloadManager.getDownloadSize(manga) },
getDownloadCount = { downloadManager.getDownloadCount(manga) }, getDownloadCount = { downloadManager.getDownloadCount(manga) },
getId = { id }, getId = { id },