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

improvement: introduce DeckPickerViewModel #17690

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

david-allison
Copy link
Member

Purpose / Description

We want more ViewModels in 2025. Let it start

Approach

  • Extract launchCollectionInLifecycleScope
  • Document remove
  • Create class
  • Bring method across

How Has This Been Tested?

Deleted a deck in the UI of an API 34 emulator via context menu

Checklist

  • 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 force-pushed the deck-picker-view-model branch 2 times, most recently from 68eb0e2 to 2250587 Compare December 29, 2024 22:43
* @see deleteDeck
* @see DeckDeletionResult
*/
val deckDeletedNotification = MutableSharedFlow<DeckDeletionResult>()
Copy link
Member Author

Choose a reason for hiding this comment

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

This could be part of an 'undoableSnackbar' flow, didn't seem useful

decks.name(focusedDeck),
decks.cardCount(focusedDeck, includeSubdecks = true),
decks.isFiltered(focusedDeck),
decks.name(viewModel.focusedDeck),
Copy link
Member Author

@david-allison david-allison Dec 29, 2024

Choose a reason for hiding this comment

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

@SanjaySargam showDeleteDeckConfirmationDialog is only used when pressing 'DEL', in all other cases, we delete unconditionally and show an 'undo' snackbar

Was this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it is intentional.

            KeyEvent.KEYCODE_DEL -> {
                // This action on a deck should only occur when the user see the deck name very clearly,
                // that is, when it appears in the trailing study option fragment
                if (fragmented) {
                    if (event.isShiftPressed) {
                        // Shortcut: Shift + DEL - Delete deck without confirmation dialog
                        Timber.i("Shift+DEL: Deck deck without confirmation")
                        deleteDeck(focusedDeck)
                    } else {
                        // Shortcut: DEL
                        Timber.i("Delete Deck from keypress")
                        showDeleteDeckConfirmationDialog()
                    }
                    return true
                }
            }

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.

LGTM and here come the ViewModels 😄
fix conflict + second review

@mikehardy mikehardy added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 6, 2025
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 code is ok, left some issues to discuss.

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Jan 7, 2025
We want to use a ViewModel for DeckPicker
This is the start

* extract 'focusedDeck'
  * will be used in the next commit
* inline confirmDeckDeletion
  * removing unnecessary 'dismiss' calls
* extract `deleteDeck`
* introduce `DeckDeletionResult`
@david-allison david-allison force-pushed the deck-picker-view-model branch from 2903a0c to b9b20d7 Compare January 8, 2025 02:29
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Jan 8, 2025
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.

Ok, let's move forward!

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Jan 8, 2025
@lukstbit lukstbit added this pull request to the merge queue Jan 8, 2025
Merged via the queue into ankidroid:main with commit e35b5b9 Jan 8, 2025
9 checks passed
@github-actions github-actions bot added this to the 2.21 release milestone Jan 8, 2025
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jan 8, 2025
@david-allison david-allison deleted the deck-picker-view-model branch January 8, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants