|
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.download
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import androidx.core.net.toUri
|
|
import androidx.core.net.toUri
|
|
import com.hippo.unifile.UniFile
|
|
import com.hippo.unifile.UniFile
|
|
|
|
+import eu.kanade.core.util.mapNotNullKeys
|
|
import eu.kanade.domain.download.service.DownloadPreferences
|
|
import eu.kanade.domain.download.service.DownloadPreferences
|
|
import eu.kanade.domain.manga.model.Manga
|
|
import eu.kanade.domain.manga.model.Manga
|
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
@@ -68,9 +69,7 @@ class DownloadCache(
|
|
downloadPreferences.downloadsDirectory().changes()
|
|
downloadPreferences.downloadsDirectory().changes()
|
|
.onEach {
|
|
.onEach {
|
|
rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
|
|
rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
|
|
-
|
|
|
|
- // Invalidate cache
|
|
|
|
- lastRenew = 0L
|
|
|
|
|
|
+ invalidateCache()
|
|
}
|
|
}
|
|
.launchIn(scope)
|
|
.launchIn(scope)
|
|
}
|
|
}
|
|
@@ -225,6 +224,10 @@ class DownloadCache(
|
|
notifyChanges()
|
|
notifyChanges()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fun invalidateCache() {
|
|
|
|
+ lastRenew = 0L
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns the downloads directory from the user's preferences.
|
|
* Returns the downloads directory from the user's preferences.
|
|
*/
|
|
*/
|
|
@@ -233,10 +236,6 @@ class DownloadCache(
|
|
return UniFile.fromUri(context, dir.toUri())
|
|
return UniFile.fromUri(context, dir.toUri())
|
|
}
|
|
}
|
|
|
|
|
|
- fun invalidateCache() {
|
|
|
|
- lastRenew = 0L
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Renews the downloads cache.
|
|
* Renews the downloads cache.
|
|
*/
|
|
*/
|
|
@@ -315,15 +314,6 @@ class DownloadCache(
|
|
_changes.send(Unit)
|
|
_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
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|