From 596799bf2fac9079ea10828589713bbcc5032ff4 Mon Sep 17 00:00:00 2001 From: sk Date: Tue, 1 Nov 2022 23:27:50 +0100 Subject: [PATCH] enable github update check --- mastodon/build.gradle | 7 ++++-- .../updater/GithubSelfUpdaterImpl.java | 23 ++++++++++++------- .../android/updater/GithubSelfUpdater.java | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 1b0e11bf6d..6e65ac2a84 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.joinmastodon.android.sk" minSdk 23 targetSdk 33 - versionCode 23 - versionName "1.1.3+fork.23" + versionCode 24 + versionName "1.1.3+fork.24" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -52,6 +52,9 @@ android { githubRelease{ setRoot "src/github" } + debug { + setRoot "src/github" + } } lintOptions{ checkReleaseBuilds false diff --git a/mastodon/src/github/java/org/joinmastodon/android/updater/GithubSelfUpdaterImpl.java b/mastodon/src/github/java/org/joinmastodon/android/updater/GithubSelfUpdaterImpl.java index a9642dbf0a..37929b089e 100644 --- a/mastodon/src/github/java/org/joinmastodon/android/updater/GithubSelfUpdaterImpl.java +++ b/mastodon/src/github/java/org/joinmastodon/android/updater/GithubSelfUpdaterImpl.java @@ -94,8 +94,8 @@ private SharedPreferences getPrefs(){ public void maybeCheckForUpdates(){ if(state!=UpdateState.NO_UPDATE && state!=UpdateState.UPDATE_AVAILABLE) return; - long timeSinceLastCheck=System.currentTimeMillis()-getPrefs().getLong("lastCheck", 0); - if(timeSinceLastCheck>CHECK_PERIOD){ + long timeSinceLastCheck=System.currentTimeMillis()-getPrefs().getLong("lastCheck", CHECK_PERIOD); + if(timeSinceLastCheck>=CHECK_PERIOD){ setState(UpdateState.CHECKING); MastodonAPIController.runInBackground(this::actuallyCheckForUpdates); } @@ -109,18 +109,25 @@ private void actuallyCheckForUpdates(){ try(Response resp=call.execute()){ JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject(); String tag=obj.get("tag_name").getAsString(); - Matcher matcher=Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)").matcher(tag); + Matcher matcher=Pattern.compile("v(\\d+)\\.(\\d+)\\.(\\d+)\\+fork\\.(\\d+)").matcher(tag); if(!matcher.find()){ Log.w(TAG, "actuallyCheckForUpdates: release tag has wrong format: "+tag); return; } - int newMajor=Integer.parseInt(matcher.group(1)), newMinor=Integer.parseInt(matcher.group(2)), newRevision=Integer.parseInt(matcher.group(3)); - String[] currentParts=BuildConfig.VERSION_NAME.split("\\."); - int curMajor=Integer.parseInt(currentParts[0]), curMinor=Integer.parseInt(currentParts[1]), curRevision=Integer.parseInt(currentParts[2]); + int newMajor=Integer.parseInt(matcher.group(1)), + newMinor=Integer.parseInt(matcher.group(2)), + newRevision=Integer.parseInt(matcher.group(3)), + newForkNumber=Integer.parseInt(matcher.group(4)); + + String[] currentParts=BuildConfig.VERSION_NAME.split("[.+]"); + int curMajor=Integer.parseInt(currentParts[0]), + curMinor=Integer.parseInt(currentParts[1]), + curRevision=Integer.parseInt(currentParts[2]), + curForkNumber=Integer.parseInt(currentParts[4]); long newVersion=((long)newMajor << 32) | ((long)newMinor << 16) | newRevision; long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision; - if(newVersion>curVersion || BuildConfig.DEBUG){ - String version=newMajor+"."+newMinor+"."+newRevision; + if(newVersion>curVersion || newForkNumber>curForkNumber || BuildConfig.DEBUG){ + String version=newMajor+"."+newMinor+"."+newRevision+"+fork."+newForkNumber; Log.d(TAG, "actuallyCheckForUpdates: new version: "+version); for(JsonElement el:obj.getAsJsonArray("assets")){ JsonObject asset=el.getAsJsonObject(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/updater/GithubSelfUpdater.java b/mastodon/src/main/java/org/joinmastodon/android/updater/GithubSelfUpdater.java index 810c516dc5..25d665f18b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/updater/GithubSelfUpdater.java +++ b/mastodon/src/main/java/org/joinmastodon/android/updater/GithubSelfUpdater.java @@ -20,7 +20,7 @@ public static GithubSelfUpdater getInstance(){ } public static boolean needSelfUpdating(){ - return BuildConfig.BUILD_TYPE.equals("githubRelease"); + return BuildConfig.BUILD_TYPE.equals("githubRelease") || BuildConfig.BUILD_TYPE.equals("debug"); } public abstract void maybeCheckForUpdates();