mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
implement F-Droid update checker
This commit is contained in:
parent
1f2f526eb6
commit
93b80a7147
@ -5,6 +5,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
@ -26,16 +28,18 @@ public final class UpdateChecker extends AsyncTask<Void, Void, Boolean> {
|
|||||||
version = "";
|
version = "";
|
||||||
|
|
||||||
HttpURLConnection conn =
|
HttpURLConnection conn =
|
||||||
(HttpURLConnection) new URL("https://github.com/austinhuang0131/instagrabber/releases/latest").openConnection();
|
(HttpURLConnection) new URL("https://f-droid.org/api/v1/packages/me.austinhuang.instagrabber").openConnection();
|
||||||
conn.setInstanceFollowRedirects(false);
|
|
||||||
conn.setUseCaches(false);
|
conn.setUseCaches(false);
|
||||||
conn.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
|
conn.setRequestProperty("User-Agent", Constants.A_USER_AGENT);
|
||||||
conn.connect();
|
conn.connect();
|
||||||
|
|
||||||
final int responseCode = conn.getResponseCode();
|
final int responseCode = conn.getResponseCode();
|
||||||
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
version = conn.getHeaderField("Location").split("/v")[1];
|
final JSONObject data = new JSONObject(Utils.readFromConnection(conn));
|
||||||
return !version.equals(BuildConfig.VERSION_NAME);
|
if (BuildConfig.VERSION_CODE < data.getInt("suggestedVersionCode")) {
|
||||||
|
version = data.getJSONArray("packages").getString("versionName");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
Loading…
Reference in New Issue
Block a user