Minor cleanup

This commit is contained in:
arkon
2022-11-10 22:23:34 -05:00
parent 08d5633d81
commit 811931ccc0
19 changed files with 120 additions and 146 deletions
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.download
import android.content.Context
import androidx.core.net.toUri
import com.hippo.unifile.UniFile
import eu.kanade.core.util.mapNotNullKeys
import eu.kanade.domain.download.service.DownloadPreferences
import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.database.models.Chapter
@@ -68,9 +69,7 @@ class DownloadCache(
downloadPreferences.downloadsDirectory().changes()
.onEach {
rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
// Invalidate cache
lastRenew = 0L
invalidateCache()
}
.launchIn(scope)
}
@@ -225,6 +224,10 @@ class DownloadCache(
notifyChanges()
}
fun invalidateCache() {
lastRenew = 0L
}
/**
* Returns the downloads directory from the user's preferences.
*/
@@ -233,10 +236,6 @@ class DownloadCache(
return UniFile.fromUri(context, dir.toUri())
}
fun invalidateCache() {
lastRenew = 0L
}
/**
* Renews the downloads cache.
*/
@@ -315,15 +314,6 @@ class DownloadCache(
_changes.send(Unit)
}
}
/**
* Returns a new map containing only the key entries of [transform] that are not null.
*/
private inline fun <K, V, R> Map<out K, V>.mapNotNullKeys(transform: (Map.Entry<K?, V>) -> R?): ConcurrentHashMap<R, V> {
val mutableMap = ConcurrentHashMap<R, V>()
forEach { element -> transform(element)?.let { mutableMap[it] = element.value } }
return mutableMap
}
}
/**