Skip to content

Instantly share code, notes, and snippets.

View DHosseiny's full-sized avatar
🏠
Working from home

Seyyed davud hosseiny DHosseiny

🏠
Working from home
View GitHub Profile
@DHosseiny
DHosseiny / migrate-to-version-catalog.kts
Last active March 29, 2024 12:32
Script to migrate gradle dependencies and plugins to version catalog. This script looks for libs.version.toml file and uses existing added libraries and logs not added libraries(just copy from logs and paste in libraries section)
import java.io.File
val path = "path/to/project/directory" // TODO: change here
println("Processing in folder: $path")
println()
fun writeDependenciesFromVersionCatalog(path: String) {
@DHosseiny
DHosseiny / Item.kt
Created October 19, 2023 13:59
visitors
sealed interface Item {
val weight: Int
val stringRepresentation: String
}
class Box(override val weight: Int) : Item {
override val stringRepresentation: String = "Box"
}
@DHosseiny
DHosseiny / build.gradle
Last active May 26, 2023 15:28
build2.gradle
android {
defaultConfig {
// Todo(hilt): Remove this when migrated to hilt completely
javaCompileOptions.annotationProcessorOptions {
arguments['dagger.hilt.disableModulesHaveInstallInCheck'] = 'true'
}
}
}
@DHosseiny
DHosseiny / MyApplication3.kt
Created May 26, 2023 13:35
MyApplication3
@HiltAndroidApp
class MyApplication : Application(), Configuration.Provider {
@Inject
lateinit var hiltWorkerFactory: HiltWorkerFactory
private val workerProviders =
HashMap<Class<out ListenableWorker>, Provider<AssistedWorkerFactory>>()
@DHosseiny
DHosseiny / MyApplication2.kt
Created May 26, 2023 13:29
MyApplication2
@HiltAndroidApp
class MyApplication : Application(), Configuration.Provider {
@Inject
lateinit var hiltWorkerFactory: HiltWorkerFactory
override fun getWorkManagerConfiguration(): Configuration {
return Configuration.Builder()
.setWorkerFactory(hiltWorkerFactory)
@DHosseiny
DHosseiny / AggregatorWorkerFactory.kt
Last active May 26, 2023 13:37
AggregatorWorkerFactory
/**
* This class aggregates hilt and dagger worker providers.
* TODO: This class can get removed when fully migrated to hilt
*/
class AggregatorWorkerFactory(
private val hiltWorkerFactory: HiltWorkerFactory,
private val daggerWorkerFactory: DaggerWorkerFactory
) : WorkerFactory() {
override fun createWorker(
@DHosseiny
DHosseiny / DaggerWorkerFactory.kt
Created May 26, 2023 13:13
DaggerWorkerFactory
class DaggerWorkerFactory(private val workerFactories: WorkerProviders) : WorkerFactory() {
override fun createWorker(
context: Context,
workerClassName: String,
workerParameters: WorkerParameters
): ListenableWorker? {
return try {
val factoryEntry = workerFactories.entries
.find { Class.forName(workerClassName).isAssignableFrom(it.key) }
@DHosseiny
DHosseiny / build.gradle
Last active May 26, 2023 13:52
plugins
plugins {
// ...
id 'dagger.hilt.android.plugin'
}
@DHosseiny
DHosseiny / build.gradle
Created May 26, 2023 11:46
Migrate to hilt
implementation "androidx.hilt:hilt-work:$hilt-work-latest-version"
kapt "androidx.hilt:hilt-compiler:$hilt-work-latest-version"
@DHosseiny
DHosseiny / MyApplication.kt
Last active May 18, 2023 10:59
Periodically migrate multi-module app from dagger to hilt
@HiltAndroidApp
class MyApplication : Application() {
// ...
}