This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.os.Bundle | |
import android.os.Handler | |
import android.os.HandlerThread | |
import android.os.Message | |
import android.view.WindowManager | |
import android.widget.ImageView | |
import androidx.appcompat.app.AppCompatActivity | |
class MainActivity : AppCompatActivity() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.datastore.core.DataStore | |
import androidx.datastore.preferences.core.Preferences | |
import androidx.datastore.preferences.core.edit | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.DelicateCoroutinesApi | |
import kotlinx.coroutines.GlobalScope | |
import kotlinx.coroutines.flow.first | |
import kotlinx.coroutines.flow.map | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation "com.google.dagger:hilt-android:$hilt-latest-version" | |
kapt "com.google.dagger:hilt-android-compiler:$hilt-latest-version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidApp | |
class MyApplication : Application() { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation "androidx.hilt:hilt-work:$hilt-work-latest-version" | |
kapt "androidx.hilt:hilt-compiler:$hilt-work-latest-version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
// ... | |
id 'dagger.hilt.android.plugin' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidApp | |
class MyApplication : Application(), Configuration.Provider { | |
@Inject | |
lateinit var hiltWorkerFactory: HiltWorkerFactory | |
override fun getWorkManagerConfiguration(): Configuration { | |
return Configuration.Builder() | |
.setWorkerFactory(hiltWorkerFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidApp | |
class MyApplication : Application(), Configuration.Provider { | |
@Inject | |
lateinit var hiltWorkerFactory: HiltWorkerFactory | |
private val workerProviders = | |
HashMap<Class<out ListenableWorker>, Provider<AssistedWorkerFactory>>() |