deleted deleteRecursively

This commit is contained in:
Pupil
2020-02-12 09:03:47 +09:00
parent a714a8230b
commit 9d1998fe52
4 changed files with 12 additions and 15 deletions

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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()
}
}
}

View File

@@ -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)