ArchiveorgSoftwareThe Official App for DroidKaigi 2021 FeaturesNow this app has the Feed feature. We will deliver Feed and events related to DroidKaigi. Designhttps://www.figma.com/file/IFlrbfmBSdYvUz7VmSzfLV/DroidKaigi2021official_appTry it outThe builds being distributed through mobile app distribution services.Production (TBR)Try the latest staging through and more... (tbw)ContributingWe always welcome any and all contributions! See CONTRIBUTING.md[1] for more informationFor Japanese speakers, please see CONTRIBUTING.ja.md[2]RequirementsLatest Android Studio Arctic Fox and higher. You can download it from this page[3].Kotlin MultiplatformTBDJetpack ComposeModern DevelopmentJetpack ComposeKotlin Coroutines & FlowsDagger HiltDataStoreKotlin MultiplatformUnidirectional data flowCompose processing and ViewModel processing are performed by Unidirectional data flow. Compose unidirectional data flowBy performing State hoisting[4](pass the value and receive the event), Jetpack Compose displays with unidirectional data flow.```kotlin/** * stateful */@Composablefun FeedScreen( onNavigationIconClick: () -> Unit, onDetailClick: (Feed) -> Unit,) {...val ( state, effectFlow, dispatch,) = use(feedViewModel())val context = LocalContext.currenteffectFlow.collectInLaunchedEffect { effect -> when (effect) { is FeedViewModel.Effect.ErrorMessage -> { scaffoldState.snackbarHostState.showSnackbar( effect.appError.getReadableMessage(context) ) } }}FeedScreen( // ... FeedContents = state.filteredFeedContents, onFavoriteChange = { dispatch(FeedViewModel.Event.ToggleFavorite(Feed = it)) }, // ...)}/** * stateless */@Composableprivate fun FeedScreen( // ... FeedContents: FeedContents, onFavoriteChange: (Feed) -> Unit, // ...) { Column { BackdropScaffold( backLayerBackgroundColor = MaterialTheme.colors.primarySurface, scaffoldState = scaffoldState, backLayerContent = { BackLayerContent(filters, onFavoriteFilterChanged) }// ... )// ... }}```ViewModel unidirectional data flowThis app handles the ViewModel with an MVI-like interface.Compose```kotlin val ( state, effectFlow, dispatch, ) = use(feedViewModel())val context = LocalContext.currenteffectFlow.collectInLaunchedEffect { effect -> when (effect) { is FeedViewModel.Effect.ErrorMessage -> { scaffoldState.snackbarHostState.showSnackbar( effect.appError.getReadableMessage(context) ) } }}FeedScreen( // ... FeedContents = state.filteredFeedContents, onFavoriteChange = { dispatch(FeedViewModel.Event.ToggleFavorite(Feed = it)) }, // ...```This state, effectFlow and dispatch are created from ViewModel.state represents the state that the UI should display.effectFlow represents a one-time event such as a Snackbar display.And dispatch represents a change of state.ViewModel Interfacekotlininterface UnidirectionalViewModel { val state: StateFlow val effect: Flow fun event(event: EVENT)}use(viewModel) function```kotlin@Composableinline fun use( viewModel: UnidirectionalViewModel,): StateEffectDispatch { val state by viewModel.state.collectAsState()val dispatch: (EVENT) -> Unit = { event -> viewModel.event(event)}return StateEffectDispatch( state = state, effectFlow = viewModel.effect, dispatch = dispatch)}```Testable & Previewable & Faster debugJetpack Compose is still a new technology. We are thinking of best practices.We will try to improve testing, preview and build by using Fake.For example, this app allows you to interact with the Android Studio Preview as if it were a real app. This is possible by creating a Fake ViewModel and making it reliable.How to make Fake's ViewModel reliableDo the same test for Fake and the real thing by testing against the interface. This makes Fake's ViewModel reliable.This technique of doing the same test against Fake was introduced in "Build testable apps for Android" session(Google I/O'19). You can also prevent forgetting to update by forcing the implementation with interface and .Also, by forcing the implementation with interface and " Exhaustive[5] ", it is possible to prevent forgetting to update Fake's ViewModel.kotlinoverride fun event(event: FeedViewModel.Event) { coroutineScope.launch { @Exhaustive when (event) { is FeedViewModel.Event.ChangeFavoriteFilter -> {How to make it previewable and testableThis app uses fake's ViewModel to enable preview. kotlin@Preview(showBackground = true)@Composablefun FeedScreenPreview() { Conferenceapp2021FeedTheme(false) { ProvideFeedViewModel(viewModel = fakeFeedViewModel()) { FeedScreen { } } }}How to debug fast?If you want to check the UI display, you can check it in the Preview of Android Studio.In that case, the required task is :uicomponent-compose:main:compileDebugKotlin.Therefore, there is no need to build the data module that contains the definitions such as API and the build of Android dex, so you can quickly build and check.Also, changes to the data layer do not affect the ui module, so you can build faster. Overall architecture Thank you for contributing!ContributorsGitHub : Contributors[6]Designernontan[7]Android Gradle plugin requires Java 11 to run. You are currently using Java 1.XJDK 1.8 is a requirement to build an Android project basically, but AGP 7.0 requires JDK 11. Please make sure you are using Java 11. Please note that the java version of Gradle Daemon is determined at the launch-time, so ./gradlew --stop might be required for you.The option 'android.enableBuildCache' is deprecated.android.enableBuildCache is REMOVED in AGP 7.0. android.enableBuildCache=false has no issue but builds randomly succeed with true value. This may affect to those who declare android.enableBuildCache=true in their $GRADLE_USER_HOME/gradle.properties. To restore the repository download the bundle wget https://archive.org/download/github.com-DroidKaigi-conference-app-2021_-_2021-03-02_15-56-50/DroidKaigi-conference-app-2021_-_2021-03-02_15-56-50.bundle and run: git clone DroidKaigi-conference-app-2021_-_2021-03-02_15-56-50.bundle Source: https://github.com/DroidKaigi/conference-app-2021[8]Uploader: DroidKaigi[9]Upload date: 2021-03-02 References^ CONTRIBUTING.md (archive.org)^ CONTRIBUTING.ja.md (archive.org)^ this page (developer.android.com)^ State hoisting (developer.android.com)^ Exhaustive (github.com)^ Contributors (github.com)^ nontan (github.com)^ https://github.com/DroidKaigi/conference-app-2021 (github.com)^ DroidKaigi (github.com)

weiterlesen: RSS Quelle öffnen