Skip to content

Commit

Permalink
Show a toast instead, and display it only if the update check was man…
Browse files Browse the repository at this point in the history
…ual.
  • Loading branch information
Isira-Seneviratne committed Aug 1, 2022
1 parent 96d1f4d commit b8d95ad
Show file tree
Hide file tree
Showing 72 changed files with 171 additions and 176 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected void onPostCreate(final Bundle savedInstanceState) {
if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
// Start the worker which is checking all conditions
// and eventually searching for a new version.
NewVersionWorker.enqueueNewVersionCheckingWork(app);
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
}
}

Expand Down
72 changes: 34 additions & 38 deletions app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.preference.PreferenceManager
import androidx.work.OneTimeWorkRequest
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkRequest
import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import com.grack.nanojson.JsonParser
import com.grack.nanojson.JsonParserException
import org.schabi.newpipe.extractor.downloader.Response
Expand Down Expand Up @@ -42,33 +43,29 @@ class NewVersionWorker(
apkLocationUrl: String?,
versionCode: Int
) {
if (BuildConfig.VERSION_CODE >= versionCode) {
if (inputData.getBoolean(IS_MANUAL, false)) {
// Show toast stating that the app is up-to-date if the update check was manual.
Toast.makeText(applicationContext, R.string.app_update_unavailable_toast, Toast.LENGTH_SHORT).show()
}
return
}

// A pending intent to open the apk location url in the browser.
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(
applicationContext, 0, intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
)
val channelId = applicationContext.getString(R.string.app_update_notification_channel_id)
val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_newpipe_update)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setAutoCancel(true)

if (BuildConfig.VERSION_CODE >= versionCode) {
// Show notification stating that the app is up-to-date.
notificationBuilder.setContentTitle(applicationContext.getString(R.string.app_update_unavailable_notification_content_title))
.setContentText(applicationContext.getString(R.string.app_update_unavailable_notification_content_text))
} else {
// A pending intent to open the apk location url in the browser.
val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri())
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(
applicationContext, 0, intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
)
notificationBuilder.setContentIntent(pendingIntent)
.setContentTitle(applicationContext.getString(R.string.app_update_available_notification_content_title))
.setContentText(
applicationContext.getString(
R.string.app_update_available_notification_content_text,
versionName
)
)
}
.setContentIntent(pendingIntent)
.setContentTitle(applicationContext.getString(R.string.app_update_available_notification_title))
.setContentText(applicationContext.getString(R.string.app_update_available_notification_text, versionName))

val notificationManager = NotificationManagerCompat.from(applicationContext)
notificationManager.notify(2000, notificationBuilder.build())
Expand Down Expand Up @@ -129,43 +126,42 @@ class NewVersionWorker(
}

