|
|
|
|
@ -27,18 +27,17 @@ public class Updater implements Download.Callback { |
|
|
|
|
private DialogUpdateBinding binding; |
|
|
|
|
private final Download download; |
|
|
|
|
private AlertDialog dialog; |
|
|
|
|
private boolean dev; |
|
|
|
|
|
|
|
|
|
private File getFile() { |
|
|
|
|
return Path.cache("update.apk"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getJson() { |
|
|
|
|
return Github.getJson(dev, BuildConfig.FLAVOR_mode); |
|
|
|
|
return Github.getJson(BuildConfig.FLAVOR_mode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getApk() { |
|
|
|
|
return Github.getApk(dev, BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_abi); |
|
|
|
|
return Github.getApk(BuildConfig.FLAVOR_mode + "-" + BuildConfig.FLAVOR_abi); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Updater create() { |
|
|
|
|
@ -55,36 +54,23 @@ public class Updater implements Download.Callback { |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Updater release() { |
|
|
|
|
this.dev = false; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Updater dev() { |
|
|
|
|
this.dev = true; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Updater check() { |
|
|
|
|
dismiss(); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void start(Activity activity) { |
|
|
|
|
if (!Setting.getUpdate()) return; |
|
|
|
|
App.execute(() -> doInBackground(activity)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean need(int code, String name) { |
|
|
|
|
return Setting.getUpdate() && (dev ? !name.equals(BuildConfig.VERSION_NAME) && code >= BuildConfig.VERSION_CODE : code > BuildConfig.VERSION_CODE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doInBackground(Activity activity) { |
|
|
|
|
try { |
|
|
|
|
JSONObject object = new JSONObject(OkHttp.string(getJson())); |
|
|
|
|
String name = object.optString("name"); |
|
|
|
|
String desc = object.optString("desc"); |
|
|
|
|
int code = object.optInt("code"); |
|
|
|
|
if (need(code, name)) App.post(() -> show(activity, name, desc)); |
|
|
|
|
if (code > BuildConfig.VERSION_CODE) App.post(() -> show(activity, name, desc)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
@ -105,7 +91,7 @@ public class Updater implements Download.Callback { |
|
|
|
|
private void cancel(View view) { |
|
|
|
|
Setting.putUpdate(false); |
|
|
|
|
download.cancel(); |
|
|
|
|
dialog.dismiss(); |
|
|
|
|
dismiss(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void confirm(View view) { |
|
|
|
|
|