|
|
|
@@ -94,8 +94,8 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
|
|
|
public void maybeCheckForUpdates(){
|
|
|
|
public void maybeCheckForUpdates(){
|
|
|
|
if(state!=UpdateState.NO_UPDATE && state!=UpdateState.UPDATE_AVAILABLE)
|
|
|
|
if(state!=UpdateState.NO_UPDATE && state!=UpdateState.UPDATE_AVAILABLE)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
long timeSinceLastCheck=System.currentTimeMillis()-getPrefs().getLong("lastCheck", 0);
|
|
|
|
long timeSinceLastCheck=System.currentTimeMillis()-getPrefs().getLong("lastCheck", CHECK_PERIOD);
|
|
|
|
if(timeSinceLastCheck>CHECK_PERIOD){
|
|
|
|
if(timeSinceLastCheck>=CHECK_PERIOD){
|
|
|
|
setState(UpdateState.CHECKING);
|
|
|
|
setState(UpdateState.CHECKING);
|
|
|
|
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
|
|
|
|
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -103,24 +103,31 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
|
|
|
|
|
|
|
|
|
|
|
private void actuallyCheckForUpdates(){
|
|
|
|
private void actuallyCheckForUpdates(){
|
|
|
|
Request req=new Request.Builder()
|
|
|
|
Request req=new Request.Builder()
|
|
|
|
.url("https://api.github.com/repos/mastodon/mastodon-android/releases/latest")
|
|
|
|
.url("https://api.github.com/repos/sk22/mastodon-android-fork/releases/latest")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
|
|
|
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
|
|
|
try(Response resp=call.execute()){
|
|
|
|
try(Response resp=call.execute()){
|
|
|
|
JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject();
|
|
|
|
JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject();
|
|
|
|
String tag=obj.get("tag_name").getAsString();
|
|
|
|
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()){
|
|
|
|
if(!matcher.find()){
|
|
|
|
Log.w(TAG, "actuallyCheckForUpdates: release tag has wrong format: "+tag);
|
|
|
|
Log.w(TAG, "actuallyCheckForUpdates: release tag has wrong format: "+tag);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int newMajor=Integer.parseInt(matcher.group(1)), newMinor=Integer.parseInt(matcher.group(2)), newRevision=Integer.parseInt(matcher.group(3));
|
|
|
|
int newMajor=Integer.parseInt(matcher.group(1)),
|
|
|
|
String[] currentParts=BuildConfig.VERSION_NAME.split("\\.");
|
|
|
|
newMinor=Integer.parseInt(matcher.group(2)),
|
|
|
|
int curMajor=Integer.parseInt(currentParts[0]), curMinor=Integer.parseInt(currentParts[1]), curRevision=Integer.parseInt(currentParts[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 newVersion=((long)newMajor << 32) | ((long)newMinor << 16) | newRevision;
|
|
|
|
long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision;
|
|
|
|
long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision;
|
|
|
|
if(newVersion>curVersion || BuildConfig.DEBUG){
|
|
|
|
if(newVersion>curVersion || newForkNumber>curForkNumber || BuildConfig.DEBUG){
|
|
|
|
String version=newMajor+"."+newMinor+"."+newRevision;
|
|
|
|
String version=newMajor+"."+newMinor+"."+newRevision+"+fork."+newForkNumber;
|
|
|
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
|
|
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
|
|
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
|
|
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
|
|
|
JsonObject asset=el.getAsJsonObject();
|
|
|
|
JsonObject asset=el.getAsJsonObject();
|
|
|
|
|