Android Weekly Notes #471 Android Weekly Issue #471

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>

需要增加這個文件裏的幫助方法:
https://github.com/android/architecture-components-samples/blob/8f4936b34ec84f7f058fba9732b8692e97c65d8f/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt

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>

https://cs.android.com/androidx/platform/tools/dokka-devsite-plugin/+/master:testData/compose/source/androidx/compose/runtime/SnapshotState.kt;l=488-500;drc=6fed3de7a56143de954d55e508a7449deb9af582

Using the Kotlin standard library from Java

混合項目如何用.

Code

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章