Skip to content

Commit 730664e

Browse files
authored
Merge pull request #8668 from Isira-Seneviratne/Show_no_update_notification
Show toast when no updates are available.
2 parents 1d53389 + 6b210e1 commit 730664e

72 files changed

Lines changed: 146 additions & 202 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: 48 additions & 31 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,40 @@ 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(
51+
applicationContext, R.string.app_update_unavailable_toast,
52+
Toast.LENGTH_SHORT
53+
).show()
54+
}
55+
}
4556
return
4657
}
47-
val app = App.getApp()
4858

4959
// A pending intent to open the apk location url in the browser.
5060
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
5161
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)
62+
val pendingIntent = PendingIntentCompat.getActivity(
63+
applicationContext, 0, intent, 0
64+
)
65+
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
66+
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
5567
.setSmallIcon(R.drawable.ic_newpipe_update)
5668
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
57-
.setContentIntent(pendingIntent)
5869
.setAutoCancel(true)
59-
.setContentTitle(app.getString(R.string.app_update_notification_content_title))
70+
.setContentIntent(pendingIntent)
71+
.setContentTitle(
72+
applicationContext.getString(R.string.app_update_available_notification_title)
73+
)
6074
.setContentText(
61-
app.getString(R.string.app_update_notification_content_text) +
62-
" " + versionName
75+
applicationContext.getString(
76+
R.string.app_update_available_notification_text, versionName
77+
)
6378
)
64-
val notificationManager = NotificationManagerCompat.from(app)
79+
80+
val notificationManager = NotificationManagerCompat.from(applicationContext)
6581
notificationManager.notify(2000, notificationBuilder.build())
6682
}
6783

@@ -72,12 +88,14 @@ class NewVersionWorker(
7288
return
7389
}
7490

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
91+
if (!inputData.getBoolean(IS_MANUAL, false)) {
92+
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
93+
// Check if the last request has happened a certain time ago
94+
// to reduce the number of API requests.
95+
val expiry = prefs.getLong(applicationContext.getString(R.string.update_expiry_key), 0)
96+
if (!isLastUpdateCheckExpired(expiry)) {
97+
return
98+
}
8199
}
82100

83101
// Make a network request to get latest NewPipe data.
@@ -120,43 +138,42 @@ class NewVersionWorker(
120138
}
121139

122140
override fun doWork(): Result {
123-
try {
141+
return try {
124142
checkNewVersion()
143+
Result.success()
125144
} catch (e: IOException) {
126145
Log.w(TAG, "Could not fetch NewPipe API: probably network problem", e)
127-
return Result.failure()
146+
Result.failure()
128147
} catch (e: ReCaptchaException) {
129148
Log.e(TAG, "ReCaptchaException should never happen here.", e)
130-
return Result.failure()
149+
Result.failure()
131150
}
132-
return Result.success()
133151
}
134152

135153
companion object {
136154
private val DEBUG = MainActivity.DEBUG
137155
private val TAG = NewVersionWorker::class.java.simpleName
138156
private const val NEWPIPE_API_URL = "https://newpipe.net/api/data.json"
157+
private const val IS_MANUAL = "isManual"
139158

140159
/**
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.
160+
* Start a new worker which checks if all conditions for performing a version check are met,
161+
* fetches the API endpoint [.NEWPIPE_API_URL] containing info about the latest NewPipe
162+
* version and displays a notification about an available update if one is available.
146163
* <br></br>
147-
* Following conditions need to be met, before data is request from the server:
164+
* Following conditions need to be met, before data is requested from the server:
148165
*
149166
* * The app is signed with the correct signing key (by TeamNewPipe / schabi).
150167
* If the signing key differs from the one used upstream, the update cannot be installed.
151168
* * The user enabled searching for and notifying about updates in the settings.
152169
* * The app did not recently check for updates.
153170
* We do not want to make unnecessary connections and DOS our servers.
154-
*
155171
*/
156172
@JvmStatic
157-
fun enqueueNewVersionCheckingWork(context: Context) {
158-
val workRequest: WorkRequest =
159-
OneTimeWorkRequest.Builder(NewVersionWorker::class.java).build()
173+
fun enqueueNewVersionCheckingWork(context: Context, isManual: Boolean) {
174+
val workRequest = OneTimeWorkRequestBuilder<NewVersionWorker>()
175+
.setInputData(workDataOf(IS_MANUAL to isManual))
176+
.build()
160177
WorkManager.getInstance(context).enqueue(workRequest)
161178
}
162179
}

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)