-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from Mindinventory/develop
Library version updated from v1.4.1(29) to v1.4.2(30)
- Loading branch information
Showing
18 changed files
with
671 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.lassi.common.utils | ||
|
||
import android.content.ContentResolver | ||
import android.content.Context | ||
import android.graphics.Bitmap.CompressFormat | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.provider.MediaStore | ||
import android.webkit.MimeTypeMap | ||
|
||
object UriHelper { | ||
private fun getMediaType(uri: Uri, contentResolver: ContentResolver): String? { | ||
// Columns to retrieve from the media store | ||
val projection = arrayOf(MediaStore.MediaColumns.MIME_TYPE) | ||
|
||
// Query the content resolver for the media information | ||
contentResolver.query(uri, projection, null, null, null)?.use { cursor -> | ||
if (cursor.moveToFirst()) { | ||
val mimeTypeColumnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE) | ||
if (mimeTypeColumnIndex >= 0) { | ||
return cursor.getString(mimeTypeColumnIndex) | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
|
||
fun isVideo(uri: Uri, contentResolver: ContentResolver): Boolean { | ||
val mimeType = getMediaType(uri, contentResolver) | ||
return mimeType?.startsWith("video/") == true | ||
} | ||
|
||
fun isPhoto(uri: Uri, contentResolver: ContentResolver): Boolean { | ||
val mimeType: String? = if (uri.scheme == ContentResolver.SCHEME_CONTENT) { | ||
contentResolver.getType(uri) | ||
} else { | ||
// For file:// URIs, manually get the MIME type based on the file extension | ||
val extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()) | ||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) | ||
} | ||
val t = mimeType?.startsWith("image/") == true | ||
return t | ||
} | ||
|
||
fun getCompressFormatForUri(uri: Uri, context: Context): CompressFormat { | ||
val mimeType = context.contentResolver?.getType(uri) | ||
return when (mimeType) { | ||
"image/png" -> CompressFormat.PNG | ||
"image/jpeg" -> CompressFormat.JPEG | ||
"image/webp" -> if (Build.VERSION.SDK_INT >= 30) CompressFormat.WEBP_LOSSLESS else CompressFormat.WEBP | ||
else -> CompressFormat.JPEG | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.