Skip to content

Instantly share code, notes, and snippets.

View lucanicoletti's full-sized avatar
:octocat:

Luca Nicoletti lucanicoletti

:octocat:
View GitHub Profile
sealed class MVIJetpackComposeViewState {
@Composable
abstract fun buildUI()
object Loading : MyViewState() {
@Composable
override fun buildUI() {
// Loading which is not provided yet
}
}
sealed class MyViewState {
class Error(val cause: String): MyViewState()
object Loading: MyViewState()
class DataLoaded(data: Data): MyViewState()
}
[...MyView...]
fun render(viewState: MyViewState) {
when (viewState) {
MyViewState.Error -> { // handle error state
@lucanicoletti
lucanicoletti / EndlessRecyclerViewScrollListener.kt
Created October 17, 2018 10:35
EndlessRecyclerViewScrollListener file for kotlin projects
/**
* Created by Luca Nicoletti
* © 17/10/2018
* Copied from: https://gist.github.com/nesquena/d09dc68ff07e845cc622; added some little edits for Kotlin
*/
abstract class EndlessRecyclerViewScrollListener(private var visibleThreshold: Int = 5): RecyclerView.OnScrollListener() {
private var currentPage = 0
private var previousTotalItemCount = 0
private var loading = true