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 onBackPressed() deprecation In Card Browser #17594

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Prince-kushwaha
Copy link
Contributor

@Prince-kushwaha Prince-kushwaha commented Dec 12, 2024

Purpose / Description

Fix onBackPressed() deprecation In Card Browser

Fixes

How Has This Been Tested?

Physical Device

WhatsApp.Video.2024-12-27.at.6.38.24.PM.mp4

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Dec 13, 2024
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

The goal of the new predictive back navigation is to have distinct back callbacks for any actions you may want on BACK pressed and to enable/disable those callbacks dynamically so the system knows ahead of time if you are managing the back action or the system should handle it(and show animations).

Using OnBackPressedCallback and permanently have it enabled is equivalent with the current onBackPressed() so the changes in this PR are not an improvement. I would rather keep the deprecated onBackPressed callback present because it stands out as needing to be fixed, instead of the callback which is going to make it harder to see there's an issue.

@Prince-kushwaha
Copy link
Contributor Author

Hi David, I will address the review points

@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Dec 24, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

I don't feel this code matches the logic of the previous implementation. It feels like it should be the following (please disagree, you're closer to the code than I am)

  • If the drawer is open, the drawer should take prioirty
  • If multiselect is open, it should be closed

If neither happen, there shouldn't be an active back dispatcher, and the activity should close normally, with the provided result set somewhere before the back button was pressed (fail + reload required should be the default).

A test here would also be great, regarding the exit + exit intent.

val data = Intent()
// Add reload flag to result intent so that schedule reset when returning to note editor
data.putExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, reloadRequired)
closeCardBrowser(RESULT_OK, data)
Copy link
Member

Choose a reason for hiding this comment

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

This seems... unusual. It feels like it shouldn't be in the callback and should be the default of pressing 'back', unless there's documentation to disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this back callback method responsible for close of CardBrowser.

Copy link
Member

Choose a reason for hiding this comment

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

As stated twice, this isn't correct

AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt Outdated Show resolved Hide resolved
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

First of all the drawer back state is handled in the super class. I defined there a back callback that should be exposed to subclasses to add to the back dispatcher. Also note that the order of adding the callbacks is important.

Secondly, there shouldn't be a "default" back callback because this would defeat the entire purpose of the new system(to know ahead of time the status of any back actions).

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Dec 26, 2024
@Prince-kushwaha
Copy link
Contributor Author

Hi @david-allison ,i defined the order of callback method ->drawerBackCallback->multiSelectBackCallback->closeCardBrowserBackCallback. and it is matching the logic of the previous implementation (onBackPressed). Below adding the testing video of it

WhatsApp.Video.2024-12-27.at.6.38.24.PM.mp4

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Forgot to submit

@@ -284,6 +286,31 @@ open class CardBrowser :
private var shouldRestoreScroll = false
private var postAutoScroll = false

private val drawerBackCallback =
Copy link
Member

Choose a reason for hiding this comment

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

Why is this in CardBrowser? This should be a responsibility of the drawer

val data = Intent()
// Add reload flag to result intent so that schedule reset when returning to note editor
data.putExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, reloadRequired)
closeCardBrowser(RESULT_OK, data)
Copy link
Member

Choose a reason for hiding this comment

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

As stated twice, this isn't correct

Comment on lines +473 to +490
val drawerListener =
object : ActionBarDrawerToggle(
this,
drawerLayout,
R.string.drawer_open,
R.string.drawer_close,
) {
override fun onDrawerClosed(drawerView: View) {
super.onDrawerClosed(drawerView)
drawerBackCallback.isEnabled = false
}

override fun onDrawerOpened(drawerView: View) {
super.onDrawerOpened(drawerView)
drawerBackCallback.isEnabled = true
}
}
drawerLayout.addDrawerListener(drawerListener)
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be the responsibility of the Card Browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Author Reply Waiting for a reply from the original author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle "predictive back" / ActivityTransitionAnimation deprecation in API34
3 participants