forked from recloudstream/cloudstream
fixed in app downloader
This commit is contained in:
parent
6a561a35c0
commit
2a325469a5
1 changed files with 23 additions and 14 deletions
|
@ -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,10 +112,17 @@ class InAppUpdater {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) }
|
foundAsset?.name?.let { assetName ->
|
||||||
|
val foundVersion = versionRegex.find(assetName)
|
||||||
val shouldUpdate =
|
val shouldUpdate =
|
||||||
if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
|
if (foundAsset.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.let { versionName ->
|
||||||
foundVersion.groupValues[2]
|
versionRegexLocal.find(versionName)?.groupValues?.let {
|
||||||
|
it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
|
||||||
|
}
|
||||||
|
}?.compareTo(
|
||||||
|
foundVersion.groupValues.let {
|
||||||
|
it[3].toInt() * 100_000_000 + it[4].toInt() * 10_000 + it[5].toInt()
|
||||||
|
}
|
||||||
)!! < 0 else false
|
)!! < 0 else false
|
||||||
return if (foundVersion != null) {
|
return if (foundVersion != null) {
|
||||||
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
|
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
|
||||||
|
@ -123,6 +130,8 @@ class InAppUpdater {
|
||||||
Update(false, null, null, null)
|
Update(false, null, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Update(false, null, null, null)
|
||||||
|
}
|
||||||
|
|
||||||
private fun Activity.getPreReleaseUpdate(): Update {
|
private fun Activity.getPreReleaseUpdate(): Update {
|
||||||
val tagUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/git/ref/tags/pre-release"
|
val tagUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/git/ref/tags/pre-release"
|
||||||
|
|
Loading…
Reference in a new issue