Android Weekly Notes #427
2020-08-23 本文已影响0人
圣骑士wind
Android Weekly Issue #427
Composite ViewModel
添加需求会让ViewModel变得越来越庞大, 所以需要拆分ViewModel.
具体做法是抽取了delegates. 每个delegate是一个mini的ViewModel.
作者还有例子.
作者的例子用了这个状态管理的库: https://github.com/beworker/knot/
首先声明Delegate的接口:
interface Delegate {
fun CompositeKnot<State>.register()
fun CompositeKnot<State>.onEvent(event: Event): Boolean
}
然后从构造传入ViewModel:
class CompositeBooksViewModel(
private val delegates: List<Delegate>
) : BooksViewModel()
初始化:
init {
for (delegate in delegates) {
with(delegate) { knot.register() }
}
knot.compose()
}
实际的逻辑处理就被放在了代理中:
class ClearButtonDelegate : Delegate {
override fun CompositeKnot<State>.register() {
registerDelegate<Change, Nothing> {
changes {
reduce<Change.Clear> { change ->
when (this) {
is State.Content -> State.Empty.only
is State.Empty -> only
else -> unexpected(change)
}
}
}
}
}
}
A glowing progress ring with rounded ends for Android
一个发光的圆圈进度条.
Introducing scrcast
一个录屏的库.
All about Hilt
关于依赖注入的讨论.
Hilt的使用介绍.
Hilt Migration Guide
本期还有一个migration guide: 从使用dagger-android迁移到Hilt.
Android TV: Best practices for engaging Apps
改造TV app的最佳实践.
Exploring the Google Play In-App Review API
Google Play In-App Review的使用.
Android Vitals - Why did my process start?
We can combine our findings from the previous post to determine cold start accurately. A cold start:
- Has a process importance of IMPORTANCE_FOREGROUND on app startup.
- Has the first activity created before the first post is dequeued.
- Has the first activity created with a null bundle.