Skip to content

Instantly share code, notes, and snippets.

View Tagakov's full-sized avatar
🦊

Vladimir Tagakov Tagakov

🦊
View GitHub Profile
@Tagakov
Tagakov / Di.kt
Last active January 16, 2020 15:15
template for adding new controller to DI graph
typealias YourController = ListEditorController
//do not forget to rename component and module
//do not forget to add module to parent component
//do not forget to add HasControllerInjector to parent entity [Application, Activity, Controller] if not present
@Subcomponent(modules = [ComponentModule::class])
interface RenameMeComponent : AndroidInjector<YourController> {
@Subcomponent.Builder
abstract class Builder : AndroidInjector.Builder<YourController>()
package com.tagakov.avdplayground
import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.os.Bundle
import android.os.Handler
import android.support.graphics.drawable.AnimatedVectorDrawableCompat
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView
class StupidIterator(val source: Iterator<*>): Iterator<String> {
private var nextElement: Any? = null
init {
acquireNextElement()
}
private fun acquireNextElement() {
nextElement = if (source.hasNext()) source.next().let { if (it is Iterator<*>) StupidIterator(it) else it } else null
}
interface ComponentDependencies
inline fun <reified T : ComponentDependencies> Controller.findComponentDependencies(): T {
var currentController: Controller? = parentController
while (currentController !is HasComponentDependencies?) {
currentController = currentController?.parentController
}
val hasDaggerProviders = currentController ?: when {
@Tagakov
Tagakov / RxKeyboardManager.kt
Created October 30, 2018 13:37
Allows to hide and show keyboard with notification after successful hiding or showing
@Reusable
class RxKeyboardManager(private val activity: Activity, private val mainThread: Scheduler, private val imm: InputMethodManager) {
val keyboardStates = Observable.create<Boolean>({
val globalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { it.onNext(isKeyboardShown()) }
it.setCancellation { activity.window.decorView.viewTreeObserver.removeOnGlobalLayoutListener(globalLayoutListener) }
activity.window.decorView.viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener)
}, Emitter.BackpressureMode.LATEST)
.distinctUntilChanged()
.subscribeOn(mainThread)
.share()
import android.app.Activity
import androidx.fragment.app.Fragment
import android.app.Application
import android.app.Service
import android.view.View
import android.view.ViewParent
import com.bluelinelabs.conductor.Controller
import dagger.MapKey
import dagger.Module
import dagger.multibindings.Multibinds