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
/// For dart 2: | |
/// | |
/// ``` | |
/// import 'package:tuple/tuple.dart'; | |
/// | |
/// Future<Tuple2<T1, T2>> zipAsync<T1, T2>( | |
/// Future<T1> future1, Future<T2> future2) async { | |
/// late T1 result1; | |
/// late T2 result2; | |
/// |
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
class GsonConverterFactory2(private val gson: Gson = Gson()) : Converter.Factory() { | |
override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *> { | |
return GsonResponseBodyConverter2(gson, gson.getAdapter(TypeToken.get(type))) | |
} | |
override fun requestBodyConverter(type: Type, parameterAnnotations: Array<Annotation>, methodAnnotations: Array<Annotation>, retrofit: Retrofit): Converter<*, RequestBody> { | |
return GsonRequestBodyConverter2(gson, gson.getAdapter(TypeToken.get(type))) | |
} | |
} |
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
fun <R> TypeAdapter<R>.convertResponse(onConvert: TypeAdapter<R>.(ResponseBody) -> R): Converter<ResponseBody, R> = | |
Converter<ResponseBody, R> { onConvert(it) } | |
fun <T> TypeAdapter<T>.convertRequest(onConvert: TypeAdapter<T>.(T) -> RequestBody): Converter<T, RequestBody> = | |
Converter<T, RequestBody> { onConvert(it) } | |
fun <T, R, I : Converter<in T, out R>> I.wrap(onConvert: I.(T) -> R): Converter<T, R> = | |
Converter<T, R> { [email protected](it) } |
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
/** | |
* See Also: BackHandler { onBack() } | |
*/ | |
@Composable | |
fun BackCompatHandler( | |
enabled: Boolean = true, | |
onBack: () -> Unit = {} | |
) { | |
val currentOnBack by rememberUpdatedState(onBack) | |
val backCallback = remember { |
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
fun <T> byWeakReference(initialValue: T? = null): MutableProperty<T?> = mutablePropertyOf(WeakReference(initialValue)).map( | |
set = { if (this.field.get() == it) this.field else WeakReference(it) }, | |
get = { it.get() }, | |
) |
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.os.Build | |
import androidx.annotation.RequiresApi | |
import java.text.BreakIterator | |
import java.text.CharacterIterator | |
interface IBreakIterator { | |
fun first(): Int | |
fun last(): Int | |
fun next(): Int | |
fun next(value: Int): Int |
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
fun Modifier.border( | |
top: Dp = 0.dp, | |
bottom: Dp = 0.dp, | |
start: Dp = 0.dp, | |
end: Dp = 0.dp, | |
color: Color, | |
) = border( | |
top = BorderStroke(top, color), | |
bottom = BorderStroke(bottom, color), | |
start = BorderStroke(start, color), |
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
/** | |
* ``` | |
* val giphyRepository = Retrofit.Builder() | |
* .baseUrl("https://api.giphy.com/") | |
* .addConverterFactory(Json { | |
* ignoreUnknownKeys = true | |
* }.asConverterFactory(contentType)) | |
* .build() | |
* .create<GiphyRepository>() | |
* |