deleted deleteRecursively
This commit is contained in:
@@ -429,12 +429,7 @@ class MainActivity : AppCompatActivity() {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
DownloadWorker.getInstance(context).cancel(galleryID)
|
||||
|
||||
var cache = Cache(context).getCachedGallery(galleryID)
|
||||
|
||||
while (cache != null) {
|
||||
cache.deleteRecursively()
|
||||
cache = Cache(context).getCachedGallery(galleryID)
|
||||
}
|
||||
Cache(context).getCachedGallery(galleryID)?.delete()
|
||||
|
||||
histories.remove(galleryID)
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class SettingsFragment :
|
||||
setMessage(R.string.settings_clear_cache_alert_message)
|
||||
setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
if (dir.exists())
|
||||
dir.deleteRecursively()
|
||||
dir.delete()
|
||||
|
||||
summary = getDirSize(dir)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ class SettingsFragment :
|
||||
setMessage(R.string.settings_clear_downloads_alert_message)
|
||||
setPositiveButton(android.R.string.yes) { _, _ ->
|
||||
if (dir.exists())
|
||||
dir.deleteRecursively()
|
||||
dir.delete()
|
||||
|
||||
summary = getDirSize(dir)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package xyz.quaver.pupil.util.download
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -189,8 +190,13 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
fun getImages(galleryID: Int): List<DocumentFile?>? {
|
||||
val gallery = getCachedGallery(galleryID) ?: return null
|
||||
val reader = getReaderOrNull(galleryID) ?: return null
|
||||
|
||||
val time = System.currentTimeMillis()
|
||||
|
||||
val images = gallery.listFiles()
|
||||
|
||||
Log.i("PUPILD", "${System.currentTimeMillis() - time} ms")
|
||||
|
||||
return reader.galleryInfo.indices.map { index ->
|
||||
images.firstOrNull { file -> file.name?.startsWith("%05d".format(index)) == true }
|
||||
}
|
||||
@@ -220,10 +226,10 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
if (!download.isParentOf(cache)) {
|
||||
val target = getDownloadDirectory(this).let {
|
||||
it.findFile(galleryID.toString()) ?: it.createDirectory(galleryID.toString())
|
||||
}
|
||||
} ?: return
|
||||
|
||||
cache.copyRecursively(this, download)
|
||||
cache.deleteRecursively()
|
||||
cache.copyRecursively(this, target)
|
||||
cache.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,10 +128,6 @@ fun DocumentFile.copyRecursively(
|
||||
}
|
||||
}
|
||||
|
||||
fun DocumentFile.deleteRecursively() {
|
||||
this.delete()
|
||||
}
|
||||
|
||||
fun DocumentFile.walk(state: LinkedList<DocumentFile> = LinkedList()) : Queue<DocumentFile> {
|
||||
if (state.isEmpty())
|
||||
state.push(this)
|
||||
|
||||
Reference in New Issue
Block a user