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

Fix "Add to playlist" not working and cleanup "RouterActivity" choice handling #8340

Merged
merged 6 commits into from
Jun 5, 2022

Conversation

litetex
Copy link
Member

@litetex litetex commented May 2, 2022

What is it?

  • Bugfix (user facing)

Description of the changes in your PR

Problem: Setting Preferred 'open' action to "Add to playlist" does nothing when opening a video
Discovered while working on #8332

This PR also cleans up how the choices are handled inside RouterActivity. It was until now possible to e.g. download a channel (which resulted in an error/unsupported url page) due to incorrect choice-availability-checks.
Now everything is centralized in open place and should be easier to maintain.

Before/After Screenshots/Screen Record

  • Before: Nothing happens when clicking a video; Behaves like "Show info"
  • After:
NPRouterActivityDemo1.gif.mp4

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

@litetex litetex added the bug Issue is related to a bug label May 2, 2022
@opusforlife2 opusforlife2 changed the title Fix "add to playlist" not working and cleanup RouterActicity choice handling Fix "Add to playlist" not working, and cleanup "RouterActivity" choice handling May 2, 2022
@opusforlife2

This comment was marked as off-topic.

@litetex litetex marked this pull request as ready for review May 3, 2022 17:19
@litetex litetex changed the title Fix "Add to playlist" not working, and cleanup "RouterActivity" choice handling Fix "Add to playlist" not working and cleanup "RouterActivity" choice handling May 3, 2022
@Stypox

This comment was marked as off-topic.

@opusforlife2

This comment was marked as off-topic.

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.

Code mostly looks good


final List<AdapterChoiceItem> returnedItems = new ArrayList<>();
returnedItems.add(showInfo); // Always present
Copy link
Member

Choose a reason for hiding this comment

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

Uhm, why is it always present? Shouldn't it be hidden in cases where it would do the exact same thing as videoPlayer, to save some space?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. You would end up with an action "Video player" that behaves like "Show Info". If thought logically it should be exactly opposite: We shouldn't show "Video player" when it can be done with "Show info".
  2. This would require a ton of if logic and another logical layer on top of the choices. Which is in my opinion overkill.
  3. It may be unexpected for the user if no "Show info" or "Video player" is present.
  4. Saving space is not relevant because there is still a huge portion of users that have all entries anyway visible (e.g. if the have auto-play enabled - which is default).

Copy link
Member

Choose a reason for hiding this comment

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

Mmmh ok, then in a separate PR the router activity should be made scrollable. When I have the phone in landscape I can't see all options.

Copy link
Member Author

@litetex litetex May 27, 2022

Choose a reason for hiding this comment

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

Oh, I didn't notice that.
Sound's like a new issue 😉

Update: Fixed it on the fly.
The cause of the problem was single_choice_dialog_view:

The view is used inside:

  • The RouterActivity
  • The PlayerCrasher-Dialog
  • The Player-Notfication configurator:
    grafik

All those are now scrollable.

And the Player-Notfication configurator also uses viewbinding now.

If this is too much for the PR I can also create a separate PR.

app/src/main/java/org/schabi/newpipe/RouterActivity.java Outdated Show resolved Hide resolved
Comment on lines +303 to +306
final List<StreamingService.ServiceInfo.MediaCapability> capabilities =
currentService.getServiceInfo().getMediaCapabilities();
Copy link
Member

Choose a reason for hiding this comment

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

Uhm, why isn't checkstyle complaining? The = should be on the newline

Copy link
Member Author

Choose a reason for hiding this comment

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

Google (Example), SunOracle (Example), Checkstyles default style and Spring (Example) do it on the same line and break after the assignment if necessary.
I think above is more or less industry standard, so why move the = to a new line?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, from the checkstyle link you provided, the default value is nl, i.e. putting the operator on new line. It always has been this way in NewPipe, so I think you should stick to that (as you did e.g. for && and || in ifs), though this is really minor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, from the checkstyle link you provided, the default value is nl, i.e. putting the operator on new line.

Uhm no:
grafik

It only checks the tokens in the right (not left) column.

It always has been this way in NewPipe...

Also no. Example:

