diff --git a/README.md b/README.md index d192e21..74fb6de 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Lassi is simplest way to pick media (either image, video, audio or doc) * Step 1. - To open a app color theme view then add Lassi in to your activity class: + To open an app color theme view then add Lassi in to your activity class: ```kotlin val intent = Lassi(this) @@ -73,7 +73,7 @@ Lassi is simplest way to pick media (either image, video, audio or doc) .setMaxTime(30) // for MediaType.VIDEO only .setSupportedFileTypes("mp4", "mkv", "webm", "avi", "flv", "3gp") // Filter by limited media format (Optional) .setMinFileSize(100) // Restrict by minimum file size - .setMaxFileSize(1024) // Restrict by maximum file size + .setMaxFileSize(1024) // Restrict by maximum file size .disableCrop() // to remove crop from the single image selection (crop is enabled by default for single image) /* * Configuration for UI @@ -81,6 +81,10 @@ Lassi is simplest way to pick media (either image, video, audio or doc) .setStatusBarColor(R.color.colorPrimaryDark) .setToolbarResourceColor(R.color.colorPrimary) .setProgressBarColor(R.color.colorAccent) + .setSortingCheckedRadioButtonColor(R.color.darkBlue) // To set color of the checked state radio button resource within sorting dialog + .setSortingUncheckedRadioButtonColor(R.color.regentStBlue) // To set color of the unchecked state radio button resource within sorting dialog + .setSortingCheckedTextColor(R.color.regentStBlue) // To set color of the checked state radio button resource within sorting dialog + .setSortingUncheckedTextColor(R.color.darkBlue) // To set color of the unchecked state radio button resource within sorting dialog .setPlaceHolder(R.drawable.ic_image_placeholder) .setErrorDrawable(R.drawable.ic_image_placeholder) .setSelectionDrawable(R.drawable.ic_checked_media) @@ -123,6 +127,24 @@ Lassi is simplest way to pick media (either image, video, audio or doc) } } ``` + +* Option - 1. To set language's text programmatically based on the current language set on the device follow below mentioned approach of setting strings in your desired language. +* getMultiLngBuilder() exposes params which you can use to set texts. +* By default english (en) language is set so no need to follow this step. + ```kotlin + val currentLang = Locale.getDefault().language.toString() + if (currentLang == "es") { + lassi.getMultiLngBuilder( + setOkLbl = "d'accord", + setCancelLbl = "Annuler", + setSortAscendingLbl = "Ascendant", + setSortDescendingLbl = "Descendant", + setSortByDateLbl = "Trier par date" + ) + } + ``` +* Option - 2. To localize text content of Lassi picker with multiple language options, define language-specific string resource file in your project and update values of string resource keys mentioned in below link with your desired language. + * [Lassi String Resources](https://github.com/Mindinventory/Lassi-Android/blob/931e147ebe6282bd1629858b5a9f29fe5a0b8b32/lassi/src/main/res/values/strings.xml) ### Document access permission note If Android device SDK is >= 30 and wants to access document (only for choose the non media file) then add ```android.permission.MANAGE_EXTERNAL_STORAGE``` permission in your app otherwise library won't allow to access documents. Kindly check sample app for more detail. diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index bfd3883..4d298cf 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -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 @@ -20,6 +21,7 @@ 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 @@ -30,8 +32,8 @@ import java.util.Locale class MainActivity : AppCompatActivity(), View.OnClickListener { private var _binding: ActivityMainBinding? = null protected val binding get() = _binding!! - private val selectedMediaAdapter by lazy { SelectedMediaAdapter(this::onItemClicked) } + lateinit var lassi: Lassi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,19 +47,40 @@ 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)) } + lassi = Lassi(this) + + // Use getMultiLngBuilder in onCreate to set your desired language + // For the demonstration purpose Spanish(es) is set for localization + val currentLang = Locale.getDefault().language.toString() + if (currentLang == "es") { + lassi.getMultiLngBuilder( + setOkLbl = "d'accord", + setCancelLbl = "Annuler", + setCameraAudioStoragePermissionRationalLbl = "Les autorisations de caméra, de microphone et/ou de stockage ne sont pas accordées. Veuillez les autoriser depuis les paramètres.", + setCameraStoragePermissionRationalLbl = "Les autorisations de caméra et/ou de stockage ne sont pas accordées. Veuillez les autoriser depuis les paramètres.", + setCameraAudioPermissionRationalLbl = "Les autorisations de caméra et/ou de microphone ne sont pas accordées. Veuillez les autoriser depuis les paramètres.", + setCameraPermissionRationalLbl = "L'autorisation de la caméra n'est pas accordée. Veuillez l'autoriser depuis les paramètres.", + setStoragePermissionRationalLbl = "L'autorisation de stockage n'est pas accordée. Veuillez l'autoriser depuis les paramètres.", + setReadMediaImagesVideoPermissionRationalLbl = "Les autorisations relatives aux photos et vidéos ne sont pas accordées. Veuillez les autoriser depuis les paramètres.", + setReadMediaAudioPermissionRationalLbl = "Les autorisations relatives à la musique et à l'audio ne sont pas accordées. Veuillez les autoriser depuis les paramètres.", + setSortAscendingLbl = "Ascendant", + setSortDescendingLbl = "Descendant", + setSortByDateLbl = "Trier par date" + ) + } + binding.btnPhotoPicker.visibility = View.VISIBLE } override fun onClick(v: View?) { when (v?.id) { R.id.btnImagePicker -> { - val intent = Lassi(this) - .with(LassiOption.CAMERA_AND_GALLERY) - .setMaxCount(1) - .setAscSort(SortingOption.ASCENDING) - .setGridSize(2) + 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) @@ -68,50 +91,37 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .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(10000) + .setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1) + .setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong()) .enableActualCircleCrop() - .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif") - .enableFlip() - .enableRotate() - .build() + .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip() + .enableRotate().build() receiveData.launch(intent) - } R.id.btnVideoPicker -> { - val intent = Lassi(this) - .with(LassiOption.CAMERA_AND_GALLERY) - .setMaxCount(4) - .setGridSize(3) - .setMinTime(5) - .setMaxTime(30) - .setMinFileSize(0) - .setMaxFileSize(20000) - .setMediaType(MediaType.VIDEO) - .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) - .setPlaceHolder(R.drawable.ic_video_placeholder) - .setErrorDrawable(R.drawable.ic_video_placeholder) - .setSelectionDrawable(R.drawable.ic_checked_media) - .setSupportedFileTypes("mp4", "mkv", "webm", "avi", "flv", "3gp") - .build() + val intent = + lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4).setGridSize(3) + .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) + .setAlertDialogNegativeButtonColor(R.color.cherry_red) + .setAlertDialogPositiveButtonColor(R.color.emerald_green) + .setProgressBarColor(R.color.colorAccent) + .setGalleryBackgroundColor(R.color.colorGrey) + .setPlaceHolder(R.drawable.ic_video_placeholder) + .setErrorDrawable(R.drawable.ic_video_placeholder) + .setSelectionDrawable(R.drawable.ic_checked_media) + .setSupportedFileTypes("mp4", "mkv", "webm", "avi", "flv", "3gp").build() receiveData.launch(intent) } R.id.btnAudioPicker -> { - val intent = Lassi(this) - .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) @@ -119,8 +129,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .setToolbarColor(R.color.colorPrimary) .setToolbarResourceColor(android.R.color.white) .setProgressBarColor(R.color.colorAccent) - .setGalleryBackgroundColor(R.color.colorGrey) - .build() + .setGalleryBackgroundColor(R.color.colorGrey).build() receiveData.launch(intent) } @@ -129,9 +138,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } R.id.btnDocumentSystemIntent -> { - val intent = Lassi(this) - .setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW) - .setSupportedFileTypes( + val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY) + .setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW).setSupportedFileTypes( "jpg", "jpeg", "png", @@ -154,18 +162,19 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { "rtf", "xlsx", "xls" - ) - .setMaxCount(3) - .setCustomLimitExceedingErrorMessage(R.string.error_exceed_msg) + ).setMaxCount(3) + .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.btnImageCapture -> { - val intent = Lassi(this) - .with(LassiOption.CAMERA) - .setMaxCount(1) - .setGridSize(2) + val intent = lassi.with(LassiOption.CAMERA).setMaxCount(1).setGridSize(2) .setPlaceHolder(R.drawable.ic_image_placeholder) .setErrorDrawable(R.drawable.ic_image_placeholder) .setSelectionDrawable(R.drawable.ic_checked_media) @@ -176,82 +185,84 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .setGalleryBackgroundColor(R.color.colorGrey) .setAlertDialogNegativeButtonColor(R.color.cherry_red) .setAlertDialogPositiveButtonColor(R.color.emerald_green) - .setMediaType(MediaType.IMAGE) - .setCropType(CropImageView.CropShape.OVAL) - .setCropAspectRatio(1, 1) - .setCompressionRatio(0) - .setMinFileSize(0) - .setMaxFileSize(1000000) - .enableActualCircleCrop() - .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif") - .enableFlip() - .enableRotate() - .build() + .setMediaType(MediaType.IMAGE).setCropType(CropImageView.CropShape.OVAL) + .setCropAspectRatio(1, 1).setCompressionRatio(0).setMinFileSize(0) + .setMaxFileSize(Int.MAX_VALUE.toLong()).enableActualCircleCrop() + .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip() + .enableRotate().build() receiveData.launch(intent) } R.id.btnVideoCapture -> { - val intent = Lassi(this) - .with(LassiOption.CAMERA) - .setMaxCount(1) - .setGridSize(3) - .setMinTime(5) - .setMaxTime(30) + val intent = + lassi.with(LassiOption.CAMERA).setMaxCount(1).setGridSize(3).setMinTime(5) + .setMaxTime(30).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).setMediaType(MediaType.VIDEO) + .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(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) - .setMediaType(MediaType.VIDEO) .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(0) - .setMinFileSize(0) - .setMaxFileSize(10000) + .setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1) + .setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(Int.MAX_VALUE.toLong()) .enableActualCircleCrop() - .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif") - .enableFlip() - .enableRotate() - .build() + .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(this) - .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) - .setStatusBarColor(R.color.colorPrimaryDark) - .setToolbarColor(R.color.colorPrimary) + .setStatusBarColor(R.color.colorPrimaryDark).setToolbarColor(R.color.colorPrimary) .setToolbarResourceColor(android.R.color.white) .setAlertDialogNegativeButtonColor(R.color.cherry_red) .setAlertDialogPositiveButtonColor(R.color.emerald_green) - .setGalleryBackgroundColor(R.color.colorGrey) - .setSupportedFileTypes( - "pdf", - "odt", - "doc", - "docs", - "docx", - "txt", - "ppt", - "pptx", - "rtf", - "xlsx", - "xls" - ) - .setProgressBarColor(R.color.colorAccent) - .build() + .setGalleryBackgroundColor(R.color.colorGrey).setSupportedFileTypes( + "pdf", "odt", "doc", "docs", "docx", "txt", "ppt", "pptx", "rtf", "xlsx", "xls" + ).setProgressBarColor(R.color.colorAccent).build() receiveData.launch(intent) } @@ -260,7 +271,6 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { if (it.resultCode == Activity.RESULT_OK) { val selectedMedia = it.data?.getSerializableExtra(KeyUtils.SELECTED_MEDIA) as ArrayList - if (selectedMedia.isNotEmpty()) { binding.ivEmpty.isVisible = selectedMedia.isEmpty() selectedMediaAdapter.setList(selectedMedia) @@ -287,8 +297,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } else { val file = File(it) val fileUri = FileProvider.getUriForFile( - this, - applicationContext.packageName + ".fileprovider", file + this, applicationContext.packageName + ".fileprovider", file ) intent.setDataAndType(fileUri, getMimeType(fileUri)) } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f8f80b1..f620172 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -150,6 +150,25 @@ app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toEndOf="@+id/btnImageCapture" app:layout_constraintTop_toBottomOf="@+id/btnDocumentSystemIntent" /> + +