Skip to content

Instantly share code, notes, and snippets.

@wellbranding
Last active May 5, 2020 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wellbranding/5557c920e28b11097f6d163272aa7cbe to your computer and use it in GitHub Desktop.
Save wellbranding/5557c920e28b11097f6d163272aa7cbe to your computer and use it in GitHub Desktop.
//Called in VM:
private fun uploadPhoto(bitmap: Bitmap, isImageUploaded: Boolean) {
launch {
prepareDataForUploadingUseCase.execute(viewModelScope,bitmap, isImageUploaded)
}
}
//called in UseCase
suspend fun execute(applicationScope: CoroutineScope, bitmap: Bitmap, isImageUploaded: Boolean) {
val currentStep = "TEST"
val resizedBitmap = withContext(Dispatchers.IO) {
imagesPreparingForUploadUseCase.getResizedBitmap(bitmap, MAX_SIZE)
}
val bitmapCopy = resizedBitmap.copy(bitmap.config, true)
applicationScope.launch {
val deferredBase64 = async(Dispatchers.IO) {
imagesPreparingForUploadUseCase.getBase64ForImageUploading(bitmapCopy)
}
val deferredFile = async(Dispatchers.IO) {
imagesPreparingForUploadUseCase.getFileForImageUploading(bitmap)
}
val result = async(Dispatchers.IO) {
prepareBackgroundZipForUploadingUseCase.execute(currentStep)
}
val file = deferredFile.await()
val base64 = deferredBase64.await()
uploadPhotoUseCase.execute(file, currentStep, base64, isImageUploaded)
}
repository.updateCurrentStepsUploadingData(currentStep)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment