diff --git a/app/src/main/java/re/flande/xshare/Util.kt b/app/src/main/java/re/flande/xshare/Util.kt index daf2e55..445473f 100644 --- a/app/src/main/java/re/flande/xshare/Util.kt +++ b/app/src/main/java/re/flande/xshare/Util.kt @@ -16,15 +16,14 @@ fun getFatalDialogBuilder(context: Activity): AlertDialog.Builder = AlertDialog.Builder(context).setOnDismissListener { context.finishAffinity() } fun Uri.getFilename(context: Context): String { + var name: String? = null context.contentResolver.query(this, null, null, null, null).use { cursor -> - if (cursor?.moveToFirst() ?: return@use) - return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)) + if (cursor?.moveToFirst() ?: return@use) { + name = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)) + } } - if (scheme == "file") - return lastPathSegment - - throw Exception("don't know how to get file name from $this") + return name ?: lastPathSegment ?: throw Exception("don't know how to get file name from $this") } fun View.fade(show: Boolean, duration: Long) {