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

Sync from reviewer when we didn't want through the deck picker #17399

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Arthur-Milchior
Copy link
Member

@Arthur-Milchior Arthur-Milchior commented Nov 8, 2024

Sync enabled in the reviewer when the deck picker was not used

Widgets and shortcuts allows to directly review a deck.
This means that automated sync, or even manual sync, is never
available. Except if the user close the reviewer and then manually
open ankidroid. This create a lot of friction on a very important
feature.

This commit enable the sync feature in the reviewer, but hides it
unless the intent actually requested it.

In my opinion, it should be always available. It's available in anki
upstream from the reviewer, and anki allows automated save every 10
minutes. Which means even if your device suddenly dies during a
streak, you only lose up to 10 minutes of review.

Still, this feature at least improve the case that was the most
dangerous for users (and frustrating for me)

I don't know the code of Reviewer2/ReviewerFragment. So this is only
enabled in the legacy reviewer. I hope the code is simple enough for
the feature to be easily ported to the other reviewers now that the
entire sync part of the code was decoupled from the DeckPicker.

Manually tested with:

  • signin in (when no account present)
  • full sync (requested locally and requested by ankiweb)
  • normal sync
  • changing the selected deck on the other device

To test it you should use a widget or a shortcut.

One point amy need to be changed. The little icon that state that
there is a not-uploaded change. While it's okay in the deckpicker, it
may not be ideal to have it as soon as we have the first review done.

@Arthur-Milchior Arthur-Milchior force-pushed the sync_handler branch 2 times, most recently from 835a76e to b2e9176 Compare November 9, 2024 00:27
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 know the code of Reviewer2/ReviewerFragment. So this is only
enabled in the legacy reviewer. I hope the code is simple enough for
the feature to be easily ported to the other reviewers now that the
entire sync part of the code was decoupled from the DeckPicker.

From an architecture perspective, supporting the new reviewer is the most important thing to get right. We want to move to the new reviewer (which affects everyone; this change only affects a subset of users), and if this PR doesn't support the new reviewer, then we're adding more friction to switching to the reviewer


I've reviewed the first two commits and they both look great. I'd strongly support a new PR to split them out if the rework of this PR will take some time.

AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt Outdated Show resolved Hide resolved
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Nov 10, 2024
@Arthur-Milchior Arthur-Milchior mentioned this pull request Nov 11, 2024
@Arthur-Milchior
Copy link
Member Author

Done in #17417

I admit I don't know the new reviewer at all. I didn't even know a new reviewer was considered. I'll take a look

@david-allison
Copy link
Member

Done in #17417

I admit I don't know the new reviewer at all. I didn't even know a new reviewer was considered. I'll take a look

It's in the developer options, it looks great and I feel we all strongly want to make it the default

@Arthur-Milchior
Copy link
Member Author

so I tried.
And the issue is that the widget and the shortcut are hardcoded for the first reviewer,even when the settings state to open the second one.
So in order to test the feature, I should first update the widget and shortcut

@Arthur-Milchior
Copy link
Member Author

Rebased on top of #17422 so that the deck picker widget can use the new reviewer.

@Arthur-Milchior
Copy link
Member Author

Feature is now ported to the new reviewer.
I don't know how currently this reviewer decide what is displayed or not. I decide to let it displayed if the deck picker was skipped

@david-allison
Copy link
Member

Conflicts

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

Conflict resolved

@Arthur-Milchior
Copy link
Member Author

I split it some of its commits in #17570 and #17569 so that they can be reviewed faster and hopefully don't get too much merge conflict.
This will ensure this PR only contains:

  • the code move from DeckPicker to Sync
  • the use of Sync from the reviewer

@mikehardy
Copy link
Member


> Task :AnkiDroid:ktlintMainSourceSetCheck FAILED
/home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt:25:1 Unused import
/home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt:283:1 Unexpected indentation (16) (should be 12)
/home/runner/work/Anki-Android/Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt:648:5 Declarations and declarations with comments should have an empty space between.

minor lint issue

