Status Update
Comments
ra...@google.com <ra...@google.com>
al...@google.com <al...@google.com>
sr...@google.com <sr...@google.com>
yo...@gmail.com <yo...@gmail.com> #3
xa...@google.com <xa...@google.com> #4
il...@google.com <il...@google.com> #5
Currently the combination of Hilt, SavedStateHandle and Safe args is not possible. The closest I've seen is to drop using safe args and just use magic strings. This also not ideal re dependency inversion as now you have to construct a mock SavedStateHandle for unit tests etc.
class ArticleViewModel @ViewModelInject constructor(
private val repository: ArticleRepository,
@Assisted savedStateHandle: SavedStateHandle
) {
// FIXME: oops, magic "articleId" string
private val articleId: Long = savedStateHandle["articleId"]
?: throw IllegalArgumentException("Article ID required")
}
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #6
I thought I needed this, but then I realized that I can just create an empty Bundle, store the Fragment's arguments in it as a Bundle (so a Bundle inside a Bundle) and use that to initialize the SavedStateHandle. Then I can just retrieve the arguments from the SavedStateHandle and use the already existing fromBundle
method.
What I like about this is that I get to have immutable init arguments, as long as I store the Fragment's arguments with a key that I would never use for other entries.
With a helper function and a base ViewModel class you can hide this entire process and have ViewModels that expose the arguments object as property/member of the ViewModel itself.
Description
Android Gradle Plugin: 3.3.0-alpha07
Gradle: 4.9
Load the arch components Gihub browser sample app
Actual:
With stable AGP versions (e.g. 3.1.2 or 3.1.4), it fails to sync and forces you to use AGP 3.3a7 .
Expected:
preview AS builds should sync with any AGP stable version from at least the last 12 months.