Android Weekly Issue #484
Don't let ViewModel know about framework level dependencies
ViewModel不应该有framework的依赖.
文章里测试的写法是那种嵌套的, 跟iOS很像的.
代码: https://github.com/PatilShreyas/ViewModelGoodPractice
Testing Hybrid Jetpack Compose Apps
如何测试XML和Compose混合的UI.
Lift on scroll in Jetpack Compose
Top app bar在下面的内容滚动上来以后, 会有一个高度提升显示阴影的效果.
如何在Compose上实现这种liftOnScroll
的效果呢.
val LazyListState.elevation: Dp
get() = if (firstVisibleItemIndex == 0) {
// For the first element, use the minimum of scroll offset and default elevation
// i.e. a value between 0 and 4.dp
minOf(firstVisibleItemScrollOffset.toFloat().dp, AppBarDefaults.TopAppBarElevation)
} else {
// If not the first element, always set elevation and show the shadow
AppBarDefaults.TopAppBarElevation
}
Composing palettes
Compose的调色板.
可以从Bitmap提取颜色.
demo: https://github.com/tkuenneth/android-demos/tree/master/misc/PaletteDemo
Effective Kotlin Item 50: Eliminate obsolete object references
我们要注意不要持有已经不用的对象的引用.
尤其是这个对象很大或者很多的时候.
Exact alarm improvements-Android12
Android 12对闹钟的改进.
How to master Swipeable and NestedScroll modifiers in Jetpack Compose
要实现一个bottom sheet, 展开后是parent的全部高度, 内容可以滚动, 但是header保持不动.
整体的实现:
https://gist.github.com/arcadefire/7fe138c0ded1a36bee6dd57acdfa3d18
Using WorkManager on Android 12
Android 12加了前台服务的启动限制:
https://developer.android.com/about/versions/12/foreground-services
也就是说, 除了一些特殊情况, Android 12上不允许从后台启动前台服务.
所以在WorkManager 2.7开始, 对紧急的任务( expedited jobs)做了处理.
val request = OneTimeWorkRequestBuilder<HighPriorityWorker>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
WorkManager.getInstance(context).enqueue(request)
Controlling TextView MinWidth
关于TextView的最小宽度控制.
Seeing What Talkback Sees
可以查看Talkback看到的文字, debug accessibility的信息.
Code
- https://github.com/kojofosu/Quantitizer
- https://github.com/microsoft/surface-duo-window-manager-samples/tree/main/TravelPlanner
- https://github.com/manueldidonna/waves-timer-animation 倒计时, 有一个水流向下的动画.
- https://github.com/sarnavakonar/Gamebaaz 一个用kotlin做前后端的完整应用.
- https://github.com/square/workflow-kotlin 状态机.