|
|
|
|
@@ -14,14 +14,12 @@ import android.os.Build;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
|
|
|
|
|
|
import org.joinmastodon.android.BuildConfig;
|
|
|
|
|
import org.joinmastodon.android.E;
|
|
|
|
|
import org.joinmastodon.android.GlobalUserPreferences;
|
|
|
|
|
import org.joinmastodon.android.MastodonApp;
|
|
|
|
|
import org.joinmastodon.android.R;
|
|
|
|
|
import org.joinmastodon.android.api.MastodonAPIController;
|
|
|
|
|
@@ -119,66 +117,60 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
|
|
|
|
|
.build();
|
|
|
|
|
Call call=MastodonAPIController.getHttpClient().newCall(req);
|
|
|
|
|
try(Response resp=call.execute()){
|
|
|
|
|
JsonArray arr=JsonParser.parseReader(resp.body().charStream()).getAsJsonArray();
|
|
|
|
|
for (JsonElement jsonElement : arr) {
|
|
|
|
|
JsonObject obj = jsonElement.getAsJsonObject();
|
|
|
|
|
if (obj.get("prerelease").getAsBoolean() && !GlobalUserPreferences.enablePreReleases) continue;
|
|
|
|
|
JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject();
|
|
|
|
|
String changelog=obj.get("body").getAsString();
|
|
|
|
|
String tag=obj.get("tag_name").getAsString();
|
|
|
|
|
Pattern pattern=Pattern.compile("v?(\\d+)\\.(\\d+)\\.(\\d+)\\+fork\\.(\\d+)");
|
|
|
|
|
Matcher matcher=pattern.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)),
|
|
|
|
|
newForkNumber=Integer.parseInt(matcher.group(4));
|
|
|
|
|
matcher=pattern.matcher(BuildConfig.VERSION_NAME);
|
|
|
|
|
String[] currentParts=BuildConfig.VERSION_NAME.split("[.+]");
|
|
|
|
|
if(!matcher.find()){
|
|
|
|
|
Log.w(TAG, "actuallyCheckForUpdates: current version has wrong format: "+BuildConfig.VERSION_NAME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int curMajor=Integer.parseInt(matcher.group(1)),
|
|
|
|
|
curMinor=Integer.parseInt(matcher.group(2)),
|
|
|
|
|
curRevision=Integer.parseInt(matcher.group(3)),
|
|
|
|
|
curForkNumber=Integer.parseInt(matcher.group(4));
|
|
|
|
|
long newVersion=((long)newMajor << 32) | ((long)newMinor << 16) | newRevision;
|
|
|
|
|
long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision;
|
|
|
|
|
if(newVersion>curVersion || newForkNumber>curForkNumber){
|
|
|
|
|
String version=newMajor+"."+newMinor+"."+newRevision+"+fork."+newForkNumber;
|
|
|
|
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
|
|
|
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
|
|
|
|
JsonObject asset=el.getAsJsonObject();
|
|
|
|
|
if("moshidon.apk".equals(asset.get("name").getAsString()) && "application/vnd.android.package-archive".equals(asset.get("content_type").getAsString()) && "uploaded".equals(asset.get("state").getAsString())){
|
|
|
|
|
long size=asset.get("size").getAsLong();
|
|
|
|
|
String url=asset.get("browser_download_url").getAsString();
|
|
|
|
|
|
|
|
|
|
String tag=obj.get("tag_name").getAsString();
|
|
|
|
|
String changelog=obj.get("body").getAsString();
|
|
|
|
|
Pattern pattern=Pattern.compile("v?(\\d+)\\.(\\d+)\\.(\\d+)\\+fork\\.(\\d+)");
|
|
|
|
|
Matcher matcher=pattern.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)),
|
|
|
|
|
newForkNumber=Integer.parseInt(matcher.group(4));
|
|
|
|
|
matcher=pattern.matcher(BuildConfig.VERSION_NAME);
|
|
|
|
|
String[] currentParts=BuildConfig.VERSION_NAME.split("[.+]");
|
|
|
|
|
if(!matcher.find()){
|
|
|
|
|
Log.w(TAG, "actuallyCheckForUpdates: current version has wrong format: "+BuildConfig.VERSION_NAME);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int curMajor=Integer.parseInt(matcher.group(1)),
|
|
|
|
|
curMinor=Integer.parseInt(matcher.group(2)),
|
|
|
|
|
curRevision=Integer.parseInt(matcher.group(3)),
|
|
|
|
|
curForkNumber=Integer.parseInt(matcher.group(4));
|
|
|
|
|
long newVersion=((long)newMajor << 32) | ((long)newMinor << 16) | newRevision;
|
|
|
|
|
long curVersion=((long)curMajor << 32) | ((long)curMinor << 16) | curRevision;
|
|
|
|
|
if(newVersion>curVersion || newForkNumber>curForkNumber){
|
|
|
|
|
String version=newMajor+"."+newMinor+"."+newRevision+"+fork."+newForkNumber;
|
|
|
|
|
Log.d(TAG, "actuallyCheckForUpdates: new version: "+version);
|
|
|
|
|
for(JsonElement el:obj.getAsJsonArray("assets")){
|
|
|
|
|
JsonObject asset=el.getAsJsonObject();
|
|
|
|
|
if("moshidon.apk".equals(asset.get("name").getAsString()) && "application/vnd.android.package-archive".equals(asset.get("content_type").getAsString()) && "uploaded".equals(asset.get("state").getAsString())){
|
|
|
|
|
long size=asset.get("size").getAsLong();
|
|
|
|
|
String url=asset.get("browser_download_url").getAsString();
|
|
|
|
|
UpdateInfo info=new UpdateInfo();
|
|
|
|
|
info.size=size;
|
|
|
|
|
info.version=version;
|
|
|
|
|
info.changelog=changelog;
|
|
|
|
|
this.info=info;
|
|
|
|
|
|
|
|
|
|
UpdateInfo info=new UpdateInfo();
|
|
|
|
|
info.size=size;
|
|
|
|
|
info.version=version;
|
|
|
|
|
info.changelog=changelog;
|
|
|
|
|
this.info=info;
|
|
|
|
|
getPrefs().edit()
|
|
|
|
|
.putLong("apkSize", size)
|
|
|
|
|
.putString("version", version)
|
|
|
|
|
.putString("apkURL", url)
|
|
|
|
|
.putInt("checkedByBuild", BuildConfig.VERSION_CODE)
|
|
|
|
|
.putString("changelog", changelog)
|
|
|
|
|
.remove("downloadID")
|
|
|
|
|
.apply();
|
|
|
|
|
|
|
|
|
|
getPrefs().edit()
|
|
|
|
|
.putLong("apkSize", size)
|
|
|
|
|
.putString("version", version)
|
|
|
|
|
.putString("apkURL", url)
|
|
|
|
|
.putString("changelog", changelog)
|
|
|
|
|
.putInt("checkedByBuild", BuildConfig.VERSION_CODE)
|
|
|
|
|
.remove("downloadID")
|
|
|
|
|
.apply();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getPrefs().edit().putLong("lastCheck", System.currentTimeMillis()).apply();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
getPrefs().edit().putLong("lastCheck", System.currentTimeMillis()).apply();
|
|
|
|
|
}catch(Exception x){
|
|
|
|
|
Log.w(TAG, "actuallyCheckForUpdates", x);
|
|
|
|
|
}finally{
|
|
|
|
|
|