1
0
Fork 0
mirror of https://github.com/KokaKiwi/BarInsta synced 2026-03-05 20:11:36 +00:00

Merge branch 'master' into task/update-feed-view

This commit is contained in:
Austin Huang 2020-09-08 15:44:04 -04:00 committed by GitHub
commit 1ea631e760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 483 additions and 76 deletions

View file

@ -3,15 +3,17 @@ package awais.instagrabber.utils;
import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.NonNull;
import org.json.JSONObject;
import java.net.HttpURLConnection;
import java.net.URL;
import awais.instagrabber.BuildConfig;
import awais.instagrabber.interfaces.FetchListener;
public final class UpdateChecker extends AsyncTask<Void, Void, String> {
private static final String TAG = "UpdateChecker";
public final class UpdateChecker extends AsyncTask<Void, Void, Boolean> {
private final FetchListener<String> fetchListener;
private String version;
@ -19,38 +21,38 @@ public final class UpdateChecker extends AsyncTask<Void, Void, String> {
this.fetchListener = fetchListener;
}
@NonNull
@Override
protected String doInBackground(final Void... voids) {
HttpURLConnection conn = null;
protected Boolean doInBackground(final Void... voids) {
try {
conn = (HttpURLConnection) new URL("https://github.com/austinhuang0131/instagrabber/releases/latest").openConnection();
conn.setInstanceFollowRedirects(false);
version = "";
HttpURLConnection conn =
(HttpURLConnection) new URL("https://f-droid.org/api/v1/packages/me.austinhuang.instagrabber").openConnection();
conn.setUseCaches(false);
conn.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
conn.connect();
final int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {
version = conn.getHeaderField("Location").split("/v")[1];
return version;
if (responseCode == HttpURLConnection.HTTP_OK) {
final JSONObject data = new JSONObject(Utils.readFromConnection(conn));
if (BuildConfig.VERSION_CODE < data.getInt("suggestedVersionCode")) {
version = data.getJSONArray("packages").getString("versionName");
return true;
}
}
conn.disconnect();
} catch (final Exception e) {
if (BuildConfig.DEBUG) Log.e(TAG, "", e);
} finally {
if (conn != null) {
conn.disconnect();
}
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
}
return null;
return false;
}
@Override
protected void onPostExecute(final String result) {
if (result == null || fetchListener == null) {
return;
}
fetchListener.onResult(version);
protected void onPostExecute(final Boolean result) {
if (result != null && result && fetchListener != null)
fetchListener.onResult("v"+version);
}
}