Skip to content

Commit

Permalink
Adds mimeType field to Image
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannikitin committed Sep 5, 2023
1 parent a5b3da2 commit 65bd118
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.MIME_TYPE,
)

@SuppressLint("InlinedApi")
Expand Down Expand Up @@ -155,9 +156,10 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader {

val id = cursor.getLong(cursor.getColumnIndex(projection[0]))
val name = cursor.getString(cursor.getColumnIndex(projection[1]))
val mimeType = cursor.getString(cursor.getColumnIndex(projection[4]))

if (name != null) {
return Image(id, name, path)
return Image(id, name, path, mimeType)
}
return null
}
Expand Down Expand Up @@ -227,4 +229,4 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ object ImagePickerUtils {
}

fun isVideoFormat(image: Image): Boolean {
val extension = getExtension(image.path)
val mimeType =
if (TextUtils.isEmpty(extension)) URLConnection.guessContentTypeFromName(image.path) else MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension)
val mimeType = getMimeType(image.path)
return mimeType != null && mimeType.startsWith("video")
}

fun getMimeType(path: String): String? {
val extension = getExtension(path)
return if (TextUtils.isEmpty(extension)) URLConnection.guessContentTypeFromName(path) else MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension)
}

fun getVideoDurationLabel(context: Context?, uri: Uri): String {
try {
val retriever = MediaMetadataRetriever()
Expand Down Expand Up @@ -145,4 +148,4 @@ object ImagePickerUtils {
data.putParcelableArrayListExtra(IpCons.EXTRA_SELECTED_IMAGES, imageArrayList)
return data
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Image(
val id: Long,
val name: String,
val path: String,
val mimeType: String?,
) : Parcelable {

@IgnoredOnParcel
Expand Down Expand Up @@ -49,6 +50,7 @@ class Image(
result = 31 * result + name.hashCode()
result = 31 * result + path.hashCode()
result = 31 * result + (uriHolder?.hashCode() ?: 0)
result = 31 * result + (mimeType?.hashCode() ?: 0)
return result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ object ImageFactory {
return listOf(Image(
id = ContentUris.parseId(uri),
name = ImagePickerUtils.getNameFromFilePath(path),
path = path
path = path,
mimeType = ImagePickerUtils.getMimeType(path),
))
}
}
}

0 comments on commit 65bd118

Please sign in to comment.