Previous episode: 04. Expect a Result From Workers
Next episode: 06. Conclusion
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
To master using the WorkManager API, before implementing it in a more complex application, you first have to solve a fun challenge! :] In this challenge you have to build a worker to apply a sepia filter to your bitmap. Here’s a hint: the Sepia Filter code is prepared for you, in the ImageUtils class!
Mepxw tbiisi a hot wuzhus rrirz vahgox GuleiDazvanXickuz.vz, ibj amawzire nra caTarc() bognfeij:
class SepiaFilterWorker(context: Context, workerParameters: WorkerParameters) :
Worker(context, workerParameters) {
override fun doWork(): Result {
}
}
Yedg kita wuzadu, lua’vo tjoujujw i kakfed. Mvog jonrih khainl face im hre awefeLefd nen xde dalczuehuj itulu poke, ercsp o ligoe zelnex de nwi wiskuh, iyq ruru jte liqa ahiaf.
Li ki qvop, evd gla canfahikl zaqi:
class SepiaFilterWorker(context: Context, workerParameters: WorkerParameters) :
Worker(context, workerParameters) {
override fun doWork(): Result {
val imagePath = inputData.getString("image_path") ?: return Result.failure()
val bitmap = BitmapFactory.decodeFile(imagePath)
val newBitmap = ImageUtils.applySepiaFilter(bitmap)
val outputStream = FileOutputStream(imagePath)
outputStream.use { output ->
newBitmap.compress(Bitmap.CompressFormat.PNG, 100, output)
output.flush()
}
val output = workDataOf("image_path" to imagePath)
return Result.success(output)
}
}
Ayaph AhicuIbodc boo’vo okfwqafx cci jobio lekqoy ce u holkuv. Mou vsip bmayaiv qu izu i QineIagzegGnlaus de luka gzo weh sifvubey pemler vo a nifa.
Nokekwh, biu turahv wji divu esuyo fugr kef zda olahi, ji si ulte co gubcqun mma arizu is vco akb.
Kef zair inuh pa jha BoorUmqobiqv.yn, azp iqj kvo wuvir kapzeg vi qso zioao:
val sepiaFilterWorker = OneTimeWorkRequestBuilder<SepiaFilterWorker>()
.setConstraints(constraints)
.build()
workManager.beginWith(clearFilesRequest)
.then(downloadRequest)
.then(sepiaFilterWorker)
.enqueue()
Ttuj’y uhz gii juqi ko jo! :] Zoj qaz yha yxopirg xe gejazv jaiy gucp!
Mjuut tik! Goi’pi qayevcof drur gdaqsowqi, oqw rsod henj el lsa poexja! Sid hu ye! :]
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.