Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit 50ba525

Browse files
restoring fork-specific update functionality
1 parent 29feaeb commit 50ba525

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.schabi.newpipe.extractor.downloader.Response
2020
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
2121
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
2222
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
23-
import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk
23+
import org.schabi.newpipe.util.Version
2424
import java.io.IOException
2525

2626
class NewVersionWorker(
@@ -34,19 +34,21 @@ class NewVersionWorker(
3434
*
3535
* @param versionName Name of new version
3636
* @param apkLocationUrl Url with the new apk
37-
* @param versionCode Code of new version
3837
*/
3938
private fun compareAppVersionAndShowNotification(
4039
versionName: String,
41-
apkLocationUrl: String?,
42-
versionCode: Int
40+
apkLocationUrl: String?
4341
) {
44-
if (BuildConfig.VERSION_CODE >= versionCode) {
42+
val sourceVersion = Version.fromString(BuildConfig.VERSION_NAME)
43+
val targetVersion = Version.fromString(versionName)
44+
45+
// abort if source version is the same or newer than target version
46+
if (sourceVersion >= targetVersion) {
4547
return
4648
}
49+
4750
val app = App.getApp()
4851

49-
// A pending intent to open the apk location url in the browser.
5052
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
5153
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
5254
val pendingIntent = PendingIntent.getActivity(app, 0, intent, 0)
@@ -67,11 +69,6 @@ class NewVersionWorker(
6769

6870
@Throws(IOException::class, ReCaptchaException::class)
6971
private fun checkNewVersion() {
70-
// Check if the current apk is a github one or not.
71-
if (!isReleaseApk()) {
72-
return
73-
}
74-
7572
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
7673
// Check if the last request has happened a certain time ago
7774
// to reduce the number of API requests.
@@ -81,7 +78,7 @@ class NewVersionWorker(
8178
}
8279

8380
// Make a network request to get latest NewPipe data.
84-
val response = DownloaderImpl.getInstance().get(NEWPIPE_API_URL)
81+
val response = DownloaderImpl.getInstance().get(API_URL)
8582
handleResponse(response)
8683
}
8784

@@ -102,19 +99,18 @@ class NewVersionWorker(
10299

103100
// Parse the json from the response.
104101
try {
105-
val githubStableObject = JsonParser.`object`()
106-
.from(response.responseBody()).getObject("flavors")
107-
.getObject("github").getObject("stable")
108-
109-
val versionName = githubStableObject.getString("version")
110-
val versionCode = githubStableObject.getInt("version_code")
111-
val apkLocationUrl = githubStableObject.getString("apk")
112-
compareAppVersionAndShowNotification(versionName, apkLocationUrl, versionCode)
102+
val jObj = JsonParser.`object`().from(response.responseBody())
103+
val versionName = jObj.getString("tag_name")
104+
val apkLocationUrl = jObj
105+
.getArray("assets")
106+
.getObject(0)
107+
.getString("browser_download_url")
108+
compareAppVersionAndShowNotification(versionName, apkLocationUrl)
113109
} catch (e: JsonParserException) {
114-
// Most likely something is wrong in data received from NEWPIPE_API_URL.
110+
// Most likely something is wrong in data received from API_URL.
115111
// Do not alarm user and fail silently.
116112
if (DEBUG) {
117-
Log.w(TAG, "Could not get NewPipe API: invalid json", e)
113+
Log.w(TAG, "Could not get Github API: invalid json", e)
118114
}
119115
}
120116
}
@@ -135,7 +131,8 @@ class NewVersionWorker(
135131
companion object {
136132
private val DEBUG = MainActivity.DEBUG
137133
private val TAG = NewVersionWorker::class.java.simpleName
138-
private const val NEWPIPE_API_URL = "https://newpipe.net/api/data.json"
134+
private const val API_URL =
135+
"https://api.github.com/repos/polymorphicshade/NewPipe/releases/latest"
139136

140137
/**
141138
* Start a new worker which

app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.schabi.newpipe.MainActivity;
1111
import org.schabi.newpipe.R;
12-
import org.schabi.newpipe.util.ReleaseVersionUtil;
1312

1413
public class MainSettingsFragment extends BasePreferenceFragment {
1514
public static final boolean DEBUG = MainActivity.DEBUG;
@@ -22,14 +21,6 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
2221

2322
setHasOptionsMenu(true); // Otherwise onCreateOptionsMenu is not called
2423

25-
// Check if the app is updatable
26-
if (!ReleaseVersionUtil.isReleaseApk()) {
27-
getPreferenceScreen().removePreference(
28-
findPreference(getString(R.string.update_pref_screen_key)));
29-
30-
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
31-
}
32-
3324
// Hide debug preferences in RELEASE build variant
3425
if (!DEBUG) {
3526
getPreferenceScreen().removePreference(

0 commit comments

Comments
 (0)