Android Weekly Notes #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  getLifecycleAwareState(
    flow: Flow,
    initialValue: T,
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): State {
    return remember(flow, lifecycleOwner) {
        flow.flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState)
    }.collectAsState(initialValue)
}

About DI Frameworks

讨论DI的框架.

作者介绍了ta仅仅18行的注入框架:


val injectionFactories = mutableMapOf, String?>, () -> Any>()

inline fun  inject(named: String? = null) =
    object: ReadOnlyProperty {
        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  factory(named: String? = null, noinline block: () -> T) {
    injectionFactories[T::class to named] = block
}

inline fun  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



    
    
    


需要增加这个文件里的帮助方法:
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  derivedStateOf(calculation: () -> T): State

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

  • https://github.com/Droppers/TimeRangePicker
  • https://github.com/robfletcher/strikt
  • https://github.com/rickclephas/KMP-NativeCoroutines
  • https://github.com/organicmaps/organicmaps
  • https://github.com/zsmb13/requireKTX

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