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