Skip to content

Commit

Permalink
sample, update check git revision
Browse files Browse the repository at this point in the history
  • Loading branch information
noties committed Dec 28, 2020
1 parent 05cdf2c commit 910bf31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 910bf31

Please sign in to comment.