Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show toast when no updates are available. #8668

Merged

Conversation

Isira-Seneviratne
Copy link
Member

@Isira-Seneviratne Isira-Seneviratne commented Jul 21, 2022

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

  • Display a toast if no new versions of NewPipe are available when checking for updates.

Before/After Screenshots/Screen Record

  • Before:
  • After:

Fixes the following issue(s)

  • Fixes #

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@Isira-Seneviratne Isira-Seneviratne marked this pull request as ready for review July 21, 2022 02:48
@TacoTheDank
Copy link
Member

Wouldn't this show every time the app is launched? That would be pretty annoying, I think.

@triallax
Copy link
Contributor

I agree with @TacoTheDank, it makes little sense to me to show a notification if there is no update available, plus it would be quite irritating. What problem are you trying to solve by this PR @Isira-Seneviratne?

@Isira-Seneviratne
Copy link
Member Author

I agree with @TacoTheDank, it makes little sense to me to show a notification if there is no update available, plus it would be quite irritating. What problem are you trying to solve by this PR @Isira-Seneviratne?

The idea was to show some feedback if no update was available, since at the moment nothing is shown if the app is up-to-date.

@triallax
Copy link
Contributor

triallax commented Jul 21, 2022

I think that would be more suited for a update check button/page perhaps.

@TobiGr
Copy link
Member

TobiGr commented Jul 21, 2022

I would not show a notification, but rather a toast. A toast saying "Checking for updates..." is already shown when the "check for updates" button is pressed (settings > updates).
I agree with the others that this info should not be shown when the check was performed automatically.

@Isira-Seneviratne
Copy link
Member Author

@TobiGr Yeah, I'll make that change.

@Isira-Seneviratne Isira-Seneviratne changed the title Show notification when no updates are available. Show toaster when no updates are available. Aug 4, 2022
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks almost good to me

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use the MANUAL flag inside NewVersionWorker.checkNewVersion to determine whether to ignore the expiry time, instead of resetting the expiry time here. Also, since only one statement would be left here then, I would remove checkNewVersionNow() and inline the work enqueueing.

app/src/main/res/values/strings.xml Show resolved Hide resolved
@triallax triallax added feature request Issue is related to a feature in the app GUI Issue is related to the graphical user interface labels Aug 4, 2022
@Isira-Seneviratne Isira-Seneviratne changed the title Show toaster when no updates are available. Show toast when no updates are available. Aug 5, 2022
Comment on lines 164 to 168
if (isManual) {
PreferenceManager.getDefaultSharedPreferences(context).edit {
putLong(context.getString(R.string.update_expiry_key), 0)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what I meant: remove this and just add an if (!manual) around these lines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the change okay?

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error, probably the wrong thread or context are used?

java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare()
        at ...
        at org.schabi.newpipe.NewVersionWorker.compareAppVersionAndShowNotification(NewVersionWorker.kt:49)

@@ -42,26 +44,30 @@ class NewVersionWorker(
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No lines longer than 100 characters... ktlint seems to be misconfigured, it should detect these problems

Suggested change
Toast.makeText(applicationContext, R.string.app_update_unavailable_toast, Toast.LENGTH_SHORT).show()
Toast.makeText(applicationContext, R.string.app_update_unavailable_toast,
Toast.LENGTH_SHORT).show()

app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt Outdated Show resolved Hide resolved
@@ -16,25 +16,17 @@ public class UpdateSettingsFragment extends BasePreferenceFragment {
.apply();

if (checkForUpdates) {
checkNewVersionNow();
NewVersionWorker.enqueueNewVersionCheckingWork(requireContext(), true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this false intead of true, since the user did not directly ask for an update check, he just enabled them. So if the last check was done a while ago (or never), then it's ok to check again, but if it has been done minutes earlier since the user just disabled and enabled twice in a row, it should not be done. Also, it's better to consider it automatic since we don't want a toast to be shown to the user in this case, as he does not expect feedback I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep this true because the user enabled the check manually, in other words wants NewPipe to check for new versions. Reporting back, that we did not find any new version this time is ok. It shows that the app does something as requested.

app/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
@Isira-Seneviratne
Copy link
Member Author

I get the following error, probably the wrong thread or context are used?

java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare()
        at ...
        at org.schabi.newpipe.NewVersionWorker.compareAppVersionAndShowNotification(NewVersionWorker.kt:49)

Yeah, it seems like the fix is to use a Handler or Executor to show the toast.

By the way, how can I check for updates in the debug build?

@TacoTheDank
Copy link
Member

By the way, how can I check for updates in the debug build?

I would assume that debug builds are for debugging, and that update checking isn't needed for them.

@Isira-Seneviratne
Copy link
Member Author

Isira-Seneviratne commented Aug 11, 2022

By the way, how can I check for updates in the debug build?

I would assume that debug builds are for debugging, and that update checking isn't needed for them.

Right, my bad. I'll check with a release build. It's been a while since I made changes to the update process.

@sonarcloud
Copy link

sonarcloud bot commented Aug 15, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you

@TobiGr TobiGr requested a review from Stypox October 9, 2022 17:47
@TobiGr
Copy link
Member

TobiGr commented Oct 9, 2022

btw. a rebase is required. I just pulled the latest translations from weblate.

To the maintainer merging this PR: please make sure to sync weblate once this PR is merged

@sonarcloud
Copy link

sonarcloud bot commented Oct 10, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Stypox Stypox force-pushed the Show_no_update_notification branch from 99a4e7b to e2670ac Compare December 4, 2022 10:57
@Stypox Stypox force-pushed the Show_no_update_notification branch from e2670ac to 6b210e1 Compare December 4, 2022 11:02
@Stypox
Copy link
Member

Stypox commented Dec 4, 2022

I merged weblate into dev, then rebased this PR onto dev, then I'm merging it.

@Stypox Stypox merged commit 730664e into TeamNewPipe:dev Dec 4, 2022
@sonarcloud
Copy link

sonarcloud bot commented Dec 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Isira-Seneviratne Isira-Seneviratne deleted the Show_no_update_notification branch December 6, 2022 14:49
@Stypox Stypox mentioned this pull request Jan 22, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issue is related to a feature in the app GUI Issue is related to the graphical user interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants