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 separate #17417

Closed
wants to merge 3 commits into from
Closed

Conversation

Arthur-Milchior
Copy link
Member

This PR is a preamble for #17399. It contains everything related to cleaning the sync code and separating it from the DeckPicker.

I moved most of the code in a single file, that can be reused by the reviewer. I remove SyncStatus which added extra abstraction layer without , I believe, adding any clarity to the code. And replaced a literal by a constant

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.

One question, nothing blocking I feel, presuming this is tested

Comment on lines +184 to +213
fun updateSyncIconFromState(menu: Menu) {
val state = syncMenuState
if (state == null) {
return
}
val menuItem = menu.findItem(R.id.action_sync)
val provider = MenuItemCompat.getActionProvider(menuItem) as? SyncActionProvider
?: return
val tooltipText = when (state.syncIcon) {
SyncIconState.Normal, SyncIconState.PendingChanges -> R.string.button_sync
SyncIconState.OneWay -> R.string.sync_menu_title_one_way_sync
SyncIconState.NotLoggedIn -> R.string.sync_menu_title_no_account
}
provider.setTooltipText(activity.getString(tooltipText))
when (state.syncIcon) {
SyncIconState.Normal -> {
BadgeDrawableBuilder.removeBadge(provider)
}
SyncIconState.PendingChanges -> {
BadgeDrawableBuilder(activity)
.withColor(activity.getColor(R.color.badge_warning))
.replaceBadge(provider)
}
SyncIconState.OneWay, SyncIconState.NotLoggedIn -> {
BadgeDrawableBuilder(activity)
.withText('!')
.withColor(activity.getColor(R.color.badge_error))
.replaceBadge(provider)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this DeckPicker specific?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, it is specific to the deck picker.
One of the point I mentioned in the full PR is that I don't know whether I'd want the badge to appear in the reviewer or not. I'd expect the "full sync needed" icon to be very important. The normal sync, as it will appear after the first review, it may be too much of a distraction.

I'd argue that, even if we decide to let it be used in the deck picker only, it's still nice to have the code in Sync, because the DeckPicker is already very big

AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt Outdated Show resolved Hide resolved
@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Nov 11, 2024
This class deals with the entire Sync part of the deck picker.
Ensuring there is no typo when using deck id in a reviewer intent
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.
@Arthur-Milchior Arthur-Milchior removed the Needs Author Reply Waiting for a reply from the original author label Nov 11, 2024
@Arthur-Milchior
Copy link
Member Author

Closing it, because I was able to deal with both reviewer, and had to do change to this system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Second Approval Has one approval, one more approval to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants