Using runCatching
This commit is contained in:
parent
d6ce7005f8
commit
2dcbe0801b
1 changed files with 3 additions and 4 deletions
|
@ -61,7 +61,6 @@ import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
class UserInfoFragment : Fragment() {
|
class UserInfoFragment : Fragment() {
|
||||||
|
|
||||||
|
@ -218,13 +217,13 @@ class UserInfoFragment : Fragment() {
|
||||||
val appDir = requireContext().filesDir
|
val appDir = requireContext().filesDir
|
||||||
val file = File(appDir, fileName)
|
val file = File(appDir, fileName)
|
||||||
var successful = false
|
var successful = false
|
||||||
try {
|
kotlin.runCatching {
|
||||||
val os = BufferedOutputStream(FileOutputStream(file))
|
val os = BufferedOutputStream(FileOutputStream(file))
|
||||||
successful = ImageUtil.resizeBitmap(bitmap, 2048)
|
successful = ImageUtil.resizeBitmap(bitmap, 2048)
|
||||||
.compress(Bitmap.CompressFormat.WEBP, 100, os)
|
.compress(Bitmap.CompressFormat.WEBP, 100, os)
|
||||||
withContext(Dispatchers.IO) { os.close() }
|
withContext(Dispatchers.IO) { os.close() }
|
||||||
} catch (e: IOException) {
|
}.onFailure {
|
||||||
e.printStackTrace()
|
it.printStackTrace()
|
||||||
}
|
}
|
||||||
if (successful) {
|
if (successful) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|
Loading…
Reference in a new issue