Fix more onBackPressed() deprecations#17579
Merged
BrayanDSO merged 5 commits intoankidroid:mainfrom Dec 10, 2024
Merged
Conversation
david-allison
approved these changes
Dec 9, 2024
Member
david-allison
left a comment
There was a problem hiding this comment.
The commit messages made this trivial to review, thank you so much!
Member
|
The previous code in onBackPressed() was just setting the result code to RESULT_OK and then finishing the activity so I set that result code directly in onCreate(), the associated fragment can change it as it chooses. With this change(vs. adding a OnBackPressedCallback) we get the nice peek animation when dragging from the left to go back( enableOnBackInvokedCallback has to be enabled for the application in the manifest file).
Moved the previous back handling code from the activity to the related fragment. The predictive BACK navigation is done by changing the enabled status of the back callback every time isDownloadInProgress is updated. There was also a direct call to the activity onBackPressed() which was replaced by the equivalent onBackPressedDispatcher.onBackPressed().
The previous code was showing a discard dialog if there were any changes, meaning that the user entered something different in the input boxed than what text was the screen initialized with. The fix introduces two listeners for the input boxes to use them as a dynamic listener for when there's change and implicitly could be BACK changes as well. The code still shows the discard changes dialog for the UP button in the toolbar like before.
Created a back callback for closing the drawer and connected it to the drawer's listener to enable and disable it dynamically. The code was added to initNavigationDrawer method which all screens that appear in the drawer(DeckPicker, CardBrowser and Reviewer) call in onCreate(). Having both the drawer opening and the back gesture happening on swipe from the screen's left edge isn't great.
4a5543d to
e398fb7
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Description
Replace some usages of onBackPressed() with specific OnBackPressedCallbacks that are enabled/disabled ahead of time(of BACK action). More info in the commits messages. Four more usages of onBackPressed() left but those are more difficult to fix. See some videos with the new behavior(must add android:enableOnBackInvokedCallback="true" for the application tag in the manifest):
study_options.mp4
shared_decks.mp4
reviewer.mp4
card_browser.mp4
card_browser_apperance.mp4
Fixes
How Has This Been Tested?
Used the app screens, less for shared decks(because I went there too many times I'm seeing 429 responses:( ).
Checklist