override fun doWork(): Result {
try {
return try {
checkNewVersion()
Result.success()
} catch (e: IOException) {
Log.w(TAG, "Could not fetch NewPipe API: probably network problem", e)
return Result.failure()
Result.failure()
} catch (e: ReCaptchaException) {
Log.e(TAG, "ReCaptchaException should never happen here.", e)
return Result.failure()
Result.failure()
}
return Result.success()
}

companion object {
private val DEBUG = MainActivity.DEBUG
private val TAG = NewVersionWorker::class.java.simpleName
private const val NEWPIPE_API_URL = "https://newpipe.net/api/data.json"
private const val IS_MANUAL = "isManual"

/**
* Start a new worker which
* checks if all conditions for performing a version check are met,
* fetches the API endpoint [.NEWPIPE_API_URL] containing info
* about the latest NewPipe version
* and displays a notification about ana available update.
* Start a new worker which checks if all conditions for performing a version check are met,
* fetches the API endpoint [.NEWPIPE_API_URL] containing info about the latest NewPipe
* version and displays a notification about an available update if one is available.
* <br></br>
* Following conditions need to be met, before data is request from the server:
* Following conditions need to be met, before data is requested from the server:
*
* * The app is signed with the correct signing key (by TeamNewPipe / schabi).
* If the signing key differs from the one used upstream, the update cannot be installed.
* * The user enabled searching for and notifying about updates in the settings.
* * The app did not recently check for updates.
* We do not want to make unnecessary connections and DOS our servers.
*
*/
@JvmStatic
fun enqueueNewVersionCheckingWork(context: Context) {
val workRequest: WorkRequest =
OneTimeWorkRequest.Builder(NewVersionWorker::class.java).build()
fun enqueueNewVersionCheckingWork(context: Context, isManual: Boolean) {
val workRequest = OneTimeWorkRequestBuilder<NewVersionWorker>()
.setInputData(workDataOf(IS_MANUAL to isManual))
.build()
WorkManager.getInstance(context).enqueue(workRequest)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void checkNewVersionNow() {
// Reset the expire time. This is necessary to check for an update immediately.
defaultPreferences.edit()
.putLong(getString(R.string.update_expiry_key), 0).apply();
NewVersionWorker.enqueueNewVersionCheckingWork(getContext());
NewVersionWorker.enqueueNewVersionCheckingWork(requireContext(), true);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@
<string name="list">القائمة</string>
<string name="grid">الشبكة</string>
<string name="auto">تلقائي</string>
<string name="app_update_available_notification_content_title">تحديث NewPipe متاح!</string>
<string name="app_update_available_notification_content_text">اضغط لتنزيل</string>
<string name="app_update_available_notification_title">تحديث NewPipe متاح!</string>
<string name="app_update_available_notification_text">اضغط لتنزيل</string>
<string name="missions_header_finished">انتهى</string>
<string name="missions_header_pending">ريثما</string>
<string name="paused">متوقف</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
<string name="queued">növbədə</string>
<string name="post_processing">son proseslər tətbiq olunur</string>
<string name="checking_updates_toast">Yeniləmələr yoxlanılır…</string>
<string name="app_update_available_notification_content_title">NewPipe yeniləməsi mövcuddur!</string>
<string name="app_update_available_notification_title">NewPipe yeniləməsi mövcuddur!</string>
<string name="metadata_licence">Lisenziya</string>
<string name="feed_load_error_terminated">Müəllifin hesabı bağlanıb.
\nNewPipe gələcəkdə bu axını yükləyə bilməyəcək.
Expand Down Expand Up @@ -572,7 +572,7 @@
<string name="recovering">bərpa olunur</string>
<string name="paused">dayandırıldı</string>
<string name="missions_header_finished">Bitdi</string>
<string name="app_update_available_notification_content_text">Endirmək üçün toxunun</string>
<string name="app_update_available_notification_text">Endirmək üçün toxunun</string>
<string name="minimize_on_exit_none_description">Heç biri</string>
<string name="minimize_on_exit_summary">Əsas video oynadıcıdan digər tətbiqə keçid zamanı hərəkət — %s</string>
<string name="decline">İmtina</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-b+ast/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@
<string name="subscribed_button_title">Soscribiéstite</string>
<string name="no_videos">Nun hai vídeos</string>
<string name="delete_search_history_alert">¿Desaniciar tol historial de busques\?</string>
<string name="app_update_available_notification_content_title">¡Hai un anovamientu pa NewPipe!</string>
<string name="app_update_available_notification_content_text">Toca pa baxalu</string>
<string name="app_update_available_notification_title">¡Hai un anovamientu pa NewPipe!</string>
<string name="app_update_available_notification_text">Toca pa baxalu</string>
<string name="error_progress_lost">Perdióse\'l progresu porque se desanició\'l ficheru</string>
<string name="peertube_instance_url_title">Instancies de PeerTube</string>
<string name="peertube_instance_add_exists">La instancia yá esiste</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-b+uz+Latn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@
<string name="paused">to\'xtatildi</string>
<string name="missions_header_pending">Kutilmoqda</string>
<string name="missions_header_finished">Tugatildi</string>
<string name="app_update_available_notification_content_text">Yuklash uchun bosing</string>
<string name="app_update_available_notification_content_title">NewPipe yangilanishi mavjud!</string>
<string name="app_update_available_notification_text">Yuklash uchun bosing</string>
<string name="app_update_available_notification_title">NewPipe yangilanishi mavjud!</string>
<string name="auto">Avto</string>
<string name="grid">Tarmoq</string>
<string name="list">Ro\'yxat</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@
<string name="list">Спіс</string>
<string name="grid">Сетка</string>
<string name="auto">Аўтаматычна</string>
<string name="app_update_available_notification_content_title">Даступна абнаўленне NewPipe!</string>
<string name="app_update_available_notification_content_text">Націсніце для загрузкі</string>
<string name="app_update_available_notification_title">Даступна абнаўленне NewPipe!</string>
<string name="app_update_available_notification_text">Націсніце для загрузкі</string>
<string name="missions_header_finished">Скончана</string>
<string name="missions_header_pending">У чарзе</string>
<string name="paused">прыпынена</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@
<string name="wifi_only">Само при Wi-Fi</string>
<string name="list_view_mode">Вид на списъка</string>
<string name="enable_playback_resume_summary">Възстанови последната позиция</string>
<string name="app_update_available_notification_content_title">Нова версия на NewPipe е налична!</string>
<string name="app_update_available_notification_title">Нова версия на NewPipe е налична!</string>
<string name="seekbar_preview_thumbnail_title">Миниатюри на лентата за превъртане</string>
<string name="low_quality_smaller">Нискокачествени (малки)</string>
<string name="app_update_available_notification_content_text">Докоснете за изтегляне</string>
<string name="app_update_available_notification_text">Докоснете за изтегляне</string>
<string name="queued">на опашка</string>
<string name="updates_setting_title">Актуализации</string>
<string name="overwrite">Презаписване</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-bn-rBD/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<string name="show_error">এরর দেখান</string>
<string name="download_failed">ডাউনলোড ব্যর্থ হয়েছে</string>
<string name="paused">স্থগিত</string>
<string name="app_update_available_notification_content_text">ডাউনলোড করতে টোকা দিন</string>
<string name="app_update_available_notification_text">ডাউনলোড করতে টোকা দিন</string>
<string name="auto">অটো</string>
<string name="limit_data_usage_none_description">সীমাহীন</string>
<string name="caption_none">কোন ক্যাপশন নেই</string>
Expand Down Expand Up @@ -392,7 +392,7 @@
<string name="notification_action_4_title">পঞ্চম পদক্ষেপ বোতাম</string>
<string name="show_description_summary">ভিডিও বর্ণনা ও বাড়তি তথ্য লুকাতে বন্ধ করুন</string>
<string name="dont_show">দেখিও না</string>
<string name="app_update_available_notification_content_title">নিউ পাইপ আপডেট এসেছে!</string>
<string name="app_update_available_notification_title">নিউ পাইপ আপডেট এসেছে!</string>
<string name="comments_are_disabled">মন্তব্যসমূহ নিষ্ক্রিয় আছে</string>
<plurals name="views">
<item quantity="one">%s বার দেখেছে</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bn-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<string name="error_unknown_host">সার্ভার পাওয়া যায় নি</string>
<string name="download_failed">ডাউন লোড হয় নি</string>
<string name="paused">পজ হয়েছে</string>
<string name="app_update_available_notification_content_text">ডাউন লোড করার জন্য চাপ দিন</string>
<string name="app_update_available_notification_text">ডাউন লোড করার জন্য চাপ দিন</string>
<string name="auto">অটো</string>
<string name="grid">গ্রিড</string>
<string name="caption_setting_title">ক্যাপশন</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<string name="download_failed">ডাউন লোড হয় নি</string>
<string name="paused">পজ হয়েছে</string>
<string name="missions_header_finished">সম্পূর্ণ</string>
<string name="app_update_available_notification_content_text">ডাউন লোড করার জন্য চাপ দিন</string>
<string name="app_update_available_notification_text">ডাউন লোড করার জন্য চাপ দিন</string>
<string name="auto">অটো</string>
<string name="grid">ছক</string>
<string name="list">তালিকা</string>
Expand Down Expand Up @@ -470,7 +470,7 @@
<string name="pause_downloads_on_mobile">পরিমাপকৃত নেটওয়ার্কে বাধা দাও</string>
<string name="error_download_resource_gone">এই ডাউনলোড উদ্ধার করা যাচ্ছে না</string>
<string name="overwrite_failed">এই ফাইলের উপর লেখা যাচ্ছে না</string>
<string name="app_update_available_notification_content_title">নিউপাইপ হালনাগাদ আছে!</string>
<string name="app_update_available_notification_title">নিউপাইপ হালনাগাদ আছে!</string>
<string name="minimize_on_exit_popup_description">ভাসমান চালকের ক্ষুদ্রকরণ করো</string>
<string name="minimize_on_exit_background_description">প্লেয়ার পটভূমিতে ক্ষুদ্রকরণ করো</string>
<string name="minimize_on_exit_title">অ্যাপ পরিবর্তনে ক্ষুদ্রকরণ করো</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
<string name="list">Llista</string>
<string name="grid">Quadrícula</string>
<string name="auto">Automàtic</string>
<string name="app_update_available_notification_content_title">Una nova versió del NewPipe està disponible!</string>
<string name="app_update_available_notification_title">Una nova versió del NewPipe està disponible!</string>
<string name="missions_header_pending">Pendent</string>
<string name="paused">en pausa</string>
<string name="queued">a la cua</string>
Expand Down Expand Up @@ -388,7 +388,7 @@
<string name="close">Tanca</string>
<string name="saved_tabs_invalid_json">S\'ha produït un error en llegir les pestanyes desades; s\'estan utilitzant les pestanyes per defecte</string>
<string name="updates_setting_description">Mostra una notificació per demanar l\'actualització de l\'aplicació si hi ha una versió nova disponible</string>
<string name="app_update_available_notification_content_text">Toqueu per baixar</string>
<string name="app_update_available_notification_text">Toqueu per baixar</string>
<string name="error_http_no_content">El servidor no està enviant dades</string>
<string name="app_update_notification_channel_name">Notificació d\'actualització de l\'aplicació</string>
<string name="enable_playback_resume_title">Reprèn la reproducció</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-ckb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
<string name="use_external_video_player_summary">هه‌ندێك له‌ قه‌باره‌كان ده‌نگیان تێدا نامێنێته‌وه‌</string>
<string name="events">ڕووداوەکان</string>
<string name="detail_uploader_thumbnail_view_description">وێنۆچکەی کەسی بەرزکەرەوە</string>
<string name="app_update_available_notification_content_text">كرتە بکە بۆ دابه‌زاندن</string>
<string name="app_update_available_notification_text">كرتە بکە بۆ دابه‌زاندن</string>
<string name="import_complete_toast">هاورده‌كرا</string>
<string name="downloads">دابه‌زاندنه‌كان</string>
<string name="playback_speed_control">کۆنترۆڵی خێرایی کارپێکەر</string>
Expand Down Expand Up @@ -519,7 +519,7 @@
\nهەڵبژێرەری فۆڵدەری سیستەم کارابکە (SAF) گەر دەتەوێت بابەتەکانت لە بیرگەی دەرەکیدا داببەزێنرێن</string>
<string name="title_last_played">دواین لێدراو</string>
<string name="could_not_setup_download_menu">ناتوانرێ لیستی دابه‌زاندن دابنرێت</string>
<string name="app_update_available_notification_content_title">وەشانی نوێی نیوپایپ بەردەستە!</string>
<string name="app_update_available_notification_title">وەشانی نوێی نیوپایپ بەردەستە!</string>
<string name="playlist_thumbnail_change_success">وێنۆچکەی خشتەلێدان گۆڕدرا.</string>
<string name="import_soundcloud_instructions">هێنانەوەی پەڕەی کەسی SoundCloud بەدانانی بەستەر یاخوود ئایدی:
\n
Expand Down
Loading

0 comments on commit b8d95ad

Please sign in to comment.