Android Weekly Issue #471
Building a Pride Rainbow Easter Egg into the Over Android App
他们app为了LGBTQ+ community做的一个菜单.
使用OpenGL实现的, 所以用了GLSurfaceView
.
用了GLSL Shader Program: Vertex Shader + Fragment Shader.
Migration to compose
一个HarryPoter的app. 改造用compose了:
https://github.com/hongbeomi/HarryPotter/tree/compose
有个这个方法:
@Composable
fun <T> getLifecycleAwareState(
flow: Flow<T>,
initialValue: T,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): State<T> {
return remember(flow, lifecycleOwner) {
flow.flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState)
}.collectAsState(initialValue)
}
About DI Frameworks
讨论DI的框架.
作者介绍了ta仅仅18行的注入框架:
val injectionFactories = mutableMapOf<Pair<KClass<out Any>, String?>, () -> Any>()
inline fun <reified T: Any> inject(named: String? = null) =
object: ReadOnlyProperty<Any, T> {
private val value: T by lazy {
@Suppress("UNCHECKED_CAST")
injectionFactories.getValue(T::class to named).invoke() as T
}
override fun getValue(thisRef: Any, property: KProperty<*>): T = value
}
inline fun <reified T: Any> factory(named: String? = null, noinline block: () -> T) {
injectionFactories[T::class to named] = block
}
inline fun <reified T: Any> single(named: String? = null, noinline block: () -> T) {
block.invoke().let { factory(named) { it } }
}
Building assertions with Strikt
一个assertion library:
https://github.com/robfletcher/strikt
App Actions: Getting Started
App Actions教程.
从实现到测试, 很全面.
KSP: Fact or kapt?
KSP (Kotlin Symbol Processor)是google推出的新的写编译器插件的api.
可以写注解处理器. 比kapt更快.
原因:
Firstly, KSP is faster since kapt depends on compiling Kotlin to Java stubs for consumption by thejavax.lang.model API used by Java annotation processors. Compiling these stubs takes a significant amount of time, and since KSP can skip this step we can write faster processors.
很多基于注解的库都被提出了支持KSP的issue. 如果迁移成功, 将会大幅度提升效率.
然后文章出了一个例子, 教大家怎么用.
这里是作者的sample: https://github.com/drawers/ksp-sample
居然还有测试工具:
https://github.com/tschuchortdev/kotlin-compile-testing
Build sophisticated search features with AppSearch
App Search看上去很有用.
Navigation: Multiple back stacks
navigation sample:
https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample
<navigation
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@+id/home">
<include app:graph="@navigation/home"/>
<include app:graph="@navigation/list"/>
<include app:graph="@navigation/form"/>
</navigation>
Announcing requireKTX
一个小小的, 用来处理null的库.
https://github.com/zsmb13/requireKTX
Compose: List / Detail - Testing part 2
Compose的list/detail测试.
Advanced Kotlin Collection Functionality
高级的Kotlin集合功能.
A crash course in classpaths: Run!
编译和运行classpath啥的.
有一系列的原理性文章: https://dev.to/autonomousapps
Plumbing data with derived state in Compose
/**
* Creates a [State] object whose [State.value] is the result of [calculation]. The result of
* calculation will be cached in such a way that calling [State.value] repeatedly will not cause
* [calculation] to be executed multiple times, but reading [State.value] will cause all [State]
* objects that got read during the [calculation] to be read in the current [Snapshot], meaning
* that this will correctly subscribe to the derived state objects if the value is being read in
* an observed context such as a [Composable] function.
*
* @param calculation the calculation to create the value this state object represents.
*/
fun <T> derivedStateOf(calculation: () -> T): State<T>
Using the Kotlin standard library from Java
混合项目如何用.