Android Weekly Notes #449

Android Weekly Issue #449

Android Kotlin Analytics Made Simple!

这居然还有一个awesome-analytics的list:
https://github.com/onurakpolat/awesome-analytics/blob/master/README.md

讲了analytics库的包装和注入.

Avoid backing properties for LiveData and StateFlow

LiveData的这种写法, 算是比较典型:

class MyViewModel: ViewModel() {
   val loading: LiveData
       get() = _loading
   private val _loading = MutableLiveData()
}

这种命名方法甚至在官方的convention里也有:
https://kotlinlang.org/docs/reference/coding-conventions.html#property-names

建议的方式是使用ViewModel接口或者抽象类.

abstract class MyViewModel: ViewModel() {
   abstract val loading: LiveData
}
class MyViewModelImpl: MyViewModel() {
   override val loading = MutableLiveData()
}

Migrate from LiveData to StateFlow and SharedFlow

用StateFlow和SharedFlow替换LiveData.

LiveData的问题:

  • LiveData的读写只能在主线程进行.

验证可行性, 例子:

  • 用StateFlow替换LiveData.
  • ShareFlow替换SingleLiveEvent. (SingleLiveEvent可以用来触发一次性的action.)

My MutableStateFlow Didn’t Emit!

一个MutableStateFlow使用时遇到的问题.

Choose Wisely: 5 Ways To Show A Message In Android

五种显示信息的方式, 该如何选择.

这个流程图很好:
https://vladsonkin.com/wp-content/uploads/2021/01/show-message-android-diagram.jpg

Code

  • https://github.com/futuredapp/donut 环形图表.
  • https://github.com/WahdanZ/SpockAdb AndroidStudio插件, 控制项目和设备.
  • https://github.com/int02h/skelly 在loading的时候只显示View骨架闪烁, 很有意思.
  • https://github.com/chrisbanes/accompanist jetpack扩展方法的集合.

你可能感兴趣的:(Android Weekly Notes #449)