diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt index 30516882b..b51791f60 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt @@ -257,10 +257,7 @@ class FilterCoordinator @Inject constructor( } private fun mergeTags(primary: Set, secondary: Set): Set { - val result = TreeSet(TagTitleComparator(repository.source.locale)) - result.addAll(secondary) - result.addAll(primary) - return result + return (primary + secondary).toSortedSet(TagTitleComparator(repository.source.locale)) } private class TagsWrapper( diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt index 37170b478..49c47fe10 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt @@ -17,8 +17,6 @@ import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.ext.computeSize import org.koitharu.kotatsu.core.util.ext.getStorageName import org.koitharu.kotatsu.core.util.ext.resolveFile -import org.koitharu.kotatsu.core.util.ext.toFileOrNull -import org.koitharu.kotatsu.parsers.util.mapToSet import java.io.File import javax.inject.Inject @@ -58,7 +56,7 @@ class LocalStorageManager @Inject constructor( } suspend fun computeAvailableSize() = runInterruptible(Dispatchers.IO) { - getAvailableStorageDirs().mapToSet { it.freeSpace }.sum() + getAvailableStorageDirs().sumOf { it.freeSpace } } suspend fun clearCache(cache: CacheDir) = runInterruptible(Dispatchers.IO) { @@ -113,19 +111,16 @@ class LocalStorageManager @Inject constructor( } @WorkerThread - private fun getConfiguredStorageDirs(): MutableSet { - val set = getAvailableStorageDirs() - set.addAll(settings.userSpecifiedMangaDirectories) - return set + private fun getConfiguredStorageDirs(): Set { + return getAvailableStorageDirs() + settings.userSpecifiedMangaDirectories } @WorkerThread - private fun getAvailableStorageDirs(): MutableSet { - val result = LinkedHashSet() - result += File(context.filesDir, DIR_NAME) - context.getExternalFilesDirs(DIR_NAME).filterNotNullTo(result) - result.retainAll { it.exists() || it.mkdirs() } - return result + private fun getAvailableStorageDirs(): Set { + return (sequenceOf(File(context.filesDir, DIR_NAME)) + context.getExternalFilesDirs(DIR_NAME)) + .filterNotNull() + .filter { it.exists() || it.mkdirs() } + .toSet() } @WorkerThread @@ -136,21 +131,11 @@ class LocalStorageManager @Inject constructor( } @WorkerThread - private fun getCacheDirs(subDir: String): MutableSet { - val result = LinkedHashSet() - result += File(context.cacheDir, subDir) - context.externalCacheDirs.mapNotNullTo(result) { - File(it ?: return@mapNotNullTo null, subDir) - } - return result - } - - @WorkerThread - private fun getCacheDirs(): MutableSet { - val result = LinkedHashSet() - result += context.cacheDir - context.externalCacheDirs.filterNotNullTo(result) - return result + private fun getCacheDirs(subDir: String = ""): Set { + return (sequenceOf(context.cacheDir) + context.externalCacheDirs) + .filterNotNull() + .map { File(it, subDir) } + .toSet() } private fun calculateDiskCacheSize(cacheDirectory: File): Long {