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