Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
EmmanuelGuther / BackgroundItemsMovementCompose.kt
Created November 7, 2021 17:32
Background with items in movement in jetpack compose example
@Preview
@Composable
fun BackgroundItemsMovement() {
var backgroundItemsMovementState by remember { mutableStateOf(PositionState.Start) }
Box(modifier = Modifier.fillMaxSize()) {
Row(modifier = Modifier.fillMaxSize()) {
repeat(4) {
BuildImg(
multiply = Random.nextInt(500, 4500),
state = backgroundItemsMovementState
@Preview
@Composable
fun BikeScreen() {
var bikeState by remember { mutableStateOf(BikePosition.Start) }
// val offsetAnimation: Dp by animateDpAsState(
// //get display size
// if (bikeState == BikePosition.Start) (800).dp else (-100).dp,
// )
val offsetX by animateDpAsState(targetValue = if (bikeState == BikePosition.Start) 5.dp else 300.dp, animationSpec =
val updateMapMarker: (LatLng) -> Unit = { latLng -> }
@EmmanuelGuther
EmmanuelGuther / registerForActivityResult.kt
Last active October 28, 2021 06:43
Use of registerForActivityResult Android activity
//There are 4 simple steps to follow while replacing the depricated method startActivityForResult(...).
private val activityResult = this.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
when(result.resultCode){
123 ->{}
6353 ->{}
}
}
getStreetAddressByLatLngUseCase.invoke(latLng.latitude, latLng.longitude).fold(
ifLeft = {
}, ifRight = {
searchAddress(it)
})
@EmmanuelGuther
EmmanuelGuther / removeWhitespace.kt
Created April 20, 2021 09:29
How to delete whitespace (newlines, spaces, tabs, etc) without regex?
fun String.removeWhitespace(): String = filterNot { it.isWhitespace() }
private suspend fun getToken(foo: String): String? = suspendCoroutine { continuation ->
val fooToken = tokenApiExample.Token(foo).start
fooToken.onCreateTokenListener { data ->
when {
data.has("id") -> {
val token = data.getString("id")
continuation.resume(token)
}
else -> {
continuation.resume(null)
@EmmanuelGuther
EmmanuelGuther / dataClassCleanWithExtensions.kt
Created February 2, 2021 07:14
Data class more clean with extensions
data class Result(
val requestCode: Int,
val data: Intent?,
)
val Result.isOk: Boolean
get() = resultCode == Activity.RESULT_OK
fun RecyclerView.onEndScrollListener(listener:()->Unit){
this.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!recyclerView.canScrollVertically(1) && newState == RecyclerView.SCROLL_STATE_IDLE) {
listener()
}
}
})
}
{
"uid": "1252MM",
"userType": "married"
}