Skip to content

Instantly share code, notes, and snippets.

View aartikov's full-sized avatar

Artur Artikov aartikov

View GitHub Profile
@aartikov
aartikov / AppAugmentedFaceNode.kt
Created April 19, 2024 16:57
AugmentedFaceNode for SceneView
package com.example.arcoremask
import com.google.android.filament.Engine
import com.google.android.filament.IndexBuffer
import com.google.android.filament.MaterialInstance
import com.google.android.filament.RenderableManager
import com.google.android.filament.RenderableManager.PrimitiveType
import com.google.android.filament.VertexBuffer
import com.google.android.filament.VertexBuffer.AttributeType
import com.google.android.filament.VertexBuffer.VertexAttribute.POSITION
@aartikov
aartikov / MultiChildStack.kt
Created February 12, 2024 10:51
multiChildStack for Decompose
package ru.mobileup.template.core.utils
import com.arkivanov.decompose.Child
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.router.stack.StackNavigationSource
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.essenty.lifecycle.Lifecycle
@aartikov
aartikov / App.kt
Created January 10, 2023 21:45
Decompose DI
class App : Application(), KoinProvider {
override lateinit var koin: Koin
private set
override fun onCreate() {
super.onCreate()
koin = createKoin()
}
@aartikov
aartikov / DecomposeUtils.kt
Created December 14, 2022 09:29
Converts Decompose Value to StateFlow
fun <T : Any> Value<T>.toStateFlow(lifecycle: Lifecycle): StateFlow<T> {
val state = MutableStateFlow(this.value)
if (lifecycle.state != Lifecycle.State.DESTROYED) {
val observer = { value: T -> state.value = value }
subscribe(observer)
lifecycle.doOnDestroy {
unsubscribe(observer)
}
}
@aartikov
aartikov / DecomposeUtils.kt
Created December 14, 2022 09:27
Creates CoroutineScope for Decompose component
fun ComponentContext.componentCoroutineScope(): CoroutineScope {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
if (lifecycle.state != Lifecycle.State.DESTROYED) {
lifecycle.doOnDestroy {
scope.cancel()
}
} else {
scope.cancel()
}
@aartikov
aartikov / DownloadNotificationManager.kt
Created January 25, 2021 09:38
DownloadNotificationManager
abstract class DownloadNotificationManager(context: Context) : DefaultFetchNotificationManager(context) {
// Copied from DefaultFetchNotificationManager to hide Pause button
override fun updateNotification(notificationBuilder: NotificationCompat.Builder,
downloadNotification: DownloadNotification,
context: Context) {
val smallIcon = if (downloadNotification.isDownloading) {
android.R.drawable.stat_sys_download
} else {
android.R.drawable.stat_sys_download_done
@aartikov
aartikov / DelegateAccess.kt
Created January 14, 2021 11:03
Wrap MutableStateFlow to property delegate
internal object DelegateAccess {
internal val delegate = ThreadLocal<Any?>()
internal val delegateRequested = ThreadLocal<Boolean>().apply { set(false) }
}
internal val <T> KProperty0<T>.delegate: Any?
get() {
try {
DelegateAccess.delegateRequested.set(true)
this.get()
@aartikov
aartikov / navigation.kt
Last active September 25, 2020 15:25
navigation
private fun bindNavigationContext() {
val builder = NavigationContext.Builder(this, navigationFactory)
val currentFlowFragment = getCurrentFlowFragment()
if (currentFlowFragment is ContainerIdProvider) {
builder.fragmentNavigation(
currentFlowFragment.childFragmentManager,
(currentFlowFragment as ContainerIdProvider).containerId
)
package me.aartikov.storesample
import com.dropbox.android.external.store4.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
@aartikov
aartikov / PactSample.kt
Created November 14, 2019 05:40
Pact Sample
package me.aartikov.packtest
import au.com.dius.pact.consumer.ConsumerPactTestMk2
import au.com.dius.pact.consumer.MockServer
import au.com.dius.pact.consumer.dsl.PactDslJsonBody
import au.com.dius.pact.consumer.dsl.PactDslWithProvider
import au.com.dius.pact.model.RequestResponsePact
import com.google.gson.Gson
import okhttp3.OkHttpClient
import okhttp3.Request