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> { this@wrap.onConvert(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
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
/** | |
* 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 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
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
/** | |
* ``` | |
* val giphyRepository = Retrofit.Builder() | |
* .baseUrl("https://api.giphy.com/") | |
* .addConverterFactory(Json { | |
* ignoreUnknownKeys = true | |
* }.asConverterFactory(contentType)) | |
* .build() | |
* .create<GiphyRepository>() | |
* |
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
inline fun <reified T : View> ViewGroup.childrenByType(): Sequence<T> = descendantsBreadth.filterIsInstance<T>() | |
val ViewGroup.descendantsBreadth: Sequence<View> | |
get() = sequence { | |
val queue: Queue<View> = LinkedList() | |
this@descendantsBreadth.forEach { child -> queue.offer(child) } | |
var child = queue.poll() | |
while (child != null) { | |
yield(child) |
NewerOlder