Android Weekly Notes

Android Weekly Notes #450

2021-02-24  本文已影响0人  圣骑士wind

Android Weekly Issue #450

Using Hilt’s ViewModelComponent

ViewModelComponent被引入之前, ViewModel的依赖scope只能是: 没有, singleton, activity这三种情况.

在类型上使用注解的时候:

在这个例子中:

@ViewModelScoped // Scopes type to the ViewModel
class UserInputAuthData(
  private val handle: SavedStateHandle // Default binding in ViewModelComponent
) { /* Cached data and logic here */ }

class RegistrationViewModel(
  private val userInputAuthData: UserInputAuthData,
  private val validateUsernameUseCase: ValidateUsernameUseCase,
  private val validatePasswordUseCase: ValidatePasswordUseCase
) : ViewModel() { /* ... */ }

class LoginViewModel(
  private val userInputAuthData: UserInputAuthData,
  private val validateUsernameUseCase: ValidateUsernameUseCase,
  private val validatePasswordUseCase: ValidatePasswordUseCase
) : ViewModel() { /* ... */ }

class ValidateUsernameUseCase(
  private val userInputAuthData: UserInputAuthData,
  private val repository: UserRepository
) { /* ... */ }

class ValidatePasswordUseCase(
  private val userInputAuthData: UserInputAuthData,
  private val repository: UserRepository
) { /* ... */ }

Android Parcelable: There's a better way

介绍这个库: https://github.com/chRyNaN/parcelable

依赖了kotlin serialization来把数据序列化成Parcels.

Why we use Kotlin Multiplatform and Redux

为什么使用了Kotlin Multiplatform和Redux来做一个小app.

文章里的图看起来挺好的(就是没仔细看).

How do we handle multi-modules navigation on our Android app

多module应用的导航.

官方的navigation也支持多module:
https://developer.android.com/guide/navigation/navigation-dynamic?authuser=1
但是和Fragment强相关.

这篇文章提供的解决方案和依赖注入相关.
demo在这里: https://github.com/PhilippeBoisney/android-multi-modules-navigation-demo

Ktor and GraphQL

如何用Ktor写一个GraphQL的server.

Helping You Understand The Syntax of Jetpack Compose

帮你读懂Jetpack Compose的语法.

Epoxy—Build Declarative & Reusable UI Components

优势: ui元素和controller独立, ui元素可以复用.

How runBlocking May Surprise You

关于协程和主线程的一些有趣的讨论, 图不错.

What’s new in Hilt and Dagger 2.31

Hilt的新特性:

Sealed goodies coming in Kotlin 1.5

Kotlin1.5推出了sealed interface.

Language Injections in Android Studio / IntelliJ IDEA

同一个文件用不同的语言.

比如Room中的sql语句.

Advanced FP for the Enterprise Bee: Higher Kinded Types

函数式编程系列文章的第三篇.

Code

上一篇 下一篇

猜你喜欢

热点阅读