-
-
Save DivS-15/3d57892241cef35f298e179a1210dac6 to your computer and use it in GitHub Desktop.
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
@HiltWorker | |
class BlurWorker @AssistedInject constructor( | |
@Assisted ctx: Context, | |
@Assisted params: WorkerParameters | |
) : CoroutineWorker( | |
ctx, | |
params | |
) { | |
override suspend fun doWork(): Result { | |
val applicationContext = applicationContext | |
val resourceUri = inputData.getString(KEY_IMAGE_URI) | |
makeStatusNotification("Sit tight, Image getting blurred", applicationContext) | |
return try { | |
if (TextUtils.isEmpty(resourceUri)) { | |
Log.e("Debug for Uri", "Invalid input uri") | |
throw IllegalArgumentException("Invalid input uri") | |
} | |
val picture = | |
BitmapFactory.decodeStream( | |
applicationContext.contentResolver.openInputStream( | |
Uri.parse( | |
resourceUri | |
) | |
) | |
) | |
val output = blurBitmap(picture, applicationContext) | |
val blurredImageUri = writeBitmapToFile(applicationContext, output) | |
val outputData = workDataOf(KEY_IMAGE_URI to blurredImageUri.toString()) | |
makeStatusNotification("$blurredImageUri", applicationContext) | |
Result.success(outputData) | |
} catch (e: Throwable) { | |
Log.e("BlurWorker", "Error blurring the image") | |
Result.failure() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment