Skip to content

Commit f1b15a9

Browse files
Show toast when no updates are available.
Co-authored-by: Stypox <stypox@pm.me>
1 parent 1d53389 commit f1b15a9

72 files changed

Lines changed: 142 additions & 204 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected void onPostCreate(final Bundle savedInstanceState) {
172172
if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
173173
// Start the worker which is checking all conditions
174174
// and eventually searching for a new version.
175-
NewVersionWorker.enqueueNewVersionCheckingWork(app);
175+
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
176176
}
177177
}
178178

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

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package org.schabi.newpipe
33
import android.content.Context
44
import android.content.Intent
55
import android.util.Log
6+
import android.widget.Toast
67
import androidx.core.app.NotificationCompat
78
import androidx.core.app.NotificationManagerCompat
9+
import androidx.core.content.ContextCompat
810
import androidx.core.content.edit
911
import androidx.core.net.toUri
1012
import androidx.preference.PreferenceManager
11-
import androidx.work.OneTimeWorkRequest
13+
import androidx.work.OneTimeWorkRequestBuilder
1214
import androidx.work.WorkManager
13-
import androidx.work.WorkRequest
1415
import androidx.work.Worker
1516
import androidx.work.WorkerParameters
17+
import androidx.work.workDataOf
1618
import com.grack.nanojson.JsonParser
1719
import com.grack.nanojson.JsonParserException
1820
import org.schabi.newpipe.extractor.downloader.Response
@@ -42,26 +44,34 @@ class NewVersionWorker(
4244
versionCode: Int
4345
) {
4446
if (BuildConfig.VERSION_CODE >= versionCode) {
47+
if (inputData.getBoolean(IS_MANUAL, false)) {
48+
// Show toast stating that the app is up-to-date if the update check was manual.
49+
ContextCompat.getMainExecutor(applicationContext).execute {
50+
Toast.makeText(applicationContext, R.string.app_update_unavailable_toast,
51+
Toast.LENGTH_SHORT).show()
52+
}
53+
}
4554
return
4655
}
47-
val app = App.getApp()
4856

4957
// A pending intent to open the apk location url in the browser.
5058
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
5159
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
52-
val pendingIntent = PendingIntentCompat.getActivity(app, 0, intent, 0)
53-
val channelId = app.getString(R.string.app_update_notification_channel_id)
54-
val notificationBuilder = NotificationCompat.Builder(app, channelId)
60+
val pendingIntent = PendingIntentCompat.getActivity(
61+
applicationContext, 0, intent, 0
62+
)
63+
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
64+
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
5565
.setSmallIcon(R.drawable.ic_newpipe_update)
5666
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
57-
.setContentIntent(pendingIntent)
5867
.setAutoCancel(true)
59-
.setContentTitle(app.getString(R.string.app_update_notification_content_title))
60-
.setContentText(
61-
app.getString(R.string.app_update_notification_content_text) +
62-
" " + versionName
63-
)
64-
val notificationManager = NotificationManagerCompat.from(app)
68+
.setContentIntent(pendingIntent)
69+
.setContentTitle(applicationContext.getString(
70+
R.string.app_update_available_notification_title))
71+
.setContentText(applicationContext.getString(
72+
R.string.app_update_available_notification_text, versionName))
73+
74+
val notificationManager = NotificationManagerCompat.from(applicationContext)
6575
notificationManager.notify(2000, notificationBuilder.build())
6676
}
6777

@@ -72,12 +82,14 @@ class NewVersionWorker(
7282
return
7383
}
7484

75-
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
76-
// Check if the last request has happened a certain time ago
77-
// to reduce the number of API requests.
78-
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
79-
if (!isLastUpdateCheckExpired(expiry)) {
80-
return
85+
if (!inputData.getBoolean(IS_MANUAL, false)) {
86+
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
87+
// Check if the last request has happened a certain time ago
88+
// to reduce the number of API requests.
89+
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
90+
if (!isLastUpdateCheckExpired(expiry)) {
91+
return
92+
}
8193
}
8294

8395
// Make a network request to get latest NewPipe data.
@@ -120,43 +132,42 @@ class NewVersionWorker(
120132
}
121133

122134
override fun doWork(): Result {
123-
try {
135+
return try {
124136
checkNewVersion()
137+
Result.success()
125138
} catch (e: IOException) {
126139
Log.w(TAG, "Could not fetch NewPipe API: probably network problem", e)
127-
return Result.failure()
140+
Result.failure()
128141
} catch (e: ReCaptchaException) {
129142
Log.e(TAG, "ReCaptchaException should never happen here.", e)
130-
return Result.failure()
143+
Result.failure()
131144
}
132-
return Result.success()
133145
}
134146

135147
companion object {
136148
private val DEBUG = MainActivity.DEBUG
137149
private val TAG = NewVersionWorker::class.java.simpleName
138150
private const val NEWPIPE_API_URL = "https://newpipe.net/api/data.json"
151+
private const val IS_MANUAL = "isManual"
139152

140153
/**
141-
* Start a new worker which
142-
* checks if all conditions for performing a version check are met,
143-
* fetches the API endpoint [.NEWPIPE_API_URL] containing info
144-
* about the latest NewPipe version
145-
* and displays a notification about ana available update.
154+
* Start a new worker which checks if all conditions for performing a version check are met,
155+
* fetches the API endpoint [.NEWPIPE_API_URL] containing info about the latest NewPipe
156+
* version and displays a notification about an available update if one is available.
146157
* <br></br>
147-
* Following conditions need to be met, before data is request from the server:
158+
* Following conditions need to be met, before data is requested from the server:
148159
*
149160
* * The app is signed with the correct signing key (by TeamNewPipe / schabi).
150161
* If the signing key differs from the one used upstream, the update cannot be installed.
151162
* * The user enabled searching for and notifying about updates in the settings.
152163
* * The app did not recently check for updates.
153164
* We do not want to make unnecessary connections and DOS our servers.
154-
*
155165
*/
156166
@JvmStatic
157-
fun enqueueNewVersionCheckingWork(context: Context) {
158-
val workRequest: WorkRequest =
159-
OneTimeWorkRequest.Builder(NewVersionWorker::class.java).build()
167+
fun enqueueNewVersionCheckingWork(context: Context, isManual: Boolean) {
168+
val workRequest = OneTimeWorkRequestBuilder<NewVersionWorker>()
169+
.setInputData(workDataOf(IS_MANUAL to isManual))
170+
.build()
160171
WorkManager.getInstance(context).enqueue(workRequest)
161172
}
162173
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,17 @@ public class UpdateSettingsFragment extends BasePreferenceFragment {
1616
.apply();
1717

1818
if (checkForUpdates) {
19-
checkNewVersionNow();
19+
NewVersionWorker.enqueueNewVersionCheckingWork(requireContext(), true);
2020
}
2121
return true;
2222
};
2323

2424
private final Preference.OnPreferenceClickListener manualUpdateClick = preference -> {
2525
Toast.makeText(getContext(), R.string.checking_updates_toast, Toast.LENGTH_SHORT).show();
26-
checkNewVersionNow();
26+
NewVersionWorker.enqueueNewVersionCheckingWork(requireContext(), true);
2727
return true;
2828
};
2929

30-
private void checkNewVersionNow() {
31-
// Search for updates immediately when update checks are enabled.
32-
// Reset the expire time. This is necessary to check for an update immediately.
33-
defaultPreferences.edit()
34-
.putLong(getString(R.string.update_expiry_key), 0).apply();
35-
NewVersionWorker.enqueueNewVersionCheckingWork(getContext());
36-
}
37-
3830
@Override
3931
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
4032
addPreferencesFromResourceRegistry();

app/src/main/res/values-ar/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@
370370
<string name="list">القائمة</string>
371371
<string name="grid">الشبكة</string>
372372
<string name="auto">تلقائي</string>
373-
<string name="app_update_notification_content_title">تحديث NewPipe متاح!</string>
374-
<string name="app_update_notification_content_text">اضغط لتنزيل</string>
373+
<string name="app_update_available_notification_title">تحديث NewPipe متاح!</string>
375374
<string name="missions_header_finished">انتهى</string>
376375
<string name="missions_header_pending">ريثما</string>
377376
<string name="paused">متوقف</string>

app/src/main/res/values-az/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@
485485
<string name="queued">növbədədir</string>
486486
<string name="post_processing">sonrakı emal olunur</string>
487487
<string name="checking_updates_toast">Yeniləmələr yoxlanılır…</string>
488-
<string name="app_update_notification_content_title">NewPipe yeniləməsi mövcuddur!</string>
488+
<string name="app_update_available_notification_title">NewPipe yeniləməsi mövcuddur!</string>
489489
<string name="metadata_licence">Lisenziya</string>
490490
<string name="feed_load_error_terminated">Müəllifin hesabı bağlanıb.
491491
\nNewPipe gələcəkdə bu axını yükləyə bilməyəcək.
@@ -572,7 +572,6 @@
572572
<string name="recovering">bərpa olunur</string>
573573
<string name="paused">dayandırıldı</string>
574574
<string name="missions_header_finished">Bitdi</string>
575-
<string name="app_update_notification_content_text">Endirmək üçün toxun</string>
576575
<string name="minimize_on_exit_none_description">Heç biri</string>
577576
<string name="minimize_on_exit_summary">Əsas video oynadıcıdan digər tətbiqə keçid zamanı hərəkət — %s</string>
578577
<string name="decline">İmtina</string>

app/src/main/res/values-b+ast/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@
236236
<string name="subscribed_button_title">Soscribiéstite</string>
237237
<string name="no_videos">Nun hai vídeos</string>
238238
<string name="delete_search_history_alert">¿Desaniciar tol historial de busques\?</string>
239-
<string name="app_update_notification_content_title">¡Hai un anovamientu pa NewPipe!</string>
240-
<string name="app_update_notification_content_text">Toca pa baxalu</string>
239+
<string name="app_update_available_notification_title">¡Hai un anovamientu pa NewPipe!</string>
241240
<string name="error_progress_lost">Perdióse\'l progresu porque se desanició\'l ficheru</string>
242241
<string name="peertube_instance_url_title">Instancies de PeerTube</string>
243242
<string name="peertube_instance_add_exists">La instancia yá esiste</string>

app/src/main/res/values-b+uz+Latn/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@
453453
<string name="paused">to\'xtatildi</string>
454454
<string name="missions_header_pending">Kutilmoqda</string>
455455
<string name="missions_header_finished">Tugatildi</string>
456-
<string name="app_update_notification_content_text">Yuklash uchun bosing</string>
457-
<string name="app_update_notification_content_title">NewPipe yangilanishi mavjud!</string>
456+
<string name="app_update_available_notification_title">NewPipe yangilanishi mavjud!</string>
458457
<string name="auto">Avto</string>
459458
<string name="grid">Tarmoq</string>
460459
<string name="list">Ro\'yxat</string>

app/src/main/res/values-be/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@
355355
<string name="list">Спіс</string>
356356
<string name="grid">Сетка</string>
357357
<string name="auto">Аўтаматычна</string>
358-
<string name="app_update_notification_content_title">Даступна абнаўленне NewPipe!</string>
359-
<string name="app_update_notification_content_text">Націсніце для загрузкі</string>
358+
<string name="app_update_available_notification_title">Даступна абнаўленне NewPipe!</string>
360359
<string name="missions_header_finished">Скончана</string>
361360
<string name="missions_header_pending">У чарзе</string>
362361
<string name="paused">прыпынена</string>

app/src/main/res/values-bg/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@
398398
<string name="wifi_only">Само при Wi-Fi</string>
399399
<string name="list_view_mode">Вид на списъка</string>
400400
<string name="enable_playback_resume_summary">Възстанови последната позиция</string>
401-
<string name="app_update_notification_content_title">Нова версия на NewPipe е налична!</string>
401+
<string name="app_update_available_notification_title">Нова версия на NewPipe е налична!</string>
402402
<string name="seekbar_preview_thumbnail_title">Миниатюри на лентата за превъртане</string>
403403
<string name="low_quality_smaller">Нискокачествени (малки)</string>
404-
<string name="app_update_notification_content_text">Докоснете за изтегляне</string>
405404
<string name="queued">на опашка</string>
406405
<string name="updates_setting_title">Актуализации</string>
407406
<string name="overwrite">Презаписване</string>

app/src/main/res/values-bn-rBD/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
<string name="show_error">এরর দেখান</string>
179179
<string name="download_failed">ডাউনলোড ব্যর্থ হয়েছে</string>
180180
<string name="paused">স্থগিত</string>
181-
<string name="app_update_notification_content_text">ডাউনলোড করতে টোকা দিন</string>
182181
<string name="auto">অটো</string>
183182
<string name="limit_data_usage_none_description">সীমাহীন</string>
184183
<string name="caption_none">কোন ক্যাপশন নেই</string>
@@ -392,7 +391,7 @@
392391
<string name="notification_action_4_title">পঞ্চম পদক্ষেপ বোতাম</string>
393392
<string name="show_description_summary">ভিডিও বর্ণনা ও বাড়তি তথ্য লুকাতে বন্ধ করুন</string>
394393
<string name="dont_show">দেখিও না</string>
395-
<string name="app_update_notification_content_title">নিউ পাইপ আপডেট এসেছে!</string>
394+
<string name="app_update_available_notification_title">নিউ পাইপ আপডেট এসেছে!</string>
396395
<string name="comments_are_disabled">মন্তব্যসমূহ নিষ্ক্রিয় আছে</string>
397396
<plurals name="views">
398397
<item quantity="one">%s বার দেখেছে</item>

0 commit comments

Comments
 (0)