Skip to content

Instantly share code, notes, and snippets.

View mbobiosio's full-sized avatar
🎯
Focusing

Mbuodile Obiosio mbobiosio

🎯
Focusing
View GitHub Profile
@ChainsDD
ChainsDD / ApiModels.kt
Created December 12, 2016 01:07
Moshi custom type adapter on Kotlin
class RedditLink(
val author: String,
val likes: RedditLikes,
val title: String,
val score: Int
)
enum class RedditLikes {
UP, DOWN, NONE
}
@wajahatkarim3
wajahatkarim3 / ActivitiesLaunchingWay.kt
Last active April 3, 2023 08:12
Kotlin Extensions for simpler, easier and funw way of launching of Activities
/**
* Kotlin Extensions for simpler, easier and funw way
* of launching of Activities
*/
inline fun <reified T : Any> Activity.launchActivity (
requestCode: Int = -1,
options: Bundle? = null,
noinline init: Intent.() -> Unit = {})
{
@jishindev
jishindev / ArrayListAdapter.kt
Last active September 18, 2021 12:26
Kotlin | Moshi Type converters and adapters for common use cases. Will be updated with new ones.
@Suppress("UNCHECKED_CAST")
class ArrayListAdapter<T>(private val adapter: JsonAdapter<T>) : JsonAdapter<ArrayList<T>>() {
@Throws(IOException::class)
override fun fromJson(reader: JsonReader): ArrayList<T>? {
val arrayList = arrayListOf<T>()
reader.beginArray()
while (reader.hasNext()) {
(adapter.fromJson(reader))?.let { arrayList.add(it) }

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

@nuhkoca
nuhkoca / HiltDataBinding.kt
Last active February 26, 2024 16:33
A demonstration about how to inject BindingAdapters with Dagger Hilt.
BindingScoped.kt
@Scope
@Retention(AnnotationRetention.BINARY)
annotation class BindingScoped
-------------------------------------------------------
CustomBindingComponent.kt
lifecycleScope.launch {
repoAdapter.loadStateFlow.collect { loadState ->
// Show a retry header if there was an error refreshing, and items were previously
// cached OR default to the default prepend state
header.loadState = loadState.mediator
?.refresh
?.takeIf { it is LoadState.Error && repoAdapter.itemCount > 0 }
?: loadState.prepend
val isListEmpty = loadState.refresh is LoadState.NotLoading && repoAdapter.itemCount == 0