Skip to content

Instantly share code, notes, and snippets.

companion object {
var callbackLoadMore: ((Int) -> Unit)? = null
var callbackLikeClick: ((Promotion) -> Unit)? = null
fun forPage(callbackLoadMore: (Int) -> Unit, callbackLikeClick: (Promotion) -> Unit): ShowcasePageOneFragment {
this.callbackLoadMore = callbackLoadMore
this.callbackLikeClick = callbackLikeClick
return ShowcasePageOneFragment()
}
}
@EmmanuelGuther
EmmanuelGuther / ConstraintLayoutGroupClickListener.kt
Created February 19, 2020 07:50
Add listener to all views in constraintlayout group
fun Group.addOnClickListener(listener: (view: View) -> Unit) {
referencedIds.forEach { id ->
rootView.findViewById<View>(id).setOnClickListener(listener)
}
}
@EmmanuelGuther
EmmanuelGuther / FunctionAsParameterThatInTurnReceivesParameter.kt
Last active February 21, 2020 21:05
Kotlin Higher-Order Function -- pass a function as a parameter that in turn receives a parameter
fun launchEmail(activity: FragmentActivity, subject: String, text: String) {
val i = Intent(Intent.ACTION_SEND)
i.type = "message/rfc822"
i.putExtra(Intent.EXTRA_SUBJECT, subject)
i.putExtra(Intent.EXTRA_TEXT, text)
try {
activity.startActivity(Intent.createChooser(i, "Send mail..."))
} catch (ex: android.content.ActivityNotFoundException) {
Toast.makeText(activity, "There are no email clients installed.", Toast.LENGTH_SHORT).show()
}
@EmmanuelGuther
EmmanuelGuther / RecomendedImageSizesForMobile.md
Last active July 10, 2020 20:10
How should an image url be in the api? Well it should be an object of urls images not just a url recommended image dimensions for mobile app

How should an image url be in the api? Well it should be an object of urls images not just a url, so we can have different sizes.

Recommended image dimensions for mobile app

Thumb (~32x48) /images/xs/1-a-bomb.jpg

Small (~160x240) /images/sm/1-a-bomb.jpg

Medium (~320x480) /images/md/1-a-bomb.jpg

{
"uid": "1309SS",
"userType": "single"
}
{
"uid": "1252MM",
"userType": "married"
}
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()
}
}
})
}
@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
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)