Skip to content

Commit

Permalink
Merge pull request #114 from Mindinventory/faeture/photo_picker_with_…
Browse files Browse the repository at this point in the history
…permission

Feature/photo picker with permission
  • Loading branch information
sanjay-mi authored Mar 26, 2024
2 parents 0c7095f + 30c51f1 commit e1ea9da
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 74 deletions.
62 changes: 54 additions & 8 deletions app/src/main/java/com/lassi/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 Down Expand Up @@ -46,6 +47,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
it.btnImageCapture.setOnClickListener(this)
it.btnVideoCapture.setOnClickListener(this)
it.btnDocumentSystemIntent.setOnClickListener(this)
it.btnPhotoPicker.setOnClickListener(this)
it.rvSelectedMedia.adapter = selectedMediaAdapter
it.rvSelectedMedia.addItemDecoration(GridSpacingItemDecoration(2, 10))
}
Expand All @@ -70,13 +72,15 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
setSortByDateLbl = "Trier par date"
)
}
binding.btnPhotoPicker.visibility = View.VISIBLE
}

override fun onClick(v: View?) {
when (v?.id) {
R.id.btnImagePicker -> {
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(1)
.setAscSort(SortingOption.ASCENDING).setGridSize(2)
.setMediaType(MediaType.IMAGE)
.setPlaceHolder(R.drawable.ic_image_placeholder)
.setErrorDrawable(R.drawable.ic_image_placeholder)
.setSelectionDrawable(R.drawable.ic_checked_media)
Expand All @@ -88,7 +92,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setProgressBarColor(R.color.colorAccent)
.setGalleryBackgroundColor(R.color.colorGrey)
.setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1)
.setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(10000)
.setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong())
.enableActualCircleCrop()
.setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip()
.enableRotate().build()
Expand All @@ -98,7 +102,10 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
R.id.btnVideoPicker -> {
val intent =
lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4).setGridSize(3)
.setMinTime(5).setMaxTime(30).setMinFileSize(0).setMaxFileSize(20000)
.setMinTime(5)
.setMaxTime(Int.MAX_VALUE.toLong()) // Set time larger to let file be visible
.setMinFileSize(0)
.setMaxFileSize(Integer.MAX_VALUE.toLong()) // For setting file size
.setMediaType(MediaType.VIDEO).setStatusBarColor(R.color.colorPrimaryDark)
.setToolbarColor(R.color.colorPrimary)
.setToolbarResourceColor(android.R.color.white)
Expand All @@ -114,7 +121,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
}

R.id.btnAudioPicker -> {
val intent = lassi.setMediaType(MediaType.AUDIO).setMaxCount(4).setGridSize(2)
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMediaType(MediaType.AUDIO).setMaxCount(4).setGridSize(2)
.setPlaceHolder(R.drawable.ic_audio_placeholder)
.setErrorDrawable(R.drawable.ic_audio_placeholder)
.setSelectionDrawable(R.drawable.ic_checked_media)
Expand Down Expand Up @@ -156,7 +163,12 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
"xlsx",
"xls"
).setMaxCount(3)
.setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg)
.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)
}
Expand All @@ -175,7 +187,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setAlertDialogPositiveButtonColor(R.color.emerald_green)
.setMediaType(MediaType.IMAGE).setCropType(CropImageView.CropShape.OVAL)
.setCropAspectRatio(1, 1).setCompressionRatio(0).setMinFileSize(0)
.setMaxFileSize(1000000).enableActualCircleCrop()
.setMaxFileSize(Int.MAX_VALUE.toLong()).enableActualCircleCrop()
.setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip()
.enableRotate().build()
receiveData.launch(intent)
Expand All @@ -195,17 +207,52 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setProgressBarColor(R.color.colorAccent)
.setGalleryBackgroundColor(R.color.colorGrey)
.setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1)
.setCompressionRatio(0).setMinFileSize(0).setMaxFileSize(10000)
.setCompressionRatio(0).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong())
.enableActualCircleCrop()
.setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip()
.enableRotate().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)
.setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1)
.setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong())
.enableActualCircleCrop()
.setCustomLimitExceedingErrorMessage("Selected item exceeded the limit!")
.setSupportedFileTypes(
"jpg",
"jpeg",
"png",
"webp",
"gif",
"mp4",
"mkv",
"webm",
"avi",
"flv",
"3gp"
).enableFlip()
.enableRotate().build()
receiveData.launch(intent)
}
}
}

private fun launchDocPicker() {
val intent = lassi.setMediaType(MediaType.DOC).setMaxCount(4).setGridSize(2)
val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMediaType(MediaType.DOC).setMaxCount(4).setGridSize(2)
.setPlaceHolder(R.drawable.ic_document_placeholder)
.setErrorDrawable(R.drawable.ic_document_placeholder)
.setSelectionDrawable(R.drawable.ic_checked_media)
Expand All @@ -224,7 +271,6 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
if (it.resultCode == Activity.RESULT_OK) {
val selectedMedia =
it.data?.getSerializableExtra(KeyUtils.SELECTED_MEDIA) as ArrayList<MiMedia>

if (selectedMedia.isNotEmpty()) {
binding.ivEmpty.isVisible = selectedMedia.isEmpty()
selectedMediaAdapter.setList(selectedMedia)
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btnImageCapture"
app:layout_constraintTop_toBottomOf="@+id/btnDocumentSystemIntent" />

<Button
android:id="@+id/btnPhotoPicker"
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:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnVideoCapture" />
</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 @@ -9,6 +9,7 @@
<string name="document">Documento</string>
<string name="audio">Audio</string>
<string name="open_system_view">"Abrir vista del sistema "</string>
<string name="photo_picker">Selector de fotos</string>

<string name="sort_by_date">Ordenar por fecha</string>
<string name="sort_ascending">Ascendente</string>
Expand Down
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 @@ -8,6 +8,7 @@
<string name="document">Document</string>
<string name="audio">Audio</string>
<string name="open_system_view">Open System View</string>
<string name="photo_picker">Photo Picker</string>

<string name="sort_by_date">Sort by Date</string>
<string name="sort_ascending">Ascending</string>
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Aug 31 11:56:21 IST 2023
#Tue Mar 12 19:15:15 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 3 additions & 0 deletions lassi/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<!-- To handle the reselection within the app on Android 14 (API level 34) -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

<!-- Required to maintain app compatibility. -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
Expand Down
1 change: 1 addition & 0 deletions lassi/src/main/java/com/lassi/common/utils/KeyUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ object KeyUtils {
const val DESCENDING_ORDER = 0
const val ASCENDING_ORDER = 1
const val DEFAULT_ORDER = 2
const val ERROR_EXCEEDING_MSG = "You are exceeding the defined Max limit."
}
3 changes: 2 additions & 1 deletion lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import com.lassi.R
import com.lassi.common.utils.KeyUtils
import com.lassi.common.utils.KeyUtils.ERROR_EXCEEDING_MSG
import com.lassi.data.media.MiMedia
import com.lassi.presentation.cameraview.controls.AspectRatio
import com.lassi.presentation.cropper.CropImageView
Expand Down Expand Up @@ -45,7 +46,7 @@ data class LassiConfig(
var isCrop: Boolean = true,
var alertDialogNegativeButtonColor: Int = Color.BLACK,
var alertDialogPositiveButtonColor: Int = Color.BLACK,
var customLimitExceedingErrorMessage: String = MultiLangConfig.getConfig().defaultExceedErrorMsg
var customLimitExceedingErrorMessage: String = ERROR_EXCEEDING_MSG
) : Parcelable {
companion object {

Expand Down
3 changes: 2 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 @@ -5,5 +5,6 @@ enum class MediaType(val value: Int) {
VIDEO(2),
AUDIO(3),
DOC(4),
FILE_TYPE_WITH_SYSTEM_VIEW(5)
FILE_TYPE_WITH_SYSTEM_VIEW(5),
PHOTO_PICKER(6)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import com.lassi.presentation.mediadirectory.LassiMediaPickerActivity

class Lassi(private val context: Context) {

private var lassiConfig = LassiConfig()
private var multiLangConfig = MultiLangConfig()
private var lassiConfig = LassiConfig()

init {
getMultiLngBuilder()
Expand Down
Loading

0 comments on commit e1ea9da

Please sign in to comment.