DownloadWorker: Inject Gson's instance using Hilt
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -44,6 +44,7 @@ import com.aurora.gplayapi.data.models.File as GPlayFile
|
||||
@HiltWorker
|
||||
class DownloadWorker @AssistedInject constructor(
|
||||
private val downloadDao: DownloadDao,
|
||||
private val gson: Gson,
|
||||
@Assisted private val appContext: Context,
|
||||
@Assisted workerParams: WorkerParameters
|
||||
) : CoroutineWorker(appContext, workerParams) {
|
||||
@@ -64,7 +65,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
// Try to parse input data into a valid app
|
||||
try {
|
||||
val downloadData = inputData.getString(DownloadWorkerUtil.DOWNLOAD_DATA)
|
||||
download = Gson().fromJson(downloadData, Download::class.java)
|
||||
download = gson.fromJson(downloadData, Download::class.java)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to parse download data", exception)
|
||||
return Result.failure()
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.aurora.store.module
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import java.lang.reflect.Modifier
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@@ -16,8 +14,6 @@ object CommonModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun providesGsonInstance(): Gson {
|
||||
return GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||
.create()
|
||||
return Gson()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user