refactor: Break navigation dependency cycles with :core:navigation #305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous code generally started an activity by having the activity provide a method in a companion object that returns the relevant intent, possibly taking additional parameters that will be included in the intent as extras.
E.g., if A wants to start B, B provides the method that returns the intent that starts B.
This introduces a dependency between A and B.
This is worse if B also wants to start A.
For example, if A is
StatusListActivity
and B isViewThreadActivity
. The user might click a status inStatusListActivity
to view the thread, startingViewThreadActivity
. But from the thread they might click a hashtag to view the list of statuses with that hashtag. NowStatusListActivity
andViewThreadActivity
have a circular dependency.Even if that doesn't happen the dependency means that any changes to B will trigger a rebuild of A, even if the changes to B are not relevant.
Break this dependency by adding a
:core:navigation
module with anapp.pachli.core.navigation
package that containsIntent
subclasses that should be used instead. Thequadrant
plugin is used to generate constants that can be used to launch activities by name instead of by class, breaking the dependency chain.The plugin uses the
Activity
names from the manifest, so when an activity is moved in the future the constant will automatically update to reflect the new package name.If the activity's intent requires specific extras those are passed via the constructor, with companion object methods to extract them from the intent.
Using the intent classes from this package is enforced by a lint
IntentDetector
which will warn if any intents are created using a class literal.