diff --git a/app/build.gradle b/app/build.gradle index 6e7bb42d0..89062b9f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -131,6 +131,7 @@ play { ext { work_manager = "2.5.0" + work_hilt = "1.0.0-alpha03" room = "2.3.0-alpha04" chucker = "3.4.0" mockk = "1.10.5" @@ -175,8 +176,8 @@ dependencies { implementation "com.google.dagger:hilt-android:$hilt_version" kapt "com.google.dagger:hilt-android-compiler:$hilt_version" - implementation 'androidx.hilt:hilt-work:1.0.0-alpha02' - kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02' + implementation "androidx.hilt:hilt-work:$work_hilt" + kapt "androidx.hilt:hilt-compiler:$work_hilt" implementation "com.aurelhubert:ahbottomnavigation:2.3.4" implementation "com.ncapdevi:frag-nav:3.3.0" diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt b/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt index a428b702b..8b6bc65d1 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/SyncWorker.kt @@ -5,11 +5,12 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat.BigTextStyle import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT import androidx.core.app.NotificationManagerCompat -import androidx.hilt.Assisted -import androidx.hilt.work.WorkerInject +import androidx.hilt.work.HiltWorker import androidx.work.CoroutineWorker import androidx.work.Data import androidx.work.WorkerParameters +import dagger.assisted.Assisted +import dagger.assisted.AssistedInject import io.github.wulkanowy.R import io.github.wulkanowy.data.repositories.PreferencesRepository import io.github.wulkanowy.data.repositories.SemesterRepository @@ -23,7 +24,8 @@ import kotlinx.coroutines.coroutineScope import timber.log.Timber import kotlin.random.Random -class SyncWorker @WorkerInject constructor( +@HiltWorker +class SyncWorker @AssistedInject constructor( @Assisted appContext: Context, @Assisted workerParameters: WorkerParameters, private val studentRepository: StudentRepository, @@ -58,9 +60,10 @@ class SyncWorker @WorkerInject constructor( } val result = when { exceptions.isNotEmpty() && inputData.getBoolean("one_time", false) -> { - Result.failure(Data.Builder() - .putString("error", exceptions.map { it.stackTraceToString() }.toString()) - .build() + Result.failure( + Data.Builder() + .putString("error", exceptions.map { it.stackTraceToString() }.toString()) + .build() ) } exceptions.isNotEmpty() -> Result.retry() @@ -74,13 +77,16 @@ class SyncWorker @WorkerInject constructor( } private fun notify(result: Result) { - notificationManager.notify(Random.nextInt(Int.MAX_VALUE), NotificationCompat.Builder(applicationContext, DebugChannel.CHANNEL_ID) - .setContentTitle("Debug notification") - .setSmallIcon(R.drawable.ic_stat_push) - .setAutoCancel(true) - .setColor(applicationContext.getCompatColor(R.color.colorPrimary)) - .setStyle(BigTextStyle().bigText("${SyncWorker::class.java.simpleName} result: $result")) - .setPriority(PRIORITY_DEFAULT) - .build()) + notificationManager.notify( + Random.nextInt(Int.MAX_VALUE), + NotificationCompat.Builder(applicationContext, DebugChannel.CHANNEL_ID) + .setContentTitle("Debug notification") + .setSmallIcon(R.drawable.ic_stat_push) + .setAutoCancel(true) + .setColor(applicationContext.getCompatColor(R.color.colorPrimary)) + .setStyle(BigTextStyle().bigText("${SyncWorker::class.java.simpleName} result: $result")) + .setPriority(PRIORITY_DEFAULT) + .build() + ) } }