Skip to content

Instantly share code, notes, and snippets.

View Zhuinden's full-sized avatar
🤔
Fighting Proguard

Gabor Varadi Zhuinden

🤔
Fighting Proguard
View GitHub Profile
@Zhuinden
Zhuinden / build.gradle
Created May 23, 2020 06:19
AssistedInjection sample: build.gradle
//...
apply plugin: 'kotlin-kapt'
android {
//...
kotlinOptions {
jvmTarget = "1.8"
}
kapt {
correctErrorTypes true
@Zhuinden
Zhuinden / with_assisted_injection.kt
Created May 23, 2020 06:17
AssistedInjection sample #2 - with assisted injection
class RuntimeArg {}
@Singleton class A @Inject constructor()
@Singleton class B @Inject constructor(private val a: A)
@Singleton class C @Inject constructor(private val b: B)
class D @AssistedInject constructor(
private val a: A,
private val b: B,
private val c: C,
@Zhuinden
Zhuinden / without_assisted_injection.kt
Created May 23, 2020 06:16
AssistedInjection sample #1 - without assisted injection
class RuntimeArg {}
@Singleton class A @Inject constructor()
@Singleton class B @Inject constructor(private val a: A)
@Singleton class C @Inject constructor(private val b: B)
class D(
private val a: A,
private val b: B,
private val c: C,
@Zhuinden
Zhuinden / worker_sample.kt
Last active May 26, 2021 07:15
WorkManager Worker Assisted Injection for Constructor Injection
// assisted injected worker
class ActualWorker @AssistedInject constructor(
private val someDependency: SomeDependency,
@Assisted appContext: Context,
@Assisted workerParams: WorkerParameters
) : ListenableWorker(appContext, workerParams) {
@AssistedInject.Factory
interface Factory : AssistedWorkerFactory<ActualWorker>
override fun startWork(): ListenableFuture<Result> {
@Zhuinden
Zhuinden / NavigationCommand.kt
Last active May 21, 2020 04:02
Using EventEmitter to move Navigation commands into ViewModels
typealias NavigationCommand = (NavController, Context) -> Unit
@Zhuinden
Zhuinden / LiveEvent.kt
Created May 21, 2020 03:34
EventEmitter + LiveEvent to replace LiveData<Event<T>>
private class LiveEvent<T> constructor(
private val eventSource: EventSource<T>,
private val lifecycleOwner: LifecycleOwner,
private val observer: EventSource.EventObserver<T>
) : LifecycleObserver {
init {
if (lifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
lifecycleOwner.lifecycle.addObserver(this)
}
}
@Zhuinden
Zhuinden / ApplicationComponent.kt
Last active September 11, 2021 06:25
Dagger + ViewModel + SavedStateHandle
@Singleton
@Component(modules = [AssistedInjectionModule::class])
interface ApplicationComponent {
fun mySavedStateViewModelFactory(): MySavedStateViewModel.Factory
}
@Zhuinden
Zhuinden / ApplicationComponent.kt
Last active June 1, 2020 07:46
Dagger + ViewModel, first iteration
@Singleton
@Component
class ApplicationComponent {
fun myViewModelProvider(): Provider<MyViewModel>
}
@Zhuinden
Zhuinden / appkill.sh
Created April 24, 2020 22:14 — forked from mlykotom/appkill.sh
Script for killing Android app (as system would)
#!/bin/bash
# Provide package of your application (com.example.myapp)
PACKAGE=$1
# First, put your app to background and then run this script
echo "Killing $PACKAGE"
adb shell ps | grep $PACKAGE | awk '{print $2}' | xargs adb shell run-as $PACKAGE kill
@Zhuinden
Zhuinden / appkill.sh
Created April 24, 2020 22:14 — forked from mlykotom/appkill.sh
Script for killing Android app (as system would)
#!/bin/bash
# Provide package of your application (com.example.myapp)
PACKAGE=$1
# First, put your app to background and then run this script
echo "Killing $PACKAGE"
adb shell ps | grep $PACKAGE | awk '{print $2}' | xargs adb shell run-as $PACKAGE kill