/**
* Class in charge of doing the sync work for another activity.
*/
class SyncHandler(
Copy link
Member

Choose a reason for hiding this comment

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

Sync.kt is already pretty big isn't it? Could this reasonably go in its own file?

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Excited to see this go in, looks like there was a lot of progress on the build-up refactors etc and most of those will likely be in today or tomorrow with a bit more back and forth. This one maybe tomorrow or next day depending on time available

@Arthur-Milchior
Copy link
Member Author

I tried ./gradlew lint and got

milchior@Liamwayl:~/ankidroid$ ./gradlew lint
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 1m 18s
153 actionable tasks: 25 executed, 5 from cache, 123 up-to-date

would you have any idea why it success locally and not on github?

@mikehardy
Copy link
Member

would you have any idea why it success locally and not on github?

no idea but looks like it resolved :-)

Currently it's only an extra indirection layer, as all provider are
returning themselves. In the next commit, it'll be used to ensure that
the activity don't have to implements the listener itself.
This class deals with the entire Sync part of the deck picker.
The enum was used only in one function. Adding an intermediary step
does not add clarity to the code.

Each method were also only used once.

I think the resulting code is easier to read, thanks to less layer of abstractions.
Widgets and shortcuts allows to directly review a deck.
This means that automated sync, or even manual sync, is never
available. Except if the user close the reviewer and then manually
open ankidroid. This create a lot of friction on a very important
feature.

This commit enable the sync feature in the reviewer, but hides it
unless the intent actually requested it.

In my opinion, it should be always available. It's available in anki
upstream from the reviewer, and anki allows automated save every 10
minutes. Which means even if your device suddenly dies during a
streak, you only lose up to 10 minutes of review.

Still, this feature at least improve the case that was the most
dangerous for users (and frustrating for me)

I don't know the code of Reviewer2/ReviewerFragment. So this is only
enabled in the legacy reviewer. I hope the code is simple enough for
the feature to be easily ported to the other reviewers now that the
entire sync part of the code was decoupled from the DeckPicker.

Manually tested with:
* signin in (when no account present)
* full sync (requested locally and requested by ankiweb)
* normal sync
* changing the selected deck on the other device

To test it you should use a widget or a shortcut.

One point amy need to be changed. The little icon that state that
there is a not-uploaded change. While it's okay in the deckpicker, it
may not be ideal to have it as soon as we have the first review done.
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.

Fundamentally: I don't feel we should have a UI to sync from the reviewer.

I wouldn't mind it via the JS API, or being performed automatically on open/close, but not as a UI option. It turns the Reviewer into a "do everything" screen

@@ -33,7 +33,11 @@ import com.ichi2.anki.showError
import com.ichi2.anki.utils.ext.dismissAllDialogFragments

class SyncErrorDialog : AsyncDialogFragment() {
interface SyncErrorDialogListener {
interface SyncErrorDialogListenerProvider {
Copy link
Member

Choose a reason for hiding this comment

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

throw exc
}
updateLogin(baseContext, username, auth.hkey)
setResult(RESULT_OK)
Copy link
Member

Choose a reason for hiding this comment

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

This looks incorrect: the activity doesn't wait for the task to complete

* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/

package com.ichi2.anki
Copy link
Member

Choose a reason for hiding this comment

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

can we move this into a subpackage?

/**
* Class in charge of doing the sync work for another activity.
*/
class SyncHandler(
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 far too coupled to implementation details for it to be worthwhile. the UI code shouldn't be here

@@ -153,6 +154,9 @@ class IntentHandler : AbstractIntentHandler() {
} else {
Intent(this, Reviewer::class.java)
}
if (intent.extras?.getBoolean(ENABLE_SYNC) == true) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be handled by the reviewer at all if there's no UI updates? Can we do it when we receive an intent instead?

@@ -206,6 +224,12 @@ open class Reviewer :

private val flagItemIds = mutableSetOf<Int>()

// flag keeping track of when the app has been paused
var activityPaused = false
Copy link
Member

Choose a reason for hiding this comment

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

This should be using lifecycle aware components, or querying the lifecycle manually

@@ -409,6 +445,18 @@ open class Reviewer :
Timber.i("Reviewer:: Home button pressed")
closeReviewer(RESULT_OK)
}
R.id.action_sync -> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this belongs here. If a user wants to sync from a widget, they can turn on auto-sync and have it handled by the code you're adding

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has Conflicts Needs Author Reply Waiting for a reply from the original author Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widget/shortcut should allow to sync
3 participants