@@ -20,7 +20,7 @@ import org.schabi.newpipe.extractor.downloader.Response
20
20
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
21
21
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
22
22
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
23
- import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk
23
+ import org.schabi.newpipe.util.Version
24
24
import java.io.IOException
25
25
26
26
class NewVersionWorker (
@@ -34,19 +34,21 @@ class NewVersionWorker(
34
34
*
35
35
* @param versionName Name of new version
36
36
* @param apkLocationUrl Url with the new apk
37
- * @param versionCode Code of new version
38
37
*/
39
38
private fun compareAppVersionAndShowNotification (
40
39
versionName : String ,
41
- apkLocationUrl : String? ,
42
- versionCode : Int
40
+ apkLocationUrl : String?
43
41
) {
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) {
45
47
return
46
48
}
49
+
47
50
val app = App .getApp()
48
51
49
- // A pending intent to open the apk location url in the browser.
50
52
val intent = Intent (Intent .ACTION_VIEW , apkLocationUrl?.toUri())
51
53
intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
52
54
val pendingIntent = PendingIntent .getActivity(app, 0 , intent, 0 )
@@ -67,11 +69,6 @@ class NewVersionWorker(
67
69
68
70
@Throws(IOException ::class , ReCaptchaException ::class )
69
71
private fun checkNewVersion () {
70
- // Check if the current apk is a github one or not.
71
- if (! isReleaseApk()) {
72
- return
73
- }
74
-
75
72
val prefs = PreferenceManager .getDefaultSharedPreferences(applicationContext)
76
73
// Check if the last request has happened a certain time ago
77
74
// to reduce the number of API requests.
@@ -81,7 +78,7 @@ class NewVersionWorker(
81
78
}
82
79
83
80
// 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 )
85
82
handleResponse(response)
86
83
}
87
84
@@ -102,19 +99,18 @@ class NewVersionWorker(
102
99
103
100
// Parse the json from the response.
104
101
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)
113
109
} 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 .
115
111
// Do not alarm user and fail silently.
116
112
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)
118
114
}
119
115
}
120
116
}
@@ -135,7 +131,8 @@ class NewVersionWorker(
135
131
companion object {
136
132
private val DEBUG = MainActivity .DEBUG
137
133
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"
139
136
140
137
/* *
141
138
* Start a new worker which
0 commit comments