Anki-Android icon indicating copy to clipboard operation
Anki-Android copied to clipboard

Abstract browser access with BrowserDestinations

Open lukstbit opened this issue 8 months ago • 5 comments

[!IMPORTANT] We use this as a reference for discussion, please don't ask to be assigned until something is decided on the approach.

Original comment: https://github.com/ankidroid/Anki-Android/pull/20532#discussion_r2968007120

I was hoping we could slowly move to a Destination-based model

We're likely going to go multi-module to improve build times, and our Destination classes both make the API of the intents clear, and reduce bugs from typos.

I'm ok with this.

The usages that could be refactored and I found with a quick search:

https://github.com/ankidroid/Anki-Android/blob/8d288e88952e10a4bda83a3978f6c463603adf35/AnkiDroid/src/main/java/com/ichi2/anki/NavigationDrawerActivity.kt#L390-L395

https://github.com/ankidroid/Anki-Android/blob/8d288e88952e10a4bda83a3978f6c463603adf35/AnkiDroid/src/main/java/com/ichi2/anki/BackendImporting.kt#L73-L81

https://github.com/ankidroid/Anki-Android/blob/8d288e88952e10a4bda83a3978f6c463603adf35/AnkiDroid/src/main/java/com/ichi2/anki/filtered/FilteredDeckOptionsFragment.kt#L128-L132

https://github.com/ankidroid/Anki-Android/blob/8d288e88952e10a4bda83a3978f6c463603adf35/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EmptyCardsDialogFragment.kt#L255-L259

lukstbit avatar Mar 23 '26 07:03 lukstbit

Hello! 👋 Thanks for logging this issue. Please remember we are all volunteers here, so some patience may be required before we can get to the issue. Also remember that the fastest way to get resolution on an issue is to propose a change directly, https://github.com/ankidroid/Anki-Android/wiki/Contributing

welcome[bot] avatar Mar 23 '26 07:03 welcome[bot]

Any issue if we alias these as CardBrowserDestination, and add a .toIntent() method:

https://github.com/ankidroid/Anki-Android/blob/b825f75f4119f2dddcd7f4f3b776ecd891fd172f/AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserLaunchOptions.kt#L24-L71

https://github.com/ankidroid/Anki-Android/blob/b825f75f4119f2dddcd7f4f3b776ecd891fd172f/AnkiDroid/src/main/java/com/ichi2/anki/browser/BrowserDestination.kt#L27-L59

david-allison avatar Mar 23 '26 08:03 david-allison

Hello, I’ve been reading through the existing BrowserDestination / CardBrowserLaunchOptions code to understand the intended direction here. If I understood correctly, the likely approach would be to introduce destination variants covering the current launch cases and then replace the direct Intent(..., CardBrowser::class.java) usages with toIntent() calls.

mixelas avatar Mar 24 '26 15:03 mixelas

@lukstbit

  • common is below libanki in the dependency tree
  • Destinations will want to be above libAnki so they can reference DeckId etc...
    • Alternately: the common types could be moved out of libanki into :common

Brief thoughts:

  • Add a :destinations module, referencing :libanki, with the intention that it will contain destinations for all types
    • Planned to be pure JVM once libanki becomes a java-library
  • feature-[card]browser would expose Destination.toIntent() for the specific destinations which it handles
    • For now, this will be in com.ichi2.anki.browser, until the browser is split into a module
  • :AnkiDroid would implement a navigate(Destination) method:
    • a large when clause mapping from the domain Destination into an Intent, then launching the intent
  • navigate(Destination) is defined, but not implemented in :destinations

david-allison avatar Apr 29 '26 17:04 david-allison

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

github-actions[bot] avatar Aug 12 '26 03:08 github-actions[bot]