sample, update check git revision
This commit is contained in:
parent
05cdf2c400
commit
910bf311da
@ -276,6 +276,9 @@ class SampleListFragment : Fragment() {
|
||||
is UpdateUtils.Result.UpdateAvailable -> {
|
||||
val md = """
|
||||
## Update available
|
||||
|
||||
${BuildConfig.GIT_SHA} -> **${result.revision}**
|
||||
|
||||
Would you like to download it?
|
||||
""".trimIndent()
|
||||
builder.setMessage(markwon.toMarkdown(md))
|
||||
@ -289,7 +292,7 @@ class SampleListFragment : Fragment() {
|
||||
is UpdateUtils.Result.NoUpdate -> {
|
||||
val md = """
|
||||
## No update
|
||||
You are using latest version (${BuildConfig.GIT_SHA})
|
||||
You are using latest version (**${BuildConfig.GIT_SHA}**)
|
||||
""".trimIndent()
|
||||
builder.setMessage(markwon.toMarkdown(md))
|
||||
builder.setPositiveButton(android.R.string.ok, null)
|
||||
|
@ -12,7 +12,7 @@ import java.io.IOException
|
||||
object UpdateUtils {
|
||||
|
||||
sealed class Result {
|
||||
class UpdateAvailable(val url: String) : Result()
|
||||
class UpdateAvailable(val revision: String, val url: String) : Result()
|
||||
object NoUpdate : Result()
|
||||
class Error(val throwable: Throwable) : Result()
|
||||
}
|
||||
@ -34,10 +34,11 @@ object UpdateUtils {
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
try {
|
||||
val revision = response.body()?.string()
|
||||
val revision = response.body()?.string()?.trim()
|
||||
val hasUpdate = revision != null && BuildConfig.GIT_SHA != revision
|
||||
if (hasUpdate) {
|
||||
action?.invoke(Result.UpdateAvailable(apkUrl))
|
||||
// revision is guarded by `hasUpdate` (includes null check)
|
||||
action?.invoke(Result.UpdateAvailable(revision!!, apkUrl))
|
||||
} else {
|
||||
action?.invoke(Result.NoUpdate)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user