Skip to content

Instantly share code, notes, and snippets.

View Aidanvii7's full-sized avatar
👾

Aidan McWilliams Aidanvii7

👾
View GitHub Profile
@Aidanvii7
Aidanvii7 / FirebaseIosPlugin.kt
Last active July 26, 2024 13:24
FirebaseIosPlugin example
package com.yourapp.plugins
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
@Aidanvii7
Aidanvii7 / example.kt
Last active March 30, 2024 11:47
possible solution to syncing the OtrKeyManagerStoreImpl with a Room DB
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
@Aidanvii7
Aidanvii7 / SharedPreferenceDelegates.kt
Last active March 24, 2022 11:39
mutableStateOf for SharedPreferences
import android.content.SharedPreferences
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.core.content.edit
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
fun SharedPreferences.mutableStateOf(
key: String,
@Aidanvii7
Aidanvii7 / FlowUtils.kt
Last active March 10, 2022 17:26
compose utils
package com.example
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle.State.CREATED
@Aidanvii7
Aidanvii7 / RandomNumberServiceExample.kt
Last active February 10, 2022 09:44
Utility for binding a local android service in compose
package com.example.app
import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.IBinder
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import kotlin.random.Random
@Aidanvii7
Aidanvii7 / BindingAdapterUtils.kt
Created December 18, 2021 17:58
Binding adapter for Spinner
import android.view.View
import androidx.annotation.IdRes
import androidx.databinding.BindingAdapter
import androidx.databinding.adapters.ListenerUtil as FrameworkListenerUtil
/**
* Designed to track objects passed as optional parameters via static [BindingAdapter] methods.
*
* Only one instance per instanceResId can be tracked at a time.
*
@Aidanvii7
Aidanvii7 / ShamefulHack.kt
Last active December 8, 2021 09:49
'fix' for correct lifecycle behaviour when using StateFlow in databinding expressions, issue here https://issuetracker.google.com/issues/184935697
import androidx.annotation.MainThread
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
/**
* See the [androidx.databinding.ViewDataBindingKtx] class as to why this works (specifically setLifecycleOwner and startCollection)
* [androidx.databinding.ViewDataBindingKtx] has been copied to the gist from the androidx.databinding:databinding-ktx artifact, do not copy into project!
@Aidanvii7
Aidanvii7 / ResultCallAdapterFactory.kt
Created August 31, 2021 08:22
A CallAdapter for the built in Result type
import okhttp3.ResponseBody
import retrofit2.*
import java.io.IOException
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
internal class ResultCallAdapterFactory(
private val errorResponseConverterFactory: Converter.Factory,
private val errorType: Type,
) : CallAdapter.Factory() {
@Aidanvii7
Aidanvii7 / CollectAsStateWhile.kt
Created August 19, 2021 14:47
Lifecycle bound collectAsState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle.State.CREATED
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.flowWithLifecycle
import kotlinx.coroutines.flow.Flow
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import kotlin.reflect.KClass
sealed class Providable<T : Any>(
val type: KClass<T>
) {
abstract val factory: () -> T