Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
547b6e8e3b | ||
|
|
d88ac27e72 | ||
|
|
e551a40d08 | ||
|
|
e810abe33a |
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "xyz.quaver.pupil"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 36
|
||||
versionName "5.3-beta2"
|
||||
versionCode 37
|
||||
versionName "5.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":36,"versionName":"5.3-beta2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":37,"versionName":"5.4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
@@ -969,11 +969,11 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
Mode.DOWNLOAD -> {
|
||||
val downloads = getDownloadDirectory(this@MainActivity)?.listFiles()?.filter { file ->
|
||||
val downloads = getDownloadDirectory(this@MainActivity).listFiles().filter { file ->
|
||||
file.isDirectory && (file.name!!.toIntOrNull() != null) && file.findFile(".metadata") != null
|
||||
}?.map {
|
||||
}.map {
|
||||
it.name!!.toInt()
|
||||
}?: listOf()
|
||||
}
|
||||
|
||||
when {
|
||||
query.isEmpty() -> downloads.apply {
|
||||
|
||||
@@ -150,7 +150,12 @@ class SettingsFragment :
|
||||
"backup" -> {
|
||||
File(ContextCompat.getDataDir(context), "favorites.json").copyTo(
|
||||
context,
|
||||
getDownloadDirectory(context).createFile("null", "favorites.json")!!
|
||||
getDownloadDirectory(context).let {
|
||||
if (it.findFile("favorites.json") != null)
|
||||
it
|
||||
else
|
||||
it.createFile("null", "favorites.json")!!
|
||||
}
|
||||
)
|
||||
|
||||
Snackbar.make(this@SettingsFragment.listView, R.string.settings_backup_snackbar, Snackbar.LENGTH_LONG)
|
||||
|
||||
@@ -45,7 +45,7 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
// Search in this order
|
||||
// Download -> Cache
|
||||
fun getCachedGallery(galleryID: Int) : DocumentFile? {
|
||||
var file = getDownloadDirectory(this)?.findFile(galleryID.toString())
|
||||
var file = getDownloadDirectory(this).findFile(galleryID.toString())
|
||||
|
||||
if (file?.exists() == true)
|
||||
return file
|
||||
@@ -192,7 +192,7 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
val images = gallery.listFiles()
|
||||
|
||||
return reader.galleryInfo.indices.map { index ->
|
||||
images.firstOrNull { file -> file.name?.startsWith(index.toString()) == true }
|
||||
images.firstOrNull { file -> file.name?.startsWith("%05d".format(index)) == true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,21 +206,26 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
if (!Regex("""^[0-9]+.+$""").matches(name))
|
||||
throw IllegalArgumentException("File name is not a number")
|
||||
|
||||
cache.createFile("null", name)?.writeBytes(this, data)
|
||||
cache.let {
|
||||
if (it.findFile(name) != null)
|
||||
it
|
||||
else
|
||||
it.createFile("null", name)
|
||||
}?.writeBytes(this, data)
|
||||
}
|
||||
|
||||
fun moveToDownload(galleryID: Int) {
|
||||
val cache = getCachedGallery(galleryID)
|
||||
|
||||
if (cache != null) {
|
||||
val download = getDownloadDirectory(this)!!
|
||||
val download = getDownloadDirectory(this)
|
||||
|
||||
if (!download.isParentOf(cache)) {
|
||||
cache.copyRecursively(this, download)
|
||||
cache.deleteRecursively()
|
||||
}
|
||||
} else
|
||||
getDownloadDirectory(this)?.createDirectory(galleryID.toString())
|
||||
getDownloadDirectory(this).createDirectory(galleryID.toString())
|
||||
}
|
||||
|
||||
fun isDownloading(galleryID: Int) = getCachedMetadata(galleryID)?.isDownloading == true
|
||||
|
||||
@@ -312,7 +312,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
val ext =
|
||||
call.request().url().encodedPath().split('.').last()
|
||||
|
||||
Cache(this@DownloadWorker).putImage(galleryID, "$i.$ext", res)
|
||||
Cache(this@DownloadWorker).putImage(galleryID, "%05d.%s".format(i, ext), res)
|
||||
progress[galleryID]?.set(i, Float.POSITIVE_INFINITY)
|
||||
}
|
||||
|
||||
|
||||
@@ -104,12 +104,17 @@ fun DocumentFile.copyRecursively(
|
||||
if (!exists())
|
||||
throw Exception("The source file doesn't exist.")
|
||||
|
||||
if (this.isFile)
|
||||
target.createFile("null", name!!)!!.writeBytes(
|
||||
if (this.isFile) {
|
||||
target.let {
|
||||
if (it.findFile(name!!) != null)
|
||||
it
|
||||
else
|
||||
createFile("null", name!!)!!
|
||||
}.writeBytes(
|
||||
context,
|
||||
readBytes(context)
|
||||
)
|
||||
else if (this.isDirectory) {
|
||||
} else if (this.isDirectory) {
|
||||
target.createDirectory(name!!).also { newTarget ->
|
||||
listFiles().forEach { child ->
|
||||
child.copyRecursively(context, newTarget!!)
|
||||
|
||||
@@ -146,7 +146,12 @@ fun checkUpdate(context: AppCompatActivity, force: Boolean = false) {
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch io@{
|
||||
val target = getDownloadDirectory(context)?.createFile("null", "Pupil.apk")!!
|
||||
val target = getDownloadDirectory(context).let {
|
||||
if (it.findFile("Pupil.apk") != null)
|
||||
it
|
||||
else
|
||||
it.createFile("null", "Pupil.apk")!!
|
||||
}
|
||||
|
||||
try {
|
||||
URL(url).download(context, target) { progress, fileSize ->
|
||||
|
||||
Reference in New Issue
Block a user