Remove old updater

This commit is contained in:
NekoInverter committed 2020-10-17 21:41:33 +08:00
1 parent e74e7b4a9d
commit b10df4f644
4 files changed
+5 -151

No files matched your search

@@ -18,60 +18,31 @@ package com.hippo.ehviewer.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.util.Log;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.hippo.app.ListCheckBoxDialogBuilder;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.UrlOpener;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhRequest;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.exception.EhException;
import com.hippo.ehviewer.dao.DownloadLabel;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.ehviewer.download.DownloadService;
import com.hippo.ehviewer.ui.scene.BaseScene;
import com.hippo.text.Html;
import com.hippo.unifile.UniFile;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.collect.LongList;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public final class CommonOperations {
private static final String TAG = CommonOperations.class.getSimpleName();
private static boolean UPDATING;
public static void checkUpdate(Activity activity, boolean feedback) {
/*if (!UPDATING) {
UPDATING = true;
new UpdateTask(activity, feedback).executeOnExecutor(IoThreadPoolExecutor.getInstance());
}*/
}
private static void doAddToFavorites(Activity activity, GalleryInfo galleryInfo,
int slot, EhClient.Callback<Void> listener) {
if (slot == -1) {
@@ -152,11 +123,11 @@ public final class CommonOperations {
intent.putExtra(DownloadService.KEY_GID_LIST, toStart);
try {
activity.startService(intent);
} catch (Exception e){
} catch (Exception e) {
// java.lang.IllegalStateException:
// Not allowed to start service Intent { act=start cmp=com.hippo.ehviewer/.download.DownloadService (has extras) }: app is in background uid null
e.printStackTrace();
return ;
return;
}
}
@@ -187,11 +158,11 @@ public final class CommonOperations {
intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
try {
activity.startService(intent);
} catch (Exception e){
} catch (Exception e) {
// java.lang.IllegalStateException:
// Not allowed to start service Intent { act=start cmp=com.hippo.ehviewer/.download.DownloadService (has extras) }: app is in background uid null
e.printStackTrace();
return ;
return;
}
}
// Notify
@@ -270,117 +241,6 @@ public final class CommonOperations {
}
}
private static final class UpdateTask extends AsyncTask<Void, Void, JSONObject> {
private final Activity mActivity;
private final OkHttpClient mHttpClient;
private final boolean mFeedback;
public UpdateTask(Activity activity, boolean feedback) {
mActivity = activity;
mHttpClient = EhApplication.getOkHttpClient(activity);
mFeedback = feedback;
}
private JSONObject fetchUpdateInfo(String url) throws IOException, JSONException {
Log.d(TAG, url);
Request request = new Request.Builder().url(url).build();
Response response = mHttpClient.newCall(request).execute();
return new JSONObject(response.body().string());
}
@Override
protected JSONObject doInBackground(Void... params) {
String url;
if (Settings.getBetaUpdateChannel()) {
url = "http://www.ehviewer.com/update_beta.json";
} else {
url = "http://www.ehviewer.com/update.json";
}
try {
return fetchUpdateInfo(url);
} catch (Throwable e1) {
ExceptionUtils.throwIfFatal(e1);
if (Settings.getBetaUpdateChannel()) {
url = "https://raw.githubusercontent.com/seven332/EhViewer/api/update_beta.json";
} else {
url = "https://raw.githubusercontent.com/seven332/EhViewer/api/update.json";
}
try {
return fetchUpdateInfo(url);
} catch (Throwable e2) {
ExceptionUtils.throwIfFatal(e2);
return null;
}
}
}
private void showUpToDateDialog() {
new MaterialAlertDialogBuilder(mActivity)
.setMessage(R.string.update_to_date)
.setPositiveButton(android.R.string.ok, null)
.show();
}
private void showUpdateDialog(String versionName, int versionCode, String size, CharSequence info, final String url) {
new MaterialAlertDialogBuilder(mActivity)
.setTitle(R.string.update)
.setMessage(mActivity.getString(R.string.update_plain, versionName, size, info))
.setPositiveButton(android.R.string.ok, (dialog, which) -> UrlOpener.openUrl(mActivity, url, false))
.setNegativeButton(R.string.update_ignore, (dialog, which) -> Settings.putSkipUpdateVersion(versionCode)).show();
}
private void handleResult(JSONObject jo) {
if (null == jo || mActivity.isFinishing()) {
return;
}
String versionName;
int versionCode;
String size;
CharSequence info;
String url;
try {
PackageManager pm = mActivity.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
int currentVersionCode = pi.versionCode;
versionCode = jo.getInt("version_code");
if (currentVersionCode >= versionCode) {
// Update to date
if (mFeedback) {
showUpToDateDialog();
}
return;
}
versionName = jo.getString("version_name");
size = FileUtils.humanReadableByteCount(jo.getLong("size"), false);
info = Html.fromHtml(jo.getString("info"));
url = jo.getString("url");
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
return;
}
if (mFeedback || versionCode != Settings.getSkipUpdateVersion()) {
showUpdateDialog(versionName, versionCode, size, info, url);
}
}
@Override
protected void onPostExecute(JSONObject jsonObject) {
try {
handleResult(jsonObject);
} finally {
UPDATING = false;
}
}
}
private static class DelegateFavoriteCallback implements EhClient.Callback<Void> {
private final EhClient.Callback<Void> delegate;