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

Improve screen rotation handling in Open action menu #9135

Merged
merged 14 commits into from
Jan 11, 2023

Conversation

devlearner
Copy link
Contributor

@devlearner devlearner commented Oct 15, 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

Currently when sharing to NewPipe (when set to Always ask), the Open action menu dialog would rotate away on orientation change (since finish() would be called by onDismissListener during dialog cleanup thus preventing RouterActivity to be recreated when screen rotates). This PR tries to improve that by making the dialogs stay across screen rotations.

Known issue: Ongoing network requests, however, won't survive config change (which would somehow require keeping track of the Observables across recreation of activity). If user selects Add to Playlist or Download and rotates away while stream info is being fetched, the network request underway would be dropped and RouterActivity would start over again when recreated on orientation change. That would (unfortunately) be another PR for another day. Addressed this using a retained fragment the other day

Misc changes
  • Fixes a bug on older Android where the Open action dialog won't appear the first time on cold start
  • Shows on Download action as well the toast that asks the user to wait
  • When fetching stream info (for Add to Playlist and Download), the transparent activity no longer blocks touch events and inadvertently locks UI thus giving the impression that NewPipe freezes
To test:
  • Make sure Settings -> Video & audio -> Preferred 'open' action is set to Always ask (the default setting)
  • Share a (YouTube) URL to NewPipe (Debug apk) (say, from a browser)
  • Happy screen rotating :)

Fixes the following issue(s)

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

@sonarcloud
Copy link

sonarcloud bot commented Oct 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 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@TobiGr TobiGr added the bug Issue is related to a bug label Oct 19, 2022
@opusforlife2 opusforlife2 added the GUI Issue is related to the graphical user interface label Oct 21, 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.

Code looks good to me. I tested and it seems to work well. Thanks!

@devlearner devlearner force-pushed the routeractivity-screen-rotate branch 4 times, most recently from dbc9d65 to a97c661 Compare December 2, 2022 14:23
// on the strength of "4. Fully transparent windows" without affecting the scrim of dialogs
final WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 0f;
getWindow().setAttributes(params);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks both for the heads up and reference! I've addressed it here, by simply setting LayoutParams.alpha to 0 to check off point 4 in their list. Do you think I'm getting it right? 🤔
From my testing (at least on my device) this won't have a side-effect on the scrim (which, in Material speak, refers to the dimmed background) behind AlertDialog/DialogFragments: the background will still be dimmed instead of fully transparent even with this put in, which is good for our purpose

@devlearner
Copy link
Contributor Author

(Oops, I messed up a bit while fast-forwarding the branch; the first five commits are the old commits from last time, sorry for the force-push noise.)

Thanks both for the review and reference! I've updated it above 👍

So while we're at it, I've also taken the opportunity to revisit the last part of the issue, and tried to address it utilizing a retained fragment. It should now get everything covered from start to end for the duration and purpose of RouterActivity any potential orientation changes without losing network requests in flight in the interim. (The only case uncovered for the time being is if the user switches to another app during the waiting window, but I guess it'd be as good as it can get for now :) )

@sonarcloud
Copy link

sonarcloud bot commented Dec 11, 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

This seems to solve a bug where the Open action menu dialog does not appear the first time on cold start on older Android (8.0).
This is also the order of things in MainActivity and probably good practice.
when orientation change is on foot
…ed from orientation change

- Handle finish() call instead of passing around callbacks to setOnDismissListener()
- Don't start over again if returning to DialogFragment before orientation change
and lengthened a bit to inform user to wait...
…ing windows

so we won't hold up UI while fetching media info for Add to Playlist or Download actions
lest user might think it freezes when in fact a network request is underway
to avoid adding it multiple times and ensure proper cleanup
pending result for openAddToPlaylistDialog() and openDownloadDialog()
Despite marked deprecated, setRetainInstance(true) is probably our best bet (since a ViewModel is probably too overkill for our present purpose)
probably due to background restrictions on Android 10+
I thought it would have required an extra dependency; apparently that doesn't seem to be the case...
We provide visual feedback via a toast to the user that, well, they're supposed to wait; but with the benefit of the cache openAddToPlaylistDialog() may return (almost) immediately, which would render the toast otiose (if not a bit confusing). This commit improves that by cancelling the toast once the wait's over

... (by 'abusing' RxJava's ambWith();
ref on compose() and Transformer: https://blog.danlew.net/2015/03/02/dont-break-the-chain/
and for me, first time laying my hands at RxJava so kindly bear with me; open for suggestions)
@Stypox Stypox force-pushed the routeractivity-screen-rotate branch from 678ea51 to dfcc464 Compare January 11, 2023 14:13
@Stypox Stypox force-pushed the routeractivity-screen-rotate branch from dfcc464 to 944e295 Compare January 11, 2023 14:14
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! I tested and it seems to work well. The only inconsistency I noticed is that the initial selection menu stays shown even when the download dialog is showing above it, except after rotating, but this is not really a problem. I pushed a small commit that uses Optional for the activity context and simplifies a couple of other things. Thank you!

@Stypox Stypox merged commit eed44b3 into TeamNewPipe:dev Jan 11, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jan 11, 2023

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 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@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
bug Issue is related to a bug GUI Issue is related to the graphical user interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Share to newpipe menu does not open at first click on link
5 participants