App crash fix

This commit is contained in:
tom5079
2019-07-07 16:36:42 +09:00
parent a74b2c9b49
commit 905ea766b1
5 changed files with 31 additions and 14 deletions

View File

@@ -13,8 +13,8 @@ android {
applicationId "xyz.quaver.pupil"
minSdkVersion 16
targetSdkVersion 29
versionCode 21
versionName "3.0"
versionCode 22
versionName "3.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true

View File

@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":21,"versionName":"3.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":22,"versionName":"3.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

View File

@@ -95,6 +95,13 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
val readerCache = { File(getCachedGallery(context, galleryBlock.id), "reader.json") }
val imageCache = { File(getCachedGallery(context, galleryBlock.id), "images") }
try {
Json(JsonConfiguration.Stable)
.parse(Reader.serializer(), readerCache.invoke().readText())
} catch(e: Exception) {
readerCache.invoke().delete()
}
if (readerCache.invoke().exists()) {
val reader = Json(JsonConfiguration.Stable)
.parse(Reader.serializer(), readerCache.invoke().readText())
@@ -146,8 +153,6 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
}
} else
view.galleryblock_progress_complete.visibility = View.INVISIBLE
null
}
}
}

View File

@@ -110,6 +110,12 @@ class GalleryDownloader(
//Check cache
val cache = File(getCachedGallery(this@GalleryDownloader, galleryID), "reader.json")
try {
json.parse(serializer, cache.readText())
} catch(e: Exception) {
cache.delete()
}
if (cache.exists()) {
val cached = json.parse(serializer, cache.readText())

View File

@@ -40,19 +40,25 @@ fun checkUpdate(url: String) : JsonObject? {
return releases.firstOrNull {
if (BuildConfig.PRERELEASE) {
BuildConfig.VERSION_NAME != it.jsonObject["tag_name"]?.content
true
} else {
it.jsonObject["prerelease"]?.boolean == false &&
BuildConfig.VERSION_NAME != (it.jsonObject["tag_name"]?.content ?: "")
it.jsonObject["prerelease"]?.boolean == false
}
}?.jsonObject
}?.let {
if (it.jsonObject["tag_name"]?.content == BuildConfig.VERSION_NAME)
null
else
it.jsonObject
}
}
fun getApkUrl(releases: JsonObject) : Pair<String?, String?>? {
releases["assets"]?.jsonArray?.forEach {
if (Regex("Pupil-v(\\d+\\.)+\\d+\\.apk").matches(it.jsonObject["name"]?.content ?: ""))
return Pair(it.jsonObject["browser_download_url"]?.content, it.jsonObject["name"]?.content)
return releases["assets"]?.jsonArray?.firstOrNull {
Regex("Pupil-v(\\d+\\.)+\\d+\\.apk").matches(it.jsonObject["name"]?.content ?: "")
}.let {
if (it == null)
null
else
Pair(it.jsonObject["browser_download_url"]?.content, it.jsonObject["name"]?.content)
}
return null
}