From efd42131e7aac98947a6269c0fe573c785f9f41e Mon Sep 17 00:00:00 2001 From: jmir1 Date: Thu, 2 Nov 2023 22:24:24 +0100 Subject: [PATCH 1/3] fix(font settings): Prevent showing multiple fonts of the same family name --- .../player/settings/sheets/subtitle/SubtitleFontPage.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/sheets/subtitle/SubtitleFontPage.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/sheets/subtitle/SubtitleFontPage.kt index a2e75965f..66e99199a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/sheets/subtitle/SubtitleFontPage.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/settings/sheets/subtitle/SubtitleFontPage.kt @@ -94,10 +94,10 @@ private fun SubtitleFont( ).listFiles { file -> file.extension.equals("ttf", true) || file.extension.equals("otf", true) - }?.map { + }?.associate { TTFFile.open(it).families.values.toTypedArray()[0] to it.absolutePath - } ?: emptyList() - listOf("Sans Serif" to "") + customFonts + } ?: emptyMap() + mapOf("Sans Serif" to ("" to null)) + customFonts } } var selectingFont by remember { mutableStateOf(false) } @@ -152,7 +152,7 @@ private fun SubtitleFont( DropdownMenu(expanded = selectingFont, onDismissRequest = { selectingFont = false }) { fontList.map { - val fontName = it.first + val fontName = it.key DropdownMenuItem( text = { Text(fontName) }, onClick = { updateFont(fontName) }, From e012f220d887473a7f0b7ec045d19e03bfa313e0 Mon Sep 17 00:00:00 2001 From: jmir1 Date: Thu, 2 Nov 2023 23:19:54 +0100 Subject: [PATCH 2/3] fix(storage stats): Don't render arc for categories with 0 size + calculate local source sizes --- .../more/storage/CumulativeStorage.kt | 6 ++++- .../download/anime/AnimeDownloadManager.kt | 24 +++++++++++++++---- .../download/manga/MangaDownloadManager.kt | 24 +++++++++++++++---- .../ui/storage/CommonStorageScreenModel.kt | 4 +--- .../storage/anime/AnimeStorageScreenModel.kt | 1 - .../storage/manga/MangaStorageScreenModel.kt | 1 - 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt b/app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt index a68112ee7..40f51001f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt +++ b/app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt @@ -35,7 +35,11 @@ fun CumulativeStorage( var currentAngle = 0f rotate(180f) { for (item in items) { - val itemAngle = (item.size / totalSize) * totalAngle + val itemAngle = if (totalSize > 0f) { + (item.size / totalSize) * totalAngle + } else { + 0f + } drawArc( color = item.color, startAngle = currentAngle, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadManager.kt index 915c43bcf..dc35e58d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadManager.kt @@ -1,10 +1,12 @@ package eu.kanade.tachiyomi.data.download.anime import android.content.Context +import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.animesource.AnimeSource import eu.kanade.tachiyomi.animesource.model.Video import eu.kanade.tachiyomi.data.download.anime.model.AnimeDownload +import eu.kanade.tachiyomi.util.size import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow 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.items.episode.model.Episode 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.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. */ 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. */ 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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadManager.kt index daaff8bcf..b5eb1e3cf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadManager.kt @@ -1,10 +1,12 @@ package eu.kanade.tachiyomi.data.download.manga import android.content.Context +import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.manga.model.MangaDownload import eu.kanade.tachiyomi.source.MangaSource import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.util.size import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow 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.items.chapter.model.Chapter 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.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. */ 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. */ 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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/CommonStorageScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/CommonStorageScreenModel.kt index cdccee98f..e6c3af31d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/CommonStorageScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/CommonStorageScreenModel.kt @@ -22,7 +22,6 @@ abstract class CommonStorageScreenModel( private val downloadCacheIsInitializing: StateFlow, private val libraries: Flow>, private val categories: Flow>, - private val getTotalDownloadSize: () -> Long, private val getDownloadSize: T.() -> Long, private val getDownloadCount: T.() -> Int, private val getId: T.() -> Long, @@ -47,14 +46,13 @@ abstract class CommonStorageScreenModel( }.filter { selectedCategory == AllCategory || it.getCategoryId() == selectedCategory.id } - val size = getTotalDownloadSize() - val random = Random(size + distinctLibraries.size) mutableState.update { StorageScreenState.Success( selectedCategory = selectedCategory, categories = listOf(AllCategory, *categories.toTypedArray()), items = distinctLibraries.map { + val random = Random(it.getId()) StorageItem( id = it.getId(), title = it.getTitle(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/anime/AnimeStorageScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/anime/AnimeStorageScreenModel.kt index 32bb03e48..80ab6206e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/anime/AnimeStorageScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/anime/AnimeStorageScreenModel.kt @@ -23,7 +23,6 @@ class AnimeStorageScreenModel( downloadCacheIsInitializing = downloadCache.isInitializing, libraries = getLibraries.subscribe(), categories = getVisibleCategories.subscribe(), - getTotalDownloadSize = { downloadManager.getDownloadSize() }, getDownloadSize = { downloadManager.getDownloadSize(anime) }, getDownloadCount = { downloadManager.getDownloadCount(anime) }, getId = { id }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/manga/MangaStorageScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/manga/MangaStorageScreenModel.kt index f9358e7eb..4f97095b3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/storage/manga/MangaStorageScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/storage/manga/MangaStorageScreenModel.kt @@ -23,7 +23,6 @@ class MangaStorageScreenModel( downloadCacheIsInitializing = downloadCache.isInitializing, libraries = getLibraries.subscribe(), categories = getVisibleCategories.subscribe(), - getTotalDownloadSize = { downloadManager.getDownloadSize() }, getDownloadSize = { downloadManager.getDownloadSize(manga) }, getDownloadCount = { downloadManager.getDownloadCount(manga) }, getId = { id }, From 5fd00d4a1c273fa73bb01c067044f96e1dfaded5 Mon Sep 17 00:00:00 2001 From: jmir1 Date: Thu, 2 Nov 2023 23:40:18 +0100 Subject: [PATCH 3/3] chore: Bump version code --- app/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2c482d54e..82c154ce0 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,7 +21,7 @@ android { defaultConfig { applicationId = "xyz.jmir.tachiyomi.mi" - versionCode = 104 + versionCode = 105 versionName = "0.14.6" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")