File tree Expand file tree Collapse file tree 1 file changed +24
-16
lines changed
JetPDFVue/src/main/java/com/pratikk/jetpdfvue/state Expand file tree Collapse file tree 1 file changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import androidx.core.net.toUri
2424import com.pratikk.jetpdfvue.util.getDateddMMyyyyHHmm
2525import com.pratikk.jetpdfvue.util.getFileType
2626import com.pratikk.jetpdfvue.util.toFile
27+ import kotlinx.coroutines.CancellationException
2728import kotlinx.coroutines.CoroutineStart
2829import kotlinx.coroutines.Dispatchers
2930import kotlinx.coroutines.Job
@@ -134,26 +135,33 @@ class VueFilePicker {
134135 importJob = launch(context = coroutineContext + Dispatchers .IO , start = CoroutineStart .LAZY ) {
135136 with ((vueFilePickerState as VueFilePickerState .VueFilePickerImported )) {
136137 // Create a temp file using result uri
137- val file = context.contentResolver.openInputStream(uri)?.use {
138- val ext = when (uri.getFileType(context)) {
139- VueFileType .PDF -> {
140- " pdf"
141- }
138+ val file = try {
139+ context.contentResolver.openInputStream(uri)?.use {
140+ val ext = when (uri.getFileType(context)) {
141+ VueFileType .PDF -> {
142+ " pdf"
143+ }
142144
143- VueFileType .IMAGE -> {
144- " jpg"
145- }
145+ VueFileType .IMAGE -> {
146+ " jpg"
147+ }
146148
147- VueFileType .BASE64 -> {
148- " txt"
149+ VueFileType .BASE64 -> {
150+ " txt"
151+ }
149152 }
153+ it.toFile(ext)
154+ }
155+ } catch (e: CancellationException ) {
156+ throw e
157+ } catch (_: Exception ) {
158+ null
159+ }
160+ file?.let {
161+ interceptResult(it)
162+ if (isActive) {
163+ onResult(file)
150164 }
151- it.toFile(ext)
152- }!!
153- interceptResult(file)
154-
155- if (isActive) {
156- onResult(file)
157165 }
158166 }
159167 }.apply {
You can’t perform that action at this time.
0 commit comments