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