This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license. | |
*/ | |
import android.location.Location | |
import com.google.android.gms.location.LocationCallback | |
import com.google.android.gms.location.LocationRequest | |
import com.google.android.gms.location.LocationResult | |
import com.google.android.gms.location.LocationServices | |
import kotlinx.coroutines.CancellationException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package i_love_companion_objects | |
suspend fun main() { | |
// Discoverability is easy with the companion object | |
// (although autocomplete could use some performance improvements...) | |
doStuff(SomeInterface.createWithDefaults()) | |
val someInstance: SomeInterface = SomeInterface.create( | |
parameterOne = 0, | |
parameterTwo = 1 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.louiscad.splitties.eap.bottomsheet | |
import android.app.Activity | |
import android.view.ViewGroup | |
import androidx.activity.compose.BackHandler | |
import androidx.compose.material.ExperimentalMaterialApi | |
import androidx.compose.material.ModalBottomSheetLayout | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.DisposableEffect | |
import androidx.compose.runtime.getValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Observer | |
import androidx.lifecycle.liveData | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.ExperimentalCoroutinesApi | |
import kotlinx.coroutines.channels.awaitClose | |
import kotlinx.coroutines.flow.* | |
import kotlin.time.Duration | |
import kotlin.time.ExperimentalTime | |
import kotlin.time.seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("NOTHING_TO_INLINE") | |
import kotlin.experimental.and // Used for Byte | |
import kotlin.experimental.inv // Used for Byte | |
import kotlin.experimental.or // Used for Byte | |
inline fun Int.hasFlag(flag: Int) = flag and this == flag | |
inline fun Int.withFlag(flag: Int) = this or flag | |
inline fun Int.minusFlag(flag: Int) = this and flag.inv() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.* | |
import kotlinx.coroutines.flow.* | |
suspend fun <T> Flow<T>.collectInParallel( | |
concurrency: Int, | |
collector: suspend (T) -> Unit | |
) = coroutineScope { | |
val channel: Channel<T> = Channel() | |
repeat(concurrency) { launch { for (e in channel) collector(e) } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.* | |
import kotlinx.coroutines.flow.* | |
fun <T> Flow<T>.chunked(size: Int): Flow<List<T>> = flow { | |
val elements = ArrayList<T>(size) | |
collect { | |
elements.add(it) | |
if (elements.size == size) { | |
emit(elements.toList()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.lifecycle.GenericLifecycleObserver | |
import android.arch.lifecycle.Lifecycle | |
import android.arch.lifecycle.Lifecycle.Event.ON_DESTROY | |
import android.arch.lifecycle.LifecycleOwner | |
import kotlinx.coroutines.experimental.CoroutineScope | |
import kotlinx.coroutines.experimental.Dispatchers | |
import kotlinx.coroutines.experimental.Job | |
import kotlinx.coroutines.experimental.android.Main | |
fun Lifecycle.createJob(cancelEvent: Lifecycle.Event = ON_DESTROY): Job { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.AlarmManager | |
import android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP | |
import android.app.PendingIntent | |
import android.content.Context | |
import android.os.SystemClock | |
import android.support.annotation.IntRange | |
import com.google.firebase.provider.FirebaseInitProvider | |
import org.jetbrains.anko.alarmManager | |
import timber.log.Timber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:Suppress("experimental_is_not_enabled") | |
@file:OptIn(ExperimentalTime::class) | |
import kotlin.math.sqrt | |
import kotlin.time.Duration | |
import kotlin.time.DurationUnit | |
import kotlin.time.ExperimentalTime | |
//// Metrics |
NewerOlder