Browse Source
implement F-Droid update checker
renovate/org.robolectric-robolectric-4.x
Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
1 changed files with
9 additions and
5 deletions
-
app/src/main/java/awais/instagrabber/utils/UpdateChecker.java
|
|
@ -5,6 +5,8 @@ import android.util.Log; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
|
|
|
@ -26,16 +28,18 @@ public final class UpdateChecker extends AsyncTask<Void, Void, Boolean> { |
|
|
|
version = ""; |
|
|
|
|
|
|
|
HttpURLConnection conn = |
|
|
|
(HttpURLConnection) new URL("https://github.com/austinhuang0131/instagrabber/releases/latest").openConnection(); |
|
|
|
conn.setInstanceFollowRedirects(false); |
|
|
|
(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.equals(BuildConfig.VERSION_NAME); |
|
|
|
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(); |
|
|
|