public static final String ACTION_SHOW_MAIN_PLAYER =
App.PACKAGE_NAME + ".VideoDetailFragment.ACTION_SHOW_MAIN_PLAYER";
public static final String ACTION_HIDE_MAIN_PLAYER =
App.PACKAGE_NAME + ".VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER";
public static final String ACTION_PLAYER_STARTED =
App.PACKAGE_NAME + ".VideoDetailFragment.ACTION_PLAYER_STARTED";
public static final String ACTION_VIDEO_FRAGMENT_RESUMED =
App.PACKAGE_NAME + ".VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED";
public static final String ACTION_VIDEO_FRAGMENT_STOPPED =
App.PACKAGE_NAME + ".VideoDetailFragment.ACTION_VIDEO_FRAGMENT_STOPPED";
or
private final ActivityResultLauncher<Intent> requestDownloadSaveAsLauncher =
registerForActivityResult(
new StartActivityForResult(), this::requestDownloadSaveAsResult);
private final ActivityResultLauncher<Intent> requestDownloadPickAudioFolderLauncher =
registerForActivityResult(
new StartActivityForResult(), this::requestDownloadPickAudioFolderResult);
private final ActivityResultLauncher<Intent> requestDownloadPickVideoFolderLauncher =
registerForActivityResult(
new StartActivityForResult(), this::requestDownloadPickVideoFolderResult);

Update: I went a bit through git history and found these commits:

So apparently someone (cough wb9688) introduced his personal code "style" but didn't persist the changes inside checkstyle and also no one noticed it inside the PR...

Anyway I - and I also think most other developers (as seen above) - favor the = after assignment style. So I would stick with that ;)

Copy link
Member

Choose a reason for hiding this comment

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

Mmmh ok. I still don't see why all operators should be on newlines (like you did for || below here) but = should not, but anyway... If this is the standard across the industry, if you have a little spare time please open a PR to enforce such style in checkstyle

serviceSupportsChoice = capabilities.contains(AUDIO);
// Check if the service supports the choice
if (isVideoPlayerSelected && capabilities.contains(VIDEO)
|| isAudioPlayerSelected && capabilities.contains(AUDIO)) {
Copy link
Member

@Stypox Stypox May 23, 2022

Choose a reason for hiding this comment

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

Parenthesis around the &&s

@litetex litetex force-pushed the fix-add-to-playlist branch from c492d1f to 1f5795d Compare May 27, 2022 22:45
@litetex litetex force-pushed the fix-add-to-playlist branch from 1f5795d to 2985258 Compare May 27, 2022 22:47
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.

Thank you! Code looks good to me. I also tested and everything works well.

A note for a separate PR: the "processing, will take a moment" toast should be shown on any action that waits for video info to be obtained. Currently it is only shown for "Add to playlist". I think the same string should also be used for actions in the long-press menu.

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.

Wait, when the router activity closes (because the dialog is dismissed), a strange animation is shown with a red line swiping through the screen. I thought this happened on dev, too, but it doesn't. I think it is some activity theming issue.

@litetex
Copy link
Member Author

litetex commented Jun 4, 2022

Wait, when the router activity closes (because the dialog is dismissed), a strange animation is shown with a red line swiping through the screen. I thought this happened on dev, too, but it doesn't. I think it is some activity theming issue.

I think you mean this or? grafik](https://user-images.githubusercontent.com/40789489/172000149-c3ccac1b-cf1e-4256-b8da-92285759fd35.png) ![NPRouterActivityP1

I will have a look into it...

@litetex
Copy link
Member Author

litetex commented Jun 4, 2022

Look a easy fix:
https://stackoverflow.com/a/26927698

Oh we are still supporting Android 4.4.... So not an easy fix... yay
grafik

Fixed it only for Android 5+ up because Android 4.4 will soon be no longer supported.

And btw, this issue arose in #8332. So a new PR would have been better :)

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 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

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.

Great, thank you :-)

@Stypox Stypox merged commit a59660f into TeamNewPipe:dev Jun 5, 2022
@litetex litetex deleted the fix-add-to-playlist branch June 10, 2022 12:59
@Stypox Stypox mentioned this pull request Jun 24, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants