Skip to content

Instantly share code, notes, and snippets.

View Tagakov's full-sized avatar
🦊

Vladimir Tagakov Tagakov

🦊
View GitHub Profile
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
@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()
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 {
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
}
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
@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>()
@Tagakov
Tagakov / EpicMiddleware.kt
Last active December 11, 2017 16:44
redux?
typealias Epic<State> = (actions: Observable<Action>, currentState: CurrentState<State>) -> Observable<Action>
typealias CurrentState<State> = () -> State
class EpicMiddleware<State: Any> constructor(): Middleware<State> {
private val epics = PublishSubject.create<Epic<State>>()
override fun invoke(store: Store<State>, nextDispatcher: Dispatcher) : Dispatcher {
val actions = PublishSubject.create<Action>()
epics
@Tagakov
Tagakov / FragmentsBug.java
Last active May 31, 2017 20:04
To reproduce bug:1. open app, 2. click on fullscreen button3. rotate device twice4. click back twice (exit app)5. look at logcat
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new FrameLayout(this) {{
setId(42);
}});
if (savedInstanceState == null) {
@Tagakov
Tagakov / Magic.kt
Last active May 23, 2017 20:02 — forked from nsk-mironov/Magic.kt
fun <T> magic(jobs: Observable<Completable>, hot: Observable<T>): Observable<T> {
return Observable.switchOnNext(jobs.map { it.andThen(hot) }.startWith(hot))
}
@Tagakov
Tagakov / mainframer-init.sh
Last active January 19, 2017 17:01
Mainframer initialization script
#!/usr/bin/env bash
REMOTE_MACHINE=${1}
APPLICATION_MODULE=${2}
ASSEMBLE_COMMAND=${3}
ASSEMBLE_TESTS_COMMAND=${4}
ANDROID_SDK_VERSION=${5}