Skip to content

Instantly share code, notes, and snippets.

🚀
Kaskade Multiplatform

Miguel Panelo gumil

🚀
Kaskade Multiplatform
Block or report user

Report or block gumil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Verifier.kt
import kotlin.test.assertEquals
import kotlin.test.assertTrue
internal class Verifier<T> {
val function: (T) -> Unit = {
invokedValues.add(it)
}
private var invokedValues = mutableListOf<T>()
@gumil
gumil / build.gradle
Created Feb 22, 2019 — forked from ultraon/build.gradle
Good example of the merged Jacoco code covarage Gradle configuration
View build.gradle
apply plugin: 'com.android.application'
apply from: "$rootDir/coverage.gradle"
//...
android {
//...
buildTypes {
//...
debug {
View tests.kt
package com.gumil.giphy.list
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer
import com.gumil.giphy.GiphyItem
import com.gumil.giphy.ImageItem
import com.gumil.giphy.R
import com.gumil.giphy.TestRepository
import com.gumil.giphy.UserItem
import com.gumil.giphy.util.just
View list states.kt
fun ListState.render(): Unit? = when (this) {
is ListState.Screen -> {
when(loadingMode) {
ListState.Mode.REFRESH -> { swipeRefreshLayout.isRefreshing = true }
ListState.Mode.LOAD_MORE -> adapter.showFooter()
ListState.Mode.IDLE_LOAD_MORE -> {
adapter.addItems(giphies)
isLoading = false
restoreRecyclerView(giphies)
View list actions.kt
fun actions() = Observable.merge<ListAction>(
recyclerView.scrollEvents()
// filter when we do a scroll up
.filter { it.dy > 0 }
// filter when recyclerView is currently loading
.filter { !isLoading }
// filter threshold
.filter {
val layoutManager = it.view.layoutManager as StaggeredGridLayoutManager
val visibleItemCount = recyclerView.childCount
View loadTrending.kt
fun <A : ListAction> Observable<ActionState<A, ListState>>.loadTrending(
mode: ListState.Mode,
offset: Int = 0,
limit: Int = 10,
listStateFunction: (ListState.Screen, List<GiphyItem>) -> ListState.Screen
): Observable<ListState> = this
.map { it.state as ListState.Screen }
.flatMap { state ->
repository.getTrending(offset, limit)
.map { giphies ->
View reducers.kt
on<ListAction.Refresh> {
flatMap {
if (it.action.limit > ListAction.DEFAULT_LIMIT) {
cache.get<List<GiphyItem>>(GiphyListViewModel.KEY_GIPHIES)?.let { giphies ->
return@flatMap ListState.Screen(giphies, ListState.Mode.IDLE_REFRESH).just()
}
}
loadTrending(ListState.Mode.REFRESH, limit = it.action.limit) { _, list ->
ListState.Screen(list, ListState.Mode.IDLE_REFRESH)
View kaskade.kt
Kaskade.create<ListAction, ListState>(ListState.Screen()) {
rx({
object : DisposableObserver<ListState>() {
override fun onComplete() {
Timber.d("flow completed")
}
override fun onNext(state: ListState) {
Timber.d("currentState = $state")
}
View states.kt
internal sealed class ListState : State {
data class Screen(
val giphies: List<GiphyItem> = emptyList(),
val loadingMode: Mode = Mode.IDLE_REFRESH
) : ListState()
data class Error(
val errorMessage: Int
) : ListState(), SingleEvent
@gumil
gumil / actions.kt
Last active Feb 17, 2019
Giphy Kaskade Medium Article
View actions.kt
internal sealed class ListAction : Action {
data class Refresh(
val limit: Int = DEFAULT_LIMIT
) : ListAction()
data class LoadMore(
val offset: Int
) : ListAction()
You can’t perform that action at this time.