Skip to content

Instantly share code, notes, and snippets.

View gumil's full-sized avatar
🌚
No Activity

Miguel Panelo gumil

🌚
No Activity
View GitHub Profile
@gumil
gumil / RecyclerLoadingView.java
Created May 25, 2016 07:17
RecyclerView with SwipeRefreshLayout, Loading, and Error Message
import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Element is unknownThe root cause java.util.NoSuchElementException was thrown at: androidx.compose.plugins.kotlin.compiler.lower.ComposableCallTransformer.irComposableExpr(ComposableCallTransformer.kt:1362)
at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:35)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:93)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm$default(JvmBackendFacade.kt:64)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:52)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:36)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles
@gumil
gumil / Component.kt
Last active December 19, 2019 14:52
Simple DI
import kotlin.reflect.KProperty
internal class Component(modules: List<Module>, private val parentComponent: Component? = null) {
private val providers: Map<Class<*>, Provider<*>> = hashMapOf<Class<*>, Provider<*>>().apply {
modules.forEach { putAll(it) }
}
inline fun <reified T> get() = get(T::class.java)
package com.usabilla.coroutines
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
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 February 22, 2019 23:15 — forked from ultraon/build.gradle
Good example of the merged Jacoco code covarage Gradle configuration
apply plugin: 'com.android.application'
apply from: "$rootDir/coverage.gradle"
//...
android {
//...
buildTypes {
//...
debug {
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
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)
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
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 ->