Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit d0128dc

Browse files
committed
refactor readability
1 parent 2e74464 commit d0128dc

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

file/src/main/java/com/crazylegend/file/FileExtensions.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fun deleteDir(@Nullable dir: File?): Boolean {
153153
}
154154
}
155155
}
156-
return dir!!.delete()
156+
return dir?.delete() == true
157157
}
158158

159159

@@ -258,10 +258,8 @@ fun Uri.getRealPath(context: Context): String? {
258258
} else if (isMediaDocument()) {
259259
val docId = DocumentsContract.getDocumentId(this)
260260
val split = docId.split(":".toRegex())
261-
val type = split[0]
262261

263-
val contentUri: Uri?
264-
contentUri = when (type) {
262+
val contentUri: Uri? = when (split[0]) {
265263
"image" -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
266264
"video" -> MediaStore.Video.Media.EXTERNAL_CONTENT_URI
267265
"audio" -> MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
@@ -271,7 +269,7 @@ fun Uri.getRealPath(context: Context): String? {
271269
val selection = "_id=?"
272270
val selectionArgs = arrayOf(split[1])
273271

274-
return context.getDataColumn(contentUri, selection, selectionArgs)
272+
return contentUri?.let { context.getDataColumn(it, selection, selectionArgs) }
275273
}// MediaProvider
276274
// DownloadsProvider
277275
} else if ("content".equals(scheme, ignoreCase = true)) {

file/src/main/java/com/crazylegend/file/UriExtensions.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ fun Uri.toByteArray(context: Context): ByteArray? {
4848
}
4949

5050
fun Uri.resolveMimeType(context: Context): String? {
51-
val mimeType: String?
52-
mimeType = if (scheme == ContentResolver.SCHEME_CONTENT) {
51+
val mimeType: String? = if (scheme == ContentResolver.SCHEME_CONTENT) {
5352
val cr = context.contentResolver
5453
cr.getType(this)
5554
} else {
@@ -97,8 +96,8 @@ val Uri.isMailToLink: Boolean
9796

9897
fun Uri?.readBytes(context: Context): ByteArray? {
9998
return this?.let {
100-
return@let context.contentResolver.openInputStream(it)?.use {
101-
return@use it.readBytes()
99+
return@let context.contentResolver.openInputStream(it)?.use { inputStream ->
100+
return@use inputStream.readBytes()
102101
}
103102
}
104103
}

0 commit comments

Comments
 (0)