fixed in app downloader

This commit is contained in:
LagradOst 2021-09-20 21:27:51 +02:00
parent 6a561a35c0
commit 2a325469a5

View file

@ -65,16 +65,16 @@ class InAppUpdater {
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build()
private fun Activity.getAppUpdate(): Update { private fun Activity.getAppUpdate(): Update {
try { return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
return if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) { if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
getPreReleaseUpdate() getPreReleaseUpdate()
} else { } else {
getReleaseUpdate() getReleaseUpdate()
} }
} catch (e: Exception) { } catch (e: Exception) {
println(e) println(e)
return Update(false, null, null, null) Update(false, null, null, null)
} }
} }
@ -84,8 +84,8 @@ class InAppUpdater {
val response = val response =
mapper.readValue<List<GithubRelease>>(khttp.get(url, headers = headers).text) mapper.readValue<List<GithubRelease>>(khttp.get(url, headers = headers).text)
val versionRegex = Regex("""(.*?((\d)\.(\d)\.(\d)).*\.apk)""") val versionRegex = Regex("""(.*?((\d+)\.(\d+)\.(\d+))\.apk)""")
val versionRegexLocal = Regex("""(.*?((\d+)\.(\d+)\.(\d+)).*)""")
/* /*
val releases = response.map { it.assets }.flatten() val releases = response.map { it.assets }.flatten()
.filter { it.content_type == "application/vnd.android.package-archive" } .filter { it.content_type == "application/vnd.android.package-archive" }
@ -112,16 +112,25 @@ class InAppUpdater {
) )
} }
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) } foundAsset?.name?.let { assetName ->
val shouldUpdate = val foundVersion = versionRegex.find(assetName)
if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo( val shouldUpdate =
foundVersion.groupValues[2] if (foundAsset.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.let { versionName ->
)!! < 0 else false versionRegexLocal.find(versionName)?.groupValues?.let {
return if (foundVersion != null) { it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body) }
} else { }?.compareTo(
Update(false, null, null, null) foundVersion.groupValues.let {
it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
}
)!! < 0 else false
return if (foundVersion != null) {
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
} else {
Update(false, null, null, null)
}
} }
return Update(false, null, null, null)
} }
private fun Activity.getPreReleaseUpdate(): Update { private fun Activity.getPreReleaseUpdate(): Update {