arch: introduce 'Destination' pattern#21023
Conversation
ee2bc18 to
bb40df7
Compare
BrayanDSO
left a comment
There was a problem hiding this comment.
I suggest splitting the anki-common part from the destination part on different PRs
Currently, I'm still trying to understand the purpose/goal/usefulness of the destination module
|
I've done some digging and (surprisingly) I don't believe we have cycles in our navigation graph. EDIT: README was clean; I may want a note in When we move to feature modules [for build speed + architecture], we should aim to have no dependencies between feature modules.
'Destination/navigate' acts as a 'mediator' in Google's terminology, as this is the one place where there would need to be dependencies between features: https://developer.android.com/topic/modularization/patterns#communication Once we've removed the bulk of cross-feature dependencies via destinations, we can pick higher yield modules to extract, rather than needing to work from the leaf nodes in the nav graph Just to note: a lot of what's in the two linked pages above is far too 'enterprise' for us. End goals:
|
This should be a responsibility of the browser, not the destination Assisted-by: Claude Opus 4.7
* ToCard => ScrollToCard * Move EXTRA_CARD_ID_KEY to ViewModel This should be a responsibility of the browser, not the destination Assisted-by: Claude Opus 4.7 - all
bb40df7 to
86580eb
Compare
| import net.ankiweb.rsdroid.RustCleanup | ||
| import net.ankiweb.rsdroid.exceptions.BackendNetworkException | ||
| import timber.log.Timber | ||
| import com.ichi2.anki.destinations.Destination as NavigateDestination |
There was a problem hiding this comment.
I am not a big fan of this, where we have to explicity handle the import, maybe rename the old one and mark that as deprecated?
i.e.
interface Destination {
fun toIntent(context: Context): Intent
}
to
@Deprecated(
"Use com.ichi2.anki.destinations.Destination + navigate(). See #20558.",
ReplaceWith("com.ichi2.anki.destinations.Destination"),
)
interface IntentDestination {
fun toIntent(context: Context): Intent
}
or anything better?
There was a problem hiding this comment.
I'd rather handle this in a follow up. I've kept the original issue open, and "doing it right" in the next PR is better than a temporary rename
There was a problem hiding this comment.
I added a TODO, but not the rename, would rather churn the code once
Decouples the navigation contract from the app module. When we move to a multi-module approach, we will not want feature modules depending on other feature modules. Moving navigation (and interface definitions for navigating to screens) to a lower module means we can break cross-module dependencies/circular dependencies. * Destination will be subclassed, and these subclasses define the requirements for types of navigation * Card Browser may take a CardId to scroll to * Exposed publicly by com.ichi2.anki.destinations.navigate(Destination) extensions Issue 20558 Assisted-by: Claude Opus 4.7
86580eb to
05e0577
Compare
* AnkiDroidNavigator handles the top-level 'when(Destination)' * Each package contains `FeatureDestination.toIntent(Context)` * When a feature module split occurs, the nav implementation lives with the feature Issue 20558 - initial implementation of navigation pattern Assisted-by: Claude Opus 4.7
05e0577 to
850d394
Compare
Split into:
Note
Assisted-by: Claude Opus 4.7
Purpose / Description
When we move to feature modules, we need a way to navigate between features without introducing cross-module dependencies (as these will nullify the build time/parallelism goals we hope to coomplish). This PR introduces a
Destinationclass andnavigate(Destination)Sample usage in an Activity/Fragment
Fixes
Approach
anki-commonmodule skeleton #21028navigatein a similar style to Refactor: extractCrashReportServiceinterface to:common#20739BrowserDestinationBrowserDestinationto the new module and applied the patternHow Has This Been Tested?
Unit tested
Checklist