Skip to content

Commit c74b33a

Browse files
author
tanpengcheng
committed
[fix] Fix code warning.
1 parent 0b31b46 commit c74b33a

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

tuiutils/publish.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GROUP_ID=io.github.tans5
22
ARTIFACT_ID=tuiutils
3-
VERSION_NAME=1.0.4
3+
VERSION_NAME=1.0.5
44

55
RELEASE_REPOSITORY_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2
66
SNAPSHOT_REPOSITORY_URL=https://s01.oss.sonatype.org/content/repositories/snapshots

tuiutils/src/main/java/com/tans/tuiutils/mediastore/MediaFileUtils.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal fun uri2FileReal(context: Context, uri: Uri): File? {
2020
val path = uri.path
2121
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && path != null) {
2222
val externals = arrayOf("/external/", "/external_path/")
23-
var file: File? = null
23+
var file: File?
2424
for (external: String in externals) {
2525
if (path.startsWith(external)) {
2626
file = File(
@@ -126,7 +126,7 @@ internal fun uri2FileReal(context: Context, uri: Uri): File? {
126126
} else if (id.startsWith("msf:")) {
127127
id = id.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
128128
}
129-
var availableId: Long = 0
129+
val availableId: Long
130130
try {
131131
availableId = id.toLong()
132132
} catch (e: Exception) {
@@ -141,7 +141,7 @@ internal fun uri2FileReal(context: Context, uri: Uri): File? {
141141
val contentUri =
142142
ContentUris.withAppendedId(Uri.parse(contentUriPrefix), availableId)
143143
try {
144-
val file: File? = getFileFromUri(context, contentUri, "1_1")
144+
val file: File? = getFileFromUri(context, contentUri)
145145
if (file != null) {
146146
return file
147147
}
@@ -166,33 +166,32 @@ internal fun uri2FileReal(context: Context, uri: Uri): File? {
166166
}
167167
val selection = "_id=?"
168168
val selectionArgs = arrayOf(split[1])
169-
return getFileFromUri(context, contentUri, selection, selectionArgs, "1_2")
169+
return getFileFromUri(context, contentUri, selection, selectionArgs)
170170
} // end 1_2
171171
else if ((ContentResolver.SCHEME_CONTENT == scheme)) {
172-
return getFileFromUri(context, uri, "1_3")
172+
return getFileFromUri(context, uri)
173173
} // end 1_3
174174
else {
175175
return null
176176
} // end 1_4
177177
} // end 1
178178
else if ((ContentResolver.SCHEME_CONTENT == scheme)) {
179-
return getFileFromUri(context, uri, "2")
179+
return getFileFromUri(context, uri)
180180
} // end 2
181181
else {
182182
return null
183183
} // end 3
184184
}
185185

186-
private fun getFileFromUri(context: Context, uri: Uri, code: String): File? {
187-
return getFileFromUri(context, uri, null, null, code)
186+
private fun getFileFromUri(context: Context, uri: Uri): File? {
187+
return getFileFromUri(context, uri, null, null)
188188
}
189189

190190
private fun getFileFromUri(
191191
context: Context,
192192
uri: Uri,
193193
selection: String?,
194-
selectionArgs: Array<String>?,
195-
code: String
194+
selectionArgs: Array<String>?
196195
): File? {
197196
if ("com.google.android.apps.photos.content" == uri.authority) {
198197
if (!TextUtils.isEmpty(uri.lastPathSegment)) {
@@ -211,7 +210,7 @@ private fun getFileFromUri(
211210
}
212211
}
213212
val cursor: Cursor = context.contentResolver?.query(
214-
uri, arrayOf<String>("_data"), selection, selectionArgs, null
213+
uri, arrayOf("_data"), selection, selectionArgs, null
215214
) ?: return null
216215
return try {
217216
if (cursor.moveToFirst()) {

0 commit comments

Comments
 (0)