This file contains hidden or 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 (C) 2011 Micah Hainline | |
* Copyright (C) 2012 Triposo | |
* Copyright (C) 2013 Paul Imhoff | |
* Copyright (C) 2014 Shahin Yousefi | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* |
This file contains hidden or 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
/// Author: Nabraj Khadka | |
/// Created: 28.05.2023 | |
/// Description: Auth Interceptor | |
/// | |
import 'package:project/app/api/interceptors/pretty_dio_logger.dart'; | |
import 'package:project/app/configs/api_endpoints.dart'; | |
import 'package:project/app/storage/storage_const.dart'; | |
import 'package:project/app/view/dialogs/toast.dart'; | |
import 'package:project/features/auth/domain/repositories/token_repository.dart'; |
This file contains hidden or 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
fun <T> debounce( | |
waitMs: Long = 300L, | |
scope: CoroutineScope, | |
destinationFunction: (T) -> Unit | |
): (T) -> Unit { | |
var debounceJob: Job? = null | |
return { param: T -> | |
debounceJob?.cancel() | |
debounceJob = scope.launch { | |
delay(waitMs) |
This file contains hidden or 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
class MenuViewModel { | |
val coffeeList: LiveData<List<Coffee>> = liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) { | |
// if the data needs to be processed before displaying, | |
// this is where I usually do it | |
menuRepo.menu.collect(::emit) | |
} | |
} | |
class MenuRepository { | |
private val menuChannel = BroadcastChannel<List<Coffee>>(CONFLATED) |
This file contains hidden or 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
sealed class Either<out L, out R> { | |
data class Left<out L>(val l: L) : Either<L, Nothing>() | |
data class Right<out R>(val r: R) : Either<Nothing, R>() | |
} | |
fun asdf() { | |
val p = Promise<Int> { resolve, reject -> | |
resolve(Either.Left(4)) | |
} |
This file contains hidden or 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
apply from: rootProject.file('gradle/install-git-hooks.gradle') |
This file contains hidden or 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
suspend fun <T> Task<T>.await(): T { | |
if (isComplete) return if (isSuccessful) result else throw exception!! | |
return suspendCoroutine { c: Continuation<T> -> | |
addOnSuccessListener { c.resume(it) } | |
addOnFailureListener { c.resumeWithException(it) } | |
} | |
} | |
fun <T> Deferred<T>.asTask(): Task<T> { | |
val source = TaskCompletionSource<T>() |
This file contains hidden or 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
public suspend inline fun <T : Closeable?, R> T.useCancellably( | |
crossinline block: (T) -> R | |
): R = suspendCancellableCoroutine { cont -> | |
cont.invokeOnCancellation { this?.close() } | |
cont.resume(use(block)) | |
} |
This file contains hidden or 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
@Keep | |
internal class LoggingHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler), | |
CoroutineExceptionHandler { | |
override fun handleException(context: CoroutineContext, exception: Throwable) { | |
Crashlytics.logException(exception) | |
// Since we don't want to crash and Coroutines will call the current thread's handler, we | |
// install a noop handler and then reinstall the existing one once coroutines calls the new | |
// handler. | |
Thread.currentThread().apply { |
This file contains hidden or 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 your.project.view.helper; | |
import android.databinding.BindingAdapter; | |
import android.graphics.drawable.Drawable; | |
import android.support.annotation.ColorInt; | |
import android.support.annotation.DrawableRes; | |
import android.support.annotation.Nullable; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v4.widget.SwipeRefreshLayout; | |
import android.text.TextUtils; |
NewerOlder