Skip to content

Commit

Permalink
Merge pull request #123 from Mindinventory/develop
Browse files Browse the repository at this point in the history
Library version updated from v1.4.1(29) to v1.4.2(30)
  • Loading branch information
sanjay-mi authored Oct 29, 2024
2 parents 98da4ab + 041f332 commit 700cd88
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 155 deletions.
57 changes: 48 additions & 9 deletions app/src/main/java/com/lassi/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.Log
import android.view.View
import android.webkit.MimeTypeMap
import androidx.activity.result.contract.ActivityResultContracts
Expand All @@ -21,7 +20,6 @@ import com.lassi.common.utils.KeyUtils
import com.lassi.data.media.MiMedia
import com.lassi.domain.media.LassiOption
import com.lassi.domain.media.MediaType
import com.lassi.domain.media.MultiLangConfig
import com.lassi.domain.media.SortingOption
import com.lassi.presentation.builder.Lassi
import com.lassi.presentation.common.decoration.GridSpacingItemDecoration
Expand All @@ -31,9 +29,9 @@ import java.util.Locale

class MainActivity : AppCompatActivity(), View.OnClickListener {
private var _binding: ActivityMainBinding? = null
protected val binding get() = _binding!!
private val binding get() = _binding!!
private val selectedMediaAdapter by lazy { SelectedMediaAdapter(this::onItemClicked) }
lateinit var lassi: Lassi
private lateinit var lassi: Lassi

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -47,7 +45,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
it.btnImageCapture.setOnClickListener(this)
it.btnVideoCapture.setOnClickListener(this)
it.btnDocumentSystemIntent.setOnClickListener(this)
it.btnPhotoVideoPicker.setOnClickListener(this)
it.btnPhotoPicker.setOnClickListener(this)
it.btnVideoMediaPicker.setOnClickListener(this)
it.rvSelectedMedia.adapter = selectedMediaAdapter
it.rvSelectedMedia.addItemDecoration(GridSpacingItemDecoration(2, 10))
}
Expand All @@ -72,13 +72,13 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
setSortByDateLbl = "Trier par date"
)
}
binding.btnPhotoPicker.visibility = View.VISIBLE
binding.btnPhotoVideoPicker.visibility = View.VISIBLE
}

override fun onClick(v: View?) {
when (v?.id) {
R.id.btnImagePicker -> {
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(1)
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4)
.setAscSort(SortingOption.ASCENDING).setGridSize(2)
.setMediaType(MediaType.IMAGE)
.setPlaceHolder(R.drawable.ic_image_placeholder)
Expand All @@ -94,6 +94,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1)
.setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong())
.enableActualCircleCrop()
.disableCrop()
.setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip()
.enableRotate().build()
receiveData.launch(intent)
Expand Down Expand Up @@ -214,9 +215,42 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
receiveData.launch(intent)
}

R.id.btnPhotoVideoPicker -> {
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4)
.setMediaType(MediaType.PHOTO_VIDEO_PICKER)
.setStatusBarColor(R.color.colorPrimaryDark)
.setToolbarColor(R.color.colorPrimary)
.setToolbarResourceColor(android.R.color.white)
.setProgressBarColor(R.color.colorAccent)
.setGalleryBackgroundColor(R.color.colorGrey)
.setCustomLimitExceedingErrorMessage("Selected item exceeded the limit!")
.build()
receiveData.launch(intent)
}

R.id.btnPhotoPicker -> {
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4)
.setAscSort(SortingOption.ASCENDING).setGridSize(2)
.setMediaType(MediaType.PHOTO_PICKER)
.setPlaceHolder(R.drawable.ic_image_placeholder)
.setErrorDrawable(R.drawable.ic_image_placeholder)
.setSelectionDrawable(R.drawable.ic_checked_media)
.setStatusBarColor(R.color.colorPrimaryDark)
.setToolbarColor(R.color.colorPrimary)
.setToolbarResourceColor(android.R.color.white)
.setAlertDialogNegativeButtonColor(R.color.cherry_red)
.setAlertDialogPositiveButtonColor(R.color.emerald_green)
.setProgressBarColor(R.color.colorAccent)
.setGalleryBackgroundColor(R.color.colorGrey)
.enableMultiSelection()
.setCustomLimitExceedingErrorMessage("Selected item exceeded the limit!")
.build()
receiveData.launch(intent)
}

R.id.btnVideoMediaPicker -> {
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4)
.setMediaType(MediaType.VIDEO_PICKER)
.setStatusBarColor(R.color.colorPrimaryDark)
.setToolbarColor(R.color.colorPrimary)
.setToolbarResourceColor(android.R.color.white)
Expand Down Expand Up @@ -247,9 +281,14 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
private val receiveData =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val selectedMedia =
it.data?.getSerializableExtra(KeyUtils.SELECTED_MEDIA) as ArrayList<MiMedia>
if (selectedMedia.isNotEmpty()) {
val selectedMedia = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
it.data?.getParcelableArrayListExtra(KeyUtils.SELECTED_MEDIA, MiMedia::class.java)
} else {
@Suppress("DEPRECATION")
it.data?.getParcelableArrayListExtra(KeyUtils.SELECTED_MEDIA)
}

if (!selectedMedia.isNullOrEmpty()) {
binding.ivEmpty.isVisible = selectedMedia.isEmpty()
selectedMediaAdapter.setList(selectedMedia)
}
Expand Down
45 changes: 43 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@
app:layout_constraintTop_toBottomOf="@+id/btnDocumentSystemIntent" />

<Button
android:id="@+id/btnPhotoPicker"
android:id="@+id/btnPhotoVideoPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/bg_rounded_button"
android:drawableStart="@drawable/ic_document"
android:padding="10dp"
android:text="@string/photo_picker"
android:text="@string/photo_video_picker"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="16sp"
Expand All @@ -169,6 +169,47 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnVideoCapture" />

<Button
android:id="@+id/btnPhotoPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/bg_rounded_button"
android:drawableStart="@drawable/ic_camera_white"
android:padding="10dp"
android:text="@string/photo_picker"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/btnVideoMediaPicker"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnPhotoVideoPicker" />

<Button
android:id="@+id/btnVideoMediaPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:background="@drawable/bg_rounded_button"
android:drawableStart="@drawable/ic_video_cam_white"
android:padding="10dp"
android:text="Video Picker"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btnPhotoPicker"
app:layout_constraintTop_toBottomOf="@+id/btnPhotoVideoPicker" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="sort_descending">Descendente</string>
<string name="camera_permission_rational">No se concede el permiso de la cámara. Por favor, permita que se configure.</string>
<string name="crop_image_menu_crop">Cultivo</string>
<string name="photo_video_picker">Fotos y videos</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<string name="sort_descending">Descending</string>
<string name="camera_permission_rational">Camera permission is not granted. Please allow it from setting.</string>
<string name="crop_image_menu_crop">Crop</string>
<string name="photo_video_picker">Photo &amp; Video Picker</string>
</resources>
4 changes: 2 additions & 2 deletions lassi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
defaultConfig {
minSdk 21
targetSdk 34
versionCode 27
versionName "1.4.0"
versionCode 30
versionName "1.4.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
Expand Down
54 changes: 54 additions & 0 deletions lassi/src/main/java/com/lassi/common/utils/UriHelper.kt
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
}
}
}
14 changes: 11 additions & 3 deletions lassi/src/main/java/com/lassi/data/media/entity/MediaFileDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ interface MediaFileDao {
" ON $MEDIA_FILE_ENTITY.$MEDIA_ID = $DURATION_ENTITY.duration_media_id" +
" INNER JOIN $ALBUM_COVER_ENTITY" +
" ON $MEDIA_FILE_ENTITY.$MEDIA_ID = $ALBUM_COVER_ENTITY.$ALBUM_COVER_MEDIA_ID" +
" WHERE $MEDIA_BUCKET = :bucket AND $MEDIA_TYPE = :mediaType ORDER BY CASE WHEN :isAsc = 1 THEN $MEDIA_DATE_ADDED END ASC, CASE WHEN :isAsc = 0 THEN $MEDIA_DATE_ADDED END DESC")
fun getSelectedSortedMediaFile(bucket: String, isAsc: Int, mediaType: Int): List<SelectedMediaModel>
" WHERE $MEDIA_BUCKET = :bucket AND $MEDIA_TYPE = :mediaType ORDER BY CASE WHEN :isAsc = 1 THEN $MEDIA_DATE_ADDED END ASC, CASE WHEN :isAsc = 0 THEN $MEDIA_DATE_ADDED END DESC"
)
fun getSelectedSortedMediaFile(
bucket: String,
isAsc: Int,
mediaType: Int,
): List<SelectedMediaModel>

@Query("SELECT * FROM $MEDIA_FILE_ENTITY WHERE $MEDIA_BUCKET = :bucket AND $MEDIA_TYPE = :mediaType")
fun getSelectedImageMediaFile(bucket: String, mediaType: Int): List<MediaFileEntity>
Expand All @@ -82,12 +87,15 @@ interface MediaFileDao {
fun getSelectedSortedImageMediaFile(
bucket: String,
isAsc: Int,
mediaType: Int
mediaType: Int,
): List<MediaFileEntity>

@Query("SELECT * FROM $MEDIA_FILE_ENTITY WHERE $MEDIA_TYPE = 1 OR $MEDIA_TYPE = 2 OR $MEDIA_TYPE = 3")
fun getAllImgVidMediaFile(): List<MediaFileEntity>

@Query("DELETE FROM $MEDIA_FILE_ENTITY WHERE $MEDIA_PATH = :mediaPath")
fun deleteByMediaPath(mediaPath: String)

@Query("DELETE FROM $MEDIA_FILE_ENTITY")
fun deleteMediaFiles()
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import kotlinx.coroutines.launch
import java.io.File

class MediaRepositoryImpl(private val context: Context) : MediaRepository {
private var mediaPathToRemove: ArrayList<MediaFileEntity>? = null
val TAG = MediaRepositoryImpl::class.java.simpleName
private val minTimeInMillis = LassiConfig.getConfig().minTime * 1000L
private val maxTimeInMillis = LassiConfig.getConfig().maxTime * 1000L
Expand Down Expand Up @@ -84,6 +83,12 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository {
return resultDeferred.await()
}

override suspend fun deleteMediaFiles() {
CoroutineScope(IO).launch {
mediaDatabase.mediaFileDao().deleteMediaFiles()
}
}

override suspend fun removeMediaData(allDataList: List<MediaFileEntity>?) {
CoroutineScope(IO).launch {
if (allDataList != null) {
Expand Down Expand Up @@ -164,7 +169,7 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository {
}.catch().flowOn(IO)
}

private suspend fun checkDurationAndAddFileToDatabase(
private fun checkDurationAndAddFileToDatabase(
bucket: String?,
id: Long,
name: String,
Expand All @@ -173,7 +178,7 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository {
albumCoverPath: String,
size: Long,
dateAdded: Long,
mediaType: MediaType
mediaType: MediaType,
) {
if (isValidDuration(duration) && isValidFileSize(size)) {
addFileToDatabase(
Expand Down Expand Up @@ -218,7 +223,7 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository {
/**
* Add file to database
*/
private suspend fun addFileToDatabase(
private fun addFileToDatabase(
bucket: String?,
miMedia: MiMedia,
dateAdded: Long,
Expand Down
8 changes: 5 additions & 3 deletions lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ data class LassiConfig(
var enableFlipImage: Boolean = false,
var enableRotateImage: Boolean = false,
var enableActualCircleCrop: Boolean = false,
var compressionRation: Int = 0,
var compressionRatio: Int = 0,
var minFileSize: Long = KeyUtils.DEFAULT_FILE_SIZE,
var maxFileSize: Long = KeyUtils.DEFAULT_FILE_SIZE,
var isCrop: Boolean = true,
var alertDialogNegativeButtonColor: Int = Color.BLACK,
var alertDialogPositiveButtonColor: Int = Color.BLACK,
var customLimitExceedingErrorMessage: String = ERROR_EXCEEDING_MSG
var customLimitExceedingErrorMessage: String = ERROR_EXCEEDING_MSG,
var isMultiPicker : Boolean = false
) : Parcelable {
companion object {

Expand Down Expand Up @@ -80,13 +81,14 @@ data class LassiConfig(
enableFlipImage = lassiConfig.enableFlipImage
enableRotateImage = lassiConfig.enableRotateImage
enableActualCircleCrop = lassiConfig.enableActualCircleCrop
compressionRation = lassiConfig.compressionRation
compressionRatio = lassiConfig.compressionRatio
minFileSize = lassiConfig.minFileSize
maxFileSize = lassiConfig.maxFileSize
isCrop = lassiConfig.isCrop
alertDialogNegativeButtonColor = lassiConfig.alertDialogNegativeButtonColor
alertDialogPositiveButtonColor = lassiConfig.alertDialogPositiveButtonColor
customLimitExceedingErrorMessage = lassiConfig.customLimitExceedingErrorMessage
isMultiPicker = lassiConfig.isMultiPicker
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface MediaRepository {
suspend fun insertMediaData(): Result<Boolean>
suspend fun insertAllMediaData(): Result<Boolean>
suspend fun removeMediaData(allDataList: List<MediaFileEntity>?)
suspend fun deleteMediaFiles()
}
4 changes: 3 additions & 1 deletion lassi/src/main/java/com/lassi/domain/media/MediaType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ enum class MediaType(val value: Int) {
AUDIO(3),
DOC(4),
FILE_TYPE_WITH_SYSTEM_VIEW(5),
PHOTO_PICKER(6)
PHOTO_PICKER(6),
VIDEO_PICKER(7),
PHOTO_VIDEO_PICKER(8),
}
Loading

0 comments on commit 700cd88

Please sign in to comment.