From 3170c2927af11ee0550dc66816241c56606529c2 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Mon, 5 Feb 2024 13:03:03 +0530 Subject: [PATCH 01/20] - Set a default cropping aspect ratio --- lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt index e79d02a..4f625fd 100644 --- a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt +++ b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt @@ -31,7 +31,7 @@ data class LassiConfig( var maxTime: Long = KeyUtils.DEFAULT_DURATION, var cropType: CropImageView.CropShape = CropImageView.CropShape.RECTANGLE, var supportedFileType: MutableList = mutableListOf(), - var cropAspectRatio: AspectRatio? = null, + var cropAspectRatio: AspectRatio? = AspectRatio.of(1, 1), var enableFlipImage: Boolean = false, var enableRotateImage: Boolean = false, var enableActualCircleCrop: Boolean = false, From 0fe9701b0fbbe9f9e5f7d0356c930ac7e81fa2ac Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Thu, 8 Feb 2024 14:45:49 +0530 Subject: [PATCH 02/20] - Created object and sub-objects to manage lassi multi-language variables - Created setters for each of them - Created a property and setter properties for populating respective variable --- .../main/java/com/lassi/app/MainActivity.kt | 5 + .../com/lassi/domain/media/MultiLangModel.kt | 319 ++++++++++++++++++ .../com/lassi/presentation/builder/Lassi.kt | 90 +++++ 3 files changed, 414 insertions(+) create mode 100644 lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index bfd3883..855de84 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -53,6 +53,11 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { override fun onClick(v: View?) { when (v?.id) { R.id.btnImagePicker -> { + Lassi(this).getMultiLngBuilder( + setOkLbl = "d'accord", + setCancelLbl = "Annuler" + ) + val intent = Lassi(this) .with(LassiOption.CAMERA_AND_GALLERY) .setMaxCount(1) diff --git a/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt new file mode 100644 index 0000000..58eb8d6 --- /dev/null +++ b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt @@ -0,0 +1,319 @@ +package com.lassi.domain.media + +import android.content.Context +import com.lassi.R +import com.lassi.domain.media.MultiLangModel.Common.cancel +import com.lassi.domain.media.MultiLangModel.Common.lassiAll +import com.lassi.domain.media.MultiLangModel.Common.ok +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageActivityNoPermissions +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageActivityTitle +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlip +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlipHorizontally +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlipVertically +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuRotateLeft +import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuRotateRight +import com.lassi.domain.media.MultiLangModel.CropImage.pickImageIntentChooserTitle +import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems +import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg +import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.errorExceedMsg +import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.noDataFound +import com.lassi.domain.media.MultiLangModel.ImageActions.cropImageMenuCrop +import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24 +import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24Horizontally +import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24Vertically +import com.lassi.domain.media.MultiLangModel.ImageActions.icRotateLeft24 +import com.lassi.domain.media.MultiLangModel.ImageActions.icRotateRight24 +import com.lassi.domain.media.MultiLangModel.ImageActions.mainActionCrop +import com.lassi.domain.media.MultiLangModel.ImageActions.mainActionRotate +import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageCamera +import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageChooserTitle +import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageGallery +import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraAudioPermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraAudioStoragePermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraPermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraStoragePermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.readMediaAudioPermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.readMediaImagesVideoPermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPermission.storagePermissionRational +import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.camera +import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.done +import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.sort +import com.lassi.domain.media.MultiLangModel.Sorting.sortAscending +import com.lassi.domain.media.MultiLangModel.Sorting.sortByDate +import com.lassi.domain.media.MultiLangModel.Sorting.sortDescending + +object MultiLangModel { + object Common { + var ok: String = "" + var cancel: String = "" + var lassiAll: String = "" + + fun setOk(value: String) { + ok = value + } + fun setCancel(value: String) { + cancel = value + } + fun setLassiAll(value: String) { + lassiAll = value + } + } + object CropImage { + var cropImageMenuRotateLeft: String = "" + var cropImageMenuRotateRight: String = "" + var cropImageMenuFlip: String = "" + var cropImageMenuFlipHorizontally: String = "" + var cropImageMenuFlipVertically: String = "" + var pickImageIntentChooserTitle: String = "" + var cropImageActivityNoPermissions: String = "" + var cropImageActivityTitle: String = "" + fun setCropImageMenuRotateLeft(value: String) { + cropImageMenuRotateLeft = value + } + fun setCropImageMenuRotateRight(value: String) { + cropImageMenuRotateRight = value + } + fun setCropImageMenuFlip(value: String) { + cropImageMenuFlip = value + } + fun setCropImageMenuFlipHorizontally(value: String) { + cropImageMenuFlipHorizontally = value + } + fun setCropImageMenuFlipVertically(value: String) { + cropImageMenuFlipVertically = value + } + fun setPickImageIntentChooserTitle(value: String) { + pickImageIntentChooserTitle = value + } + fun setCropImageActivityNoPermissions(value: String) { + cropImageActivityNoPermissions = value + } + fun setCropImageActivityTitle(value: String) { + cropImageActivityTitle = value + } + } + object MediaPickerMenu { + var camera: String = "" + var sort: String = "" + var done: String = "" + + fun setCamera(value: String) { + camera = value + } + fun setSort(value: String) { + sort = value + } + fun setDone(value: String) { + done = value + } + } + object MediaPermission { + var cameraAudioStoragePermissionRational: String = "" + var cameraStoragePermissionRational: String = "" + var cameraAudioPermissionRational: String = "" + var cameraPermissionRational: String = "" + var storagePermissionRational: String = "" + var readMediaImagesVideoPermissionRational: String = "" + var readMediaAudioPermissionRational: String = "" + + fun setCameraAudioStoragePermissionRational(value: String) { + cameraAudioStoragePermissionRational = value + } + fun setCameraStoragePermissionRational(value: String) { + cameraStoragePermissionRational = value + } + fun setCameraAudioPermissionRational(value: String) { + cameraAudioPermissionRational = value + } + fun setCameraPermissionRational(value: String) { + cameraPermissionRational = value + } + fun setStoragePermissionRational(value: String) { + storagePermissionRational = value + } + fun setReadMediaImagesVideoPermissionRational(value: String) { + readMediaImagesVideoPermissionRational = value + } + fun setReadMediaAudioPermissionRational(value: String) { + readMediaAudioPermissionRational = value + } + } + object ErrorOrAlertMessage { + var alreadySelectedMaxItems: String = "" + var errorExceedMsg: String = "" + var defaultExceedErrorMsg: String = "" + var noDataFound: String = "" + + fun setAlreadySelectedMaxItems(value: String) { + alreadySelectedMaxItems = value + } + fun setErrorExceedMsg(value: String) { + errorExceedMsg = value + } + fun setDefaultExceedErrorMsg(value: String) { + defaultExceedErrorMsg = value + } + fun setNoDataFound(value: String) { + noDataFound = value + } + } + object Sorting { + var sortByDate: String = "" + var sortAscending: String = "" + var sortDescending: String = "" + + fun setSortByDate(value: String) { + sortByDate = value + } + fun setSortAscending(value: String) { + sortAscending = value + } + fun setSortDescending(value: String) { + sortDescending = value + } + } + object ImageActions { + var icRotateLeft24: String = "" + var icRotateRight24: String = "" + var cropImageMenuCrop: String = "" + var icFlip24: String = "" + var icFlip24Horizontally: String = "" + var icFlip24Vertically: String = "" + var pickImageChooserTitle: String = "" + var pickImageCamera: String = "" + var pickImageGallery: String = "" + var mainActionRotate: String = "" + var mainActionCrop: String = "" + + fun setIcRotateLeft24(value: String) { + icRotateLeft24 = value + } + fun setIcRotateRight24(value: String) { + icRotateRight24 = value + } + fun setCropImageMenuCrop(value: String) { + cropImageMenuCrop = value + } + fun setIcFlip24(value: String) { + icFlip24 = value + } + fun setIcFlip24Horizontally(value: String) { + icFlip24Horizontally = value + } + fun setIcFlip24Vertically(value: String) { + icFlip24Vertically = value + } + fun setPickImageChooserTitle(value: String) { + pickImageChooserTitle = value + } + fun setPickImageCamera(value: String) { + pickImageCamera = value + } + fun setPickImageGallery(value: String) { + pickImageGallery = value + } + fun setMainActionRotate(value: String) { + mainActionRotate = value + } + fun setMainActionCrop(value: String) { + mainActionCrop = value + } + } + + //Setting data initially + fun initializeDefaultValues(context: Context) { + ok = context.getString(R.string.ok) + cancel = context.getString(R.string.cancel) + lassiAll = context.getString(R.string.lassi_all) + + cropImageMenuRotateLeft = context.getString(R.string.crop_image_menu_rotate_left) + cropImageMenuRotateRight = context.getString(R.string.crop_image_menu_rotate_right) + cropImageMenuFlip = context.getString(R.string.crop_image_menu_flip) + cropImageMenuFlipHorizontally = context.getString(R.string.crop_image_menu_flip_horizontally) + cropImageMenuFlipVertically = context.getString(R.string.crop_image_menu_flip_vertically) + pickImageIntentChooserTitle = context.getString(R.string.pick_image_intent_chooser_title) + cropImageActivityNoPermissions = context.getString(R.string.crop_image_activity_no_permissions) + cropImageActivityTitle = context.getString(R.string.crop_image_activity_title) + + camera = context.getString(R.string.camera) + sort = context.getString(R.string.sort) + done = context.getString(R.string.done) + + cameraAudioStoragePermissionRational = context.getString(R.string.camera_audio_storage_permission_rational) + cameraStoragePermissionRational = context.getString(R.string.camera_storage_permission_rational) + cameraAudioPermissionRational = context.getString(R.string.camera_audio_permission_rational) + cameraPermissionRational = context.getString(R.string.camera_permission_rational) + storagePermissionRational = context.getString(R.string.storage_permission_rational) + readMediaImagesVideoPermissionRational = context.getString(R.string.read_media_images_video_permission_rational) + readMediaAudioPermissionRational = context.getString(R.string.read_media_audio_permission_rational) + + alreadySelectedMaxItems = context.getString(R.string.already_selected_max_items) + errorExceedMsg = context.getString(R.string.error_exceed_msg) + defaultExceedErrorMsg = context.getString(R.string.default_exceed_error_msg) + noDataFound = context.getString(R.string.no_data_found) + + sortByDate = context.getString(R.string.sort_by_date) + sortAscending = context.getString(R.string.sort_ascending) + sortDescending = context.getString(R.string.sort_descending) + + icRotateLeft24 = context.getString(R.string.ic_rotate_left_24) + icRotateRight24 = context.getString(R.string.ic_rotate_right_24) + cropImageMenuCrop = context.getString(R.string.crop_image_menu_crop) + icFlip24 = context.getString(R.string.ic_flip_24) + icFlip24Horizontally = context.getString(R.string.ic_flip_24_horizontally) + icFlip24Vertically = context.getString(R.string.ic_flip_24_vertically) + pickImageChooserTitle = context.getString(R.string.pick_image_chooser_title) + pickImageCamera = context.getString(R.string.pick_image_camera) + pickImageGallery = context.getString(R.string.pick_image_gallery) + mainActionRotate = context.getString(R.string.main_action_rotate) + mainActionCrop = context.getString(R.string.main_action_crop) + } +} + + +/* +data class MultiLangModel( + val ok: String, + val cancel: String, + val selectedItems: String, + val directoryWithItemCount: String, + val lassiAll: String, + val cropImageMenuRotateLeft: String, + val cropImageMenuRotateRight: String, + val cropImageMenuFlip: String, + val cropImageMenuFlipHorizontally: String, + val cropImageMenuFlipVertically: String, + val pickImageIntentChooserTitle: String, + val cropImageActivityNoPermissions: String, + val cropImageActivityTitle: String, + val camera: String, + val sort: String, + val done: String, + val alreadySelectedMaxItems: String, + val cameraAudioStoragePermissionRational: String, + val cameraStoragePermissionRational: String, + val cameraAudioPermissionRational: String, + val cameraPermissionRational: String, + val storagePermissionRational: String, + val readMediaImagesVideoPermissionRational: String, + val readMediaAudioPermissionRational: String, +// val minVideoRecordingTimeError: String, + val errorExceedMsg: String, + val defaultExceedErrorMsg: String, + val icRotateLeft24: String, + val icRotateRight24: String, + val cropImageMenuCrop: String, + val icFlip24: String, + val icFlip24Horizontally: String, + val icFlip24Vertically: String, + val pickImageChooserTitle: String, + val pickImageCamera: String, + val pickImageGallery: String, + val mainActionRotate: String, + val mainActionCrop: String, + val noDataFound: String, + val sortByDate: String, + val sortAscending: String, + val sortDescending: String, +// val sortingOptions: Array +)*/ diff --git a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt index c2750c4..d8a2e61 100644 --- a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt +++ b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt @@ -10,6 +10,7 @@ import com.lassi.common.utils.KeyUtils import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import com.lassi.domain.media.SortingOption import com.lassi.presentation.cameraview.controls.AspectRatio import com.lassi.presentation.cropper.CropImageView @@ -19,6 +20,95 @@ class Lassi(private val context: Context) { private var lassiConfig = LassiConfig() + /** + * Multi-language support + */ + fun getMultiLngBuilder( + setOkLbl: String? = "", + setCancelLbl: String? = "", + setLassiAllLbl: String? = "", + setCropImageMenuRotateLeftLbl: String? = "", + setCropImageMenuRotateRightLbl: String? = "", + setCropImageMenuFlipLbl: String? = "", + setCropImageMenuFlipHorizontallyLbl: String? = "", + setCropImageMenuFlipVerticallyLbl: String? = "", + setPickImageIntentChooserTitleLbl: String? = "", + setCropImageActivityNoPermissionsLbl: String? = "", + setCropImageActivityTitleLbl: String? = "", + setCameraLbl: String? = "", + setSortLbl: String? = "", + setDoneLbl: String? = "", + setCameraAudioStoragePermissionRationalLbl: String? = "", + setCameraStoragePermissionRationalLbl: String? = "", + setCameraAudioPermissionRationalLbl: String? = "", + setCameraPermissionRationalLbl: String? = "", + setStoragePermissionRationalLbl: String? = "", + setReadMediaImagesVideoPermissionRationalLbl: String? = "", + setReadMediaAudioPermissionRationalLbl: String? = "", + setAlreadySelectedMaxItemsLbl: String? = "", + setErrorExceedMsgLbl: String? = "", + setDefaultExceedErrorMsgLbl: String? = "", + setNoDataFoundLbl: String? = "", + setSortByDateLbl: String? = "", + setSortAscendingLbl: String? = "", + setSortDescendingLbl: String? = "", + setIcRotateLeft24Lbl: String? = "", + setIcRotateRight24Lbl: String? = "", + setCropImageMenuCropLbl: String? = "", + setIcFlip24Lbl: String? = "", + setIcFlip24HorizontallyLbl: String? = "", + setIcFlip24VerticallyLbl: String? = "", + setPickImageChooserTitleLbl: String? = "", + setPickImageCameraLbl: String? = "", + setPickImageGalleryLbl: String? = "", + setMainActionRotateLbl: String? = "", + setMainActionCropLbl: String? = "", + ): Lassi { + //Initialized default values + + MultiLangModel.initializeDefaultValues(context) + setOkLbl?.let { MultiLangModel.Common.setOk(it) } + setCancelLbl?.let { MultiLangModel.Common.setCancel(it) } + setLassiAllLbl?.let { MultiLangModel.Common.setLassiAll(it) } + setCropImageMenuRotateLeftLbl?.let { MultiLangModel.CropImage.setCropImageMenuRotateLeft(it) } + setCropImageMenuRotateRightLbl?.let { MultiLangModel.CropImage.setCropImageMenuRotateRight(it) } + setCropImageMenuFlipLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlip(it) } + setCropImageMenuFlipHorizontallyLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlipHorizontally(it) } + setCropImageMenuFlipVerticallyLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlipVertically(it) } + setPickImageIntentChooserTitleLbl?.let { MultiLangModel.CropImage.setPickImageIntentChooserTitle(it) } + setCropImageActivityNoPermissionsLbl?.let { MultiLangModel.CropImage.setCropImageActivityNoPermissions(it) } + setCropImageActivityTitleLbl?.let { MultiLangModel.CropImage.setCropImageActivityTitle(it) } + setCameraLbl?.let { MultiLangModel.MediaPickerMenu.setCamera(it) } + setSortLbl?.let { MultiLangModel.MediaPickerMenu.setSort(it) } + setDoneLbl?.let { MultiLangModel.MediaPickerMenu.setDone(it) } + setCameraAudioStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraAudioStoragePermissionRational(it) } + setCameraStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraStoragePermissionRational(it) } + setCameraAudioPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraAudioPermissionRational(it) } + setCameraPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraPermissionRational(it) } + setStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setStoragePermissionRational(it) } + setReadMediaImagesVideoPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setReadMediaImagesVideoPermissionRational(it) } + setReadMediaAudioPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setReadMediaAudioPermissionRational(it) } + setAlreadySelectedMaxItemsLbl?.let { MultiLangModel.ErrorOrAlertMessage.setAlreadySelectedMaxItems(it) } + setErrorExceedMsgLbl?.let { MultiLangModel.ErrorOrAlertMessage.setErrorExceedMsg(it) } + setDefaultExceedErrorMsgLbl?.let { MultiLangModel.ErrorOrAlertMessage.setDefaultExceedErrorMsg(it) } + setNoDataFoundLbl?.let { MultiLangModel.ErrorOrAlertMessage.setNoDataFound(it) } + setSortByDateLbl?.let { MultiLangModel.Sorting.setSortByDate(it) } + setSortAscendingLbl?.let { MultiLangModel.Sorting.setSortAscending(it) } + setSortDescendingLbl?.let { MultiLangModel.Sorting.setSortDescending(it) } + setIcRotateLeft24Lbl?.let { MultiLangModel.ImageActions.setIcRotateLeft24(it) } + setIcRotateRight24Lbl?.let { MultiLangModel.ImageActions.setIcRotateRight24(it) } + setCropImageMenuCropLbl?.let { MultiLangModel.ImageActions.setCropImageMenuCrop(it) } + setIcFlip24Lbl?.let { MultiLangModel.ImageActions.setIcFlip24(it) } + setIcFlip24HorizontallyLbl?.let { MultiLangModel.ImageActions.setIcFlip24Horizontally(it) } + setIcFlip24VerticallyLbl?.let { MultiLangModel.ImageActions.setIcFlip24Vertically(it) } + setPickImageChooserTitleLbl?.let { MultiLangModel.ImageActions.setPickImageChooserTitle(it) } + setPickImageCameraLbl?.let { MultiLangModel.ImageActions.setPickImageCamera(it) } + setPickImageGalleryLbl?.let { MultiLangModel.ImageActions.setPickImageGallery(it) } + setMainActionRotateLbl?.let { MultiLangModel.ImageActions.setMainActionRotate(it) } + setMainActionCropLbl?.let { MultiLangModel.ImageActions.setMainActionCrop(it) } + return this + } + /** * Limit max item selection */ From 618974a08841a629a5f3df1cc627996d18965446 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Fri, 9 Feb 2024 12:21:54 +0530 Subject: [PATCH 03/20] - Set defaults set by the user instead of string resources - Updated MultiLangModel approach and removed setters which were causing signature related error - Changed the approach of setting data in Lassi --- .../main/java/com/lassi/app/MainActivity.kt | 27 ++- .../media/repository/MediaRepositoryImpl.kt | 3 +- .../com/lassi/domain/media/LassiConfig.kt | 2 +- .../com/lassi/domain/media/MultiLangModel.kt | 127 +------------ .../com/lassi/presentation/builder/Lassi.kt | 171 +++++++++--------- .../presentation/camera/CameraFragment.kt | 17 +- .../presentation/cropper/CropImageActivity.kt | 7 +- .../cropper/CropImageIntentChooser.kt | 3 +- .../lassi/presentation/docs/DocsFragment.kt | 7 +- .../lassi/presentation/media/MediaFragment.kt | 38 +++- .../mediadirectory/FolderFragment.kt | 15 +- .../LassiMediaPickerActivity.kt | 5 +- 12 files changed, 182 insertions(+), 240 deletions(-) diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index 855de84..8f41536 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.MultiLangModel import com.lassi.domain.media.SortingOption import com.lassi.presentation.builder.Lassi import com.lassi.presentation.common.decoration.GridSpacingItemDecoration @@ -36,6 +38,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) _binding = ActivityMainBinding.inflate(layoutInflater) +// Lassi(this).getMultiLngBuilder() //Initially set it binding.also { setContentView(it.root) it.btnImagePicker.setOnClickListener(this) @@ -48,15 +51,29 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { it.rvSelectedMedia.adapter = selectedMediaAdapter it.rvSelectedMedia.addItemDecoration(GridSpacingItemDecoration(2, 10)) } + + Log.d("TAG", "!@# OCCURRENCE: MAINACTIVITY") + + //TODO - For now this method calling is must or else string defaults won't set + Lassi(this).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" + ) } override fun onClick(v: View?) { when (v?.id) { R.id.btnImagePicker -> { - Lassi(this).getMultiLngBuilder( - setOkLbl = "d'accord", - setCancelLbl = "Annuler" - ) val intent = Lassi(this) .with(LassiOption.CAMERA_AND_GALLERY) @@ -161,7 +178,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { "xls" ) .setMaxCount(3) - .setCustomLimitExceedingErrorMessage(R.string.error_exceed_msg) + .setCustomLimitExceedingErrorMessage(MultiLangModel.ErrorOrAlertMessage.errorExceedMsg) .build() receiveData.launch(intent) } diff --git a/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt b/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt index 21ed9a7..539bb83 100644 --- a/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt +++ b/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt @@ -21,6 +21,7 @@ import com.lassi.data.media.entity.MediaFileEntity import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.MediaRepository import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers.IO @@ -224,7 +225,7 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository { dateAdded: Long, mediaType: MediaType, ) { - val bucketName = bucket ?: context.getString(R.string.lassi_all) + val bucketName = bucket ?: MultiLangModel.Common.lassiAll if (isFileTypeSupported(miMedia.path)) { CoroutineScope(IO).launch { miMedia.path?.let { path -> diff --git a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt index e79d02a..a387092 100644 --- a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt +++ b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt @@ -41,7 +41,7 @@ data class LassiConfig( var isCrop: Boolean = true, var alertDialogNegativeButtonColor: Int = Color.BLACK, var alertDialogPositiveButtonColor: Int = Color.BLACK, - var customLimitExceedingErrorMessage: Int = R.string.default_exceed_error_msg + var customLimitExceedingErrorMessage: String = MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg ) : Parcelable { companion object { diff --git a/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt index 58eb8d6..d13a336 100644 --- a/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt +++ b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt @@ -47,16 +47,6 @@ object MultiLangModel { var ok: String = "" var cancel: String = "" var lassiAll: String = "" - - fun setOk(value: String) { - ok = value - } - fun setCancel(value: String) { - cancel = value - } - fun setLassiAll(value: String) { - lassiAll = value - } } object CropImage { var cropImageMenuRotateLeft: String = "" @@ -67,45 +57,11 @@ object MultiLangModel { var pickImageIntentChooserTitle: String = "" var cropImageActivityNoPermissions: String = "" var cropImageActivityTitle: String = "" - fun setCropImageMenuRotateLeft(value: String) { - cropImageMenuRotateLeft = value - } - fun setCropImageMenuRotateRight(value: String) { - cropImageMenuRotateRight = value - } - fun setCropImageMenuFlip(value: String) { - cropImageMenuFlip = value - } - fun setCropImageMenuFlipHorizontally(value: String) { - cropImageMenuFlipHorizontally = value - } - fun setCropImageMenuFlipVertically(value: String) { - cropImageMenuFlipVertically = value - } - fun setPickImageIntentChooserTitle(value: String) { - pickImageIntentChooserTitle = value - } - fun setCropImageActivityNoPermissions(value: String) { - cropImageActivityNoPermissions = value - } - fun setCropImageActivityTitle(value: String) { - cropImageActivityTitle = value - } } object MediaPickerMenu { var camera: String = "" var sort: String = "" var done: String = "" - - fun setCamera(value: String) { - camera = value - } - fun setSort(value: String) { - sort = value - } - fun setDone(value: String) { - done = value - } } object MediaPermission { var cameraAudioStoragePermissionRational: String = "" @@ -115,62 +71,17 @@ object MultiLangModel { var storagePermissionRational: String = "" var readMediaImagesVideoPermissionRational: String = "" var readMediaAudioPermissionRational: String = "" - - fun setCameraAudioStoragePermissionRational(value: String) { - cameraAudioStoragePermissionRational = value - } - fun setCameraStoragePermissionRational(value: String) { - cameraStoragePermissionRational = value - } - fun setCameraAudioPermissionRational(value: String) { - cameraAudioPermissionRational = value - } - fun setCameraPermissionRational(value: String) { - cameraPermissionRational = value - } - fun setStoragePermissionRational(value: String) { - storagePermissionRational = value - } - fun setReadMediaImagesVideoPermissionRational(value: String) { - readMediaImagesVideoPermissionRational = value - } - fun setReadMediaAudioPermissionRational(value: String) { - readMediaAudioPermissionRational = value - } } object ErrorOrAlertMessage { var alreadySelectedMaxItems: String = "" var errorExceedMsg: String = "" var defaultExceedErrorMsg: String = "" var noDataFound: String = "" - - fun setAlreadySelectedMaxItems(value: String) { - alreadySelectedMaxItems = value - } - fun setErrorExceedMsg(value: String) { - errorExceedMsg = value - } - fun setDefaultExceedErrorMsg(value: String) { - defaultExceedErrorMsg = value - } - fun setNoDataFound(value: String) { - noDataFound = value - } } object Sorting { var sortByDate: String = "" var sortAscending: String = "" var sortDescending: String = "" - - fun setSortByDate(value: String) { - sortByDate = value - } - fun setSortAscending(value: String) { - sortAscending = value - } - fun setSortDescending(value: String) { - sortDescending = value - } } object ImageActions { var icRotateLeft24: String = "" @@ -184,44 +95,10 @@ object MultiLangModel { var pickImageGallery: String = "" var mainActionRotate: String = "" var mainActionCrop: String = "" - - fun setIcRotateLeft24(value: String) { - icRotateLeft24 = value - } - fun setIcRotateRight24(value: String) { - icRotateRight24 = value - } - fun setCropImageMenuCrop(value: String) { - cropImageMenuCrop = value - } - fun setIcFlip24(value: String) { - icFlip24 = value - } - fun setIcFlip24Horizontally(value: String) { - icFlip24Horizontally = value - } - fun setIcFlip24Vertically(value: String) { - icFlip24Vertically = value - } - fun setPickImageChooserTitle(value: String) { - pickImageChooserTitle = value - } - fun setPickImageCamera(value: String) { - pickImageCamera = value - } - fun setPickImageGallery(value: String) { - pickImageGallery = value - } - fun setMainActionRotate(value: String) { - mainActionRotate = value - } - fun setMainActionCrop(value: String) { - mainActionCrop = value - } } //Setting data initially - fun initializeDefaultValues(context: Context) { + /*fun initializeDefaultValues(context: Context) { ok = context.getString(R.string.ok) cancel = context.getString(R.string.cancel) lassiAll = context.getString(R.string.lassi_all) @@ -267,7 +144,7 @@ object MultiLangModel { pickImageGallery = context.getString(R.string.pick_image_gallery) mainActionRotate = context.getString(R.string.main_action_rotate) mainActionCrop = context.getString(R.string.main_action_crop) - } + }*/ } diff --git a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt index d8a2e61..3bced02 100644 --- a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt +++ b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt @@ -3,9 +3,11 @@ package com.lassi.presentation.builder import android.content.Context import android.content.Intent import android.graphics.Color +import android.util.Log import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat +import com.lassi.R import com.lassi.common.utils.KeyUtils import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption @@ -20,92 +22,97 @@ class Lassi(private val context: Context) { private var lassiConfig = LassiConfig() + init { + //To set default language + Log.d("TAG", "!@# OCCURRENCE: Lassi INIT") + + //TODO - Need to remove this call and call it from UI side +// getMultiLngBuilder() + } + /** * Multi-language support */ fun getMultiLngBuilder( - setOkLbl: String? = "", - setCancelLbl: String? = "", - setLassiAllLbl: String? = "", - setCropImageMenuRotateLeftLbl: String? = "", - setCropImageMenuRotateRightLbl: String? = "", - setCropImageMenuFlipLbl: String? = "", - setCropImageMenuFlipHorizontallyLbl: String? = "", - setCropImageMenuFlipVerticallyLbl: String? = "", - setPickImageIntentChooserTitleLbl: String? = "", - setCropImageActivityNoPermissionsLbl: String? = "", - setCropImageActivityTitleLbl: String? = "", - setCameraLbl: String? = "", - setSortLbl: String? = "", - setDoneLbl: String? = "", - setCameraAudioStoragePermissionRationalLbl: String? = "", - setCameraStoragePermissionRationalLbl: String? = "", - setCameraAudioPermissionRationalLbl: String? = "", - setCameraPermissionRationalLbl: String? = "", - setStoragePermissionRationalLbl: String? = "", - setReadMediaImagesVideoPermissionRationalLbl: String? = "", - setReadMediaAudioPermissionRationalLbl: String? = "", - setAlreadySelectedMaxItemsLbl: String? = "", - setErrorExceedMsgLbl: String? = "", - setDefaultExceedErrorMsgLbl: String? = "", - setNoDataFoundLbl: String? = "", - setSortByDateLbl: String? = "", - setSortAscendingLbl: String? = "", - setSortDescendingLbl: String? = "", - setIcRotateLeft24Lbl: String? = "", - setIcRotateRight24Lbl: String? = "", - setCropImageMenuCropLbl: String? = "", - setIcFlip24Lbl: String? = "", - setIcFlip24HorizontallyLbl: String? = "", - setIcFlip24VerticallyLbl: String? = "", - setPickImageChooserTitleLbl: String? = "", - setPickImageCameraLbl: String? = "", - setPickImageGalleryLbl: String? = "", - setMainActionRotateLbl: String? = "", - setMainActionCropLbl: String? = "", + setOkLbl: String? = null, + setCancelLbl: String? = null, + setLassiAllLbl: String? = null, + setCropImageMenuRotateLeftLbl: String? = null, + setCropImageMenuRotateRightLbl: String? = null, + setCropImageMenuFlipLbl: String? = null, + setCropImageMenuFlipHorizontallyLbl: String? = null, + setCropImageMenuFlipVerticallyLbl: String? = null, + setPickImageIntentChooserTitleLbl: String? = null, + setCropImageActivityNoPermissionsLbl: String? = null, + setCropImageActivityTitleLbl: String? = null, + setCameraLbl: String? = null, + setSortLbl: String? = null, + setDoneLbl: String? = null, + setCameraAudioStoragePermissionRationalLbl: String? = null, + setCameraStoragePermissionRationalLbl: String? = null, + setCameraAudioPermissionRationalLbl: String? = null, + setCameraPermissionRationalLbl: String? = null, + setStoragePermissionRationalLbl: String? = null, + setReadMediaImagesVideoPermissionRationalLbl: String? = null, + setReadMediaAudioPermissionRationalLbl: String? = null, + setAlreadySelectedMaxItemsLbl: String? = null, + setErrorExceedMsgLbl: String? = null, + setDefaultExceedErrorMsgLbl: String? = null, + setNoDataFoundLbl: String? = null, + setSortByDateLbl: String? = null, + setSortAscendingLbl: String? = null, + setSortDescendingLbl: String? = null, + setIcRotateLeft24Lbl: String? = null, + setIcRotateRight24Lbl: String? = null, + setCropImageMenuCropLbl: String? = null, + setIcFlip24Lbl: String? = null, + setIcFlip24HorizontallyLbl: String? = null, + setIcFlip24VerticallyLbl: String? = null, + setPickImageChooserTitleLbl: String? = null, + setPickImageCameraLbl: String? = null, + setPickImageGalleryLbl: String? = null, + setMainActionRotateLbl: String? = null, + setMainActionCropLbl: String? = null, ): Lassi { - //Initialized default values - - MultiLangModel.initializeDefaultValues(context) - setOkLbl?.let { MultiLangModel.Common.setOk(it) } - setCancelLbl?.let { MultiLangModel.Common.setCancel(it) } - setLassiAllLbl?.let { MultiLangModel.Common.setLassiAll(it) } - setCropImageMenuRotateLeftLbl?.let { MultiLangModel.CropImage.setCropImageMenuRotateLeft(it) } - setCropImageMenuRotateRightLbl?.let { MultiLangModel.CropImage.setCropImageMenuRotateRight(it) } - setCropImageMenuFlipLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlip(it) } - setCropImageMenuFlipHorizontallyLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlipHorizontally(it) } - setCropImageMenuFlipVerticallyLbl?.let { MultiLangModel.CropImage.setCropImageMenuFlipVertically(it) } - setPickImageIntentChooserTitleLbl?.let { MultiLangModel.CropImage.setPickImageIntentChooserTitle(it) } - setCropImageActivityNoPermissionsLbl?.let { MultiLangModel.CropImage.setCropImageActivityNoPermissions(it) } - setCropImageActivityTitleLbl?.let { MultiLangModel.CropImage.setCropImageActivityTitle(it) } - setCameraLbl?.let { MultiLangModel.MediaPickerMenu.setCamera(it) } - setSortLbl?.let { MultiLangModel.MediaPickerMenu.setSort(it) } - setDoneLbl?.let { MultiLangModel.MediaPickerMenu.setDone(it) } - setCameraAudioStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraAudioStoragePermissionRational(it) } - setCameraStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraStoragePermissionRational(it) } - setCameraAudioPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraAudioPermissionRational(it) } - setCameraPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setCameraPermissionRational(it) } - setStoragePermissionRationalLbl?.let { MultiLangModel.MediaPermission.setStoragePermissionRational(it) } - setReadMediaImagesVideoPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setReadMediaImagesVideoPermissionRational(it) } - setReadMediaAudioPermissionRationalLbl?.let { MultiLangModel.MediaPermission.setReadMediaAudioPermissionRational(it) } - setAlreadySelectedMaxItemsLbl?.let { MultiLangModel.ErrorOrAlertMessage.setAlreadySelectedMaxItems(it) } - setErrorExceedMsgLbl?.let { MultiLangModel.ErrorOrAlertMessage.setErrorExceedMsg(it) } - setDefaultExceedErrorMsgLbl?.let { MultiLangModel.ErrorOrAlertMessage.setDefaultExceedErrorMsg(it) } - setNoDataFoundLbl?.let { MultiLangModel.ErrorOrAlertMessage.setNoDataFound(it) } - setSortByDateLbl?.let { MultiLangModel.Sorting.setSortByDate(it) } - setSortAscendingLbl?.let { MultiLangModel.Sorting.setSortAscending(it) } - setSortDescendingLbl?.let { MultiLangModel.Sorting.setSortDescending(it) } - setIcRotateLeft24Lbl?.let { MultiLangModel.ImageActions.setIcRotateLeft24(it) } - setIcRotateRight24Lbl?.let { MultiLangModel.ImageActions.setIcRotateRight24(it) } - setCropImageMenuCropLbl?.let { MultiLangModel.ImageActions.setCropImageMenuCrop(it) } - setIcFlip24Lbl?.let { MultiLangModel.ImageActions.setIcFlip24(it) } - setIcFlip24HorizontallyLbl?.let { MultiLangModel.ImageActions.setIcFlip24Horizontally(it) } - setIcFlip24VerticallyLbl?.let { MultiLangModel.ImageActions.setIcFlip24Vertically(it) } - setPickImageChooserTitleLbl?.let { MultiLangModel.ImageActions.setPickImageChooserTitle(it) } - setPickImageCameraLbl?.let { MultiLangModel.ImageActions.setPickImageCamera(it) } - setPickImageGalleryLbl?.let { MultiLangModel.ImageActions.setPickImageGallery(it) } - setMainActionRotateLbl?.let { MultiLangModel.ImageActions.setMainActionRotate(it) } - setMainActionCropLbl?.let { MultiLangModel.ImageActions.setMainActionCrop(it) } + MultiLangModel.Common.ok = setOkLbl ?: context.getString(R.string.ok) + MultiLangModel.Common.cancel = setCancelLbl ?: context.getString(R.string.cancel) + MultiLangModel.Common.lassiAll = setLassiAllLbl ?: context.getString(R.string.lassi_all) + MultiLangModel.CropImage.cropImageMenuRotateLeft = setCropImageMenuRotateLeftLbl ?: context.getString(R.string.crop_image_menu_rotate_left) + MultiLangModel.CropImage.cropImageMenuRotateRight = setCropImageMenuRotateRightLbl ?: context.getString(R.string.crop_image_menu_rotate_right) + MultiLangModel.CropImage.cropImageMenuFlip = setCropImageMenuFlipLbl ?: context.getString(R.string.crop_image_menu_flip) + MultiLangModel.CropImage.cropImageMenuFlipHorizontally = setCropImageMenuFlipHorizontallyLbl ?: context.getString(R.string.crop_image_menu_flip_horizontally) + MultiLangModel.CropImage.cropImageMenuFlipVertically = setCropImageMenuFlipVerticallyLbl ?: context.getString(R.string.crop_image_menu_flip_vertically) + MultiLangModel.CropImage.pickImageIntentChooserTitle = setPickImageIntentChooserTitleLbl ?: context.getString(R.string.pick_image_intent_chooser_title) + MultiLangModel.CropImage.cropImageActivityNoPermissions = setCropImageActivityNoPermissionsLbl ?: context.getString(R.string.crop_image_activity_no_permissions) + MultiLangModel.CropImage.cropImageActivityTitle = setCropImageActivityTitleLbl ?: context.getString(R.string.crop_image_activity_title) + MultiLangModel.MediaPickerMenu.camera = setCameraLbl ?: context.getString(R.string.camera) + MultiLangModel.MediaPickerMenu.sort = setSortLbl ?: context.getString(R.string.sort) + MultiLangModel.MediaPickerMenu.done = setDoneLbl ?: context.getString(R.string.done) + MultiLangModel.MediaPermission.cameraAudioStoragePermissionRational = setCameraAudioStoragePermissionRationalLbl ?: context.getString(R.string.camera_audio_storage_permission_rational) + MultiLangModel.MediaPermission.cameraStoragePermissionRational = setCameraStoragePermissionRationalLbl ?: context.getString(R.string.camera_storage_permission_rational) + MultiLangModel.MediaPermission.cameraAudioPermissionRational = setCameraAudioPermissionRationalLbl ?: context.getString(R.string.camera_audio_permission_rational) + MultiLangModel.MediaPermission.cameraPermissionRational = setCameraPermissionRationalLbl ?: context.getString(R.string.camera_permission_rational) + MultiLangModel.MediaPermission.storagePermissionRational = setStoragePermissionRationalLbl ?: context.getString(R.string.storage_permission_rational) + MultiLangModel.MediaPermission.readMediaImagesVideoPermissionRational = setReadMediaImagesVideoPermissionRationalLbl ?: context.getString(R.string.read_media_images_video_permission_rational) + MultiLangModel.MediaPermission.readMediaAudioPermissionRational = setReadMediaAudioPermissionRationalLbl ?: context.getString(R.string.read_media_audio_permission_rational) + MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems = setAlreadySelectedMaxItemsLbl ?: context.getString(R.string.already_selected_max_items) + MultiLangModel.ErrorOrAlertMessage.errorExceedMsg = setErrorExceedMsgLbl ?: context.getString(R.string.error_exceed_msg) + MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg = setDefaultExceedErrorMsgLbl ?: context.getString(R.string.default_exceed_error_msg) + MultiLangModel.ErrorOrAlertMessage.noDataFound = setNoDataFoundLbl ?: context.getString(R.string.no_data_found) + MultiLangModel.Sorting.sortByDate = setSortByDateLbl ?: context.getString(R.string.sort_by_date) + MultiLangModel.Sorting.sortAscending = setSortAscendingLbl ?: context.getString(R.string.sort_ascending) + MultiLangModel.Sorting.sortDescending = setSortDescendingLbl ?: context.getString(R.string.sort_descending) + MultiLangModel.ImageActions.icRotateLeft24 = setIcRotateLeft24Lbl ?: context.getString(R.string.ic_rotate_left_24) + MultiLangModel.ImageActions.icRotateRight24 = setIcRotateRight24Lbl ?: context.getString(R.string.ic_rotate_right_24) + MultiLangModel.ImageActions.cropImageMenuCrop = setCropImageMenuCropLbl ?: context.getString(R.string.crop_image_menu_crop) + MultiLangModel.ImageActions.icFlip24 = setIcFlip24Lbl ?: context.getString(R.string.ic_flip_24) + MultiLangModel.ImageActions.icFlip24Horizontally = setIcFlip24HorizontallyLbl ?: context.getString(R.string.ic_flip_24_horizontally) + MultiLangModel.ImageActions.icFlip24Vertically = setIcFlip24VerticallyLbl ?: context.getString(R.string.ic_flip_24_vertically) + MultiLangModel.ImageActions.pickImageChooserTitle = setPickImageChooserTitleLbl ?: context.getString(R.string.pick_image_chooser_title) + MultiLangModel.ImageActions.pickImageCamera = setPickImageCameraLbl ?: context.getString(R.string.pick_image_camera) + MultiLangModel.ImageActions.pickImageGallery = setPickImageGalleryLbl ?: context.getString(R.string.pick_image_gallery) + MultiLangModel.ImageActions.mainActionRotate = setMainActionRotateLbl ?: context.getString(R.string.main_action_rotate) + MultiLangModel.ImageActions.mainActionCrop = setMainActionCropLbl ?: context.getString(R.string.main_action_crop) return this } @@ -397,7 +404,7 @@ class Lassi(private val context: Context) { /** * To set custom error message when picked items exceeds the defined maxCount */ - fun setCustomLimitExceedingErrorMessage(errorMessage: Int): Lassi { + fun setCustomLimitExceedingErrorMessage(errorMessage: String): Lassi { lassiConfig.customLimitExceedingErrorMessage = errorMessage return this } diff --git a/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt b/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt index 4c19825..d2c4832 100644 --- a/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt @@ -8,6 +8,7 @@ import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.provider.Settings +import android.util.Log import android.view.LayoutInflater import android.view.View import androidx.activity.result.contract.ActivityResultContracts @@ -30,6 +31,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.cameraview.audio.Audio import com.lassi.presentation.cameraview.audio.Flash import com.lassi.presentation.cameraview.audio.Mode @@ -325,29 +327,32 @@ class CameraFragment : LassiBaseViewModelFragment= Build.VERSION_CODES.TIRAMISU ) { - R.string.camera_audio_permission_rational + MultiLangModel.MediaPermission.cameraAudioPermissionRational } else if (LassiConfig.getConfig().mediaType == MediaType.IMAGE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) { - R.string.camera_permission_rational + MultiLangModel.MediaPermission.cameraPermissionRational } else { - R.string.camera_storage_permission_rational + MultiLangModel.MediaPermission.cameraStoragePermissionRational } + Log.d("TAG", "!@# LASSI:: CAMERA: MultiLangModel.Common.ok: ${MultiLangModel.Common.ok}") + val alertDialog = AlertDialog.Builder(requireContext(), R.style.dialogTheme) .setMessage(alertMessage) .setCancelable(false) - .setPositiveButton(R.string.ok) { _, _ -> + .setPositiveButton(MultiLangModel.Common.ok) { _, _ -> + val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS data = Uri.fromParts("package", activity?.packageName, null) } permissionSettingResult.launch(intent) } - .setNegativeButton(R.string.cancel) { _, _ -> + .setNegativeButton(MultiLangModel.Common.cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt index 296908c..266be34 100644 --- a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt +++ b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt @@ -27,6 +27,7 @@ import com.lassi.common.utils.KeyUtils import com.lassi.common.utils.Logger import com.lassi.data.media.MiMedia import com.lassi.databinding.CropImageActivityBinding +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.cropper.utils.getUriForFile import java.io.File @@ -176,11 +177,11 @@ open class CropImageActivity : AppCompatActivity(), CropImageView.OnSetImageUriC } true } - .setTitle(R.string.pick_image_chooser_title) + .setTitle(MultiLangModel.ImageActions.pickImageChooserTitle) .setItems( arrayOf( - getString(R.string.pick_image_camera), - getString(R.string.pick_image_gallery), + MultiLangModel.ImageActions.pickImageCamera, + MultiLangModel.ImageActions.pickImageGallery ), ) { _, position -> openSource(if (position == 0) Source.CAMERA else Source.GALLERY) } .show() diff --git a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt index 292044b..6d3b6e5 100644 --- a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt +++ b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt @@ -14,6 +14,7 @@ import android.provider.MediaStore import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts import com.lassi.R +import com.lassi.domain.media.MultiLangModel internal class CropImageIntentChooser( private val activity: ComponentActivity, @@ -32,7 +33,7 @@ internal class CropImageIntentChooser( const val MIUI_GALLERY = "com.miui.gallery" } - private var title: String = activity.getString(R.string.pick_image_chooser_title) + private var title: String = MultiLangModel.ImageActions.pickImageChooserTitle private var priorityIntentList = listOf( GOOGLE_PHOTOS, GOOGLE_PHOTOS_GO, diff --git a/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt b/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt index c51f247..f362626 100644 --- a/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt @@ -26,6 +26,7 @@ import com.lassi.data.media.MiMedia import com.lassi.databinding.FragmentMediaPickerBinding import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.media.SelectedMediaViewModel @@ -234,16 +235,16 @@ class DocsFragment : LassiBaseViewModelFragment + alertDialog.setPositiveButton(MultiLangModel.Common.ok) { _, _ -> val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS data = Uri.fromParts("package", activity?.packageName, null) } mPermissionSettingResult.launch(intent) } - alertDialog.setNegativeButton(R.string.cancel) { _, _ -> + alertDialog.setNegativeButton(MultiLangModel.Common.cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt index ec4ca84..be0fd56 100644 --- a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem +import android.widget.RadioButton import android.widget.RadioGroup import android.widget.Toast import androidx.core.graphics.BlendModeColorFilterCompat @@ -29,6 +30,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.cropper.CropImageContract @@ -268,19 +270,45 @@ class MediaFragment : val sortingRadioGroup = customDialogView.findViewById(R.id.sortingRadioGroup) //To set the previously selected option as checked. - sortingRadioGroup.check( + /*sortingRadioGroup.check( when (viewModel.currentSortingOption.value) { ASCENDING_ORDER -> R.id.radioAscending DESCENDING_ORDER -> R.id.radioDescending else -> R.id.radioAscending } - ) + )*/ + + val currentSortingOption = viewModel.currentSortingOption.value + val ascendingLabel = MultiLangModel.Sorting.sortAscending + val descendingLabel = MultiLangModel.Sorting.sortDescending + + val checkedId = when (currentSortingOption) { + ASCENDING_ORDER -> { + sortingRadioGroup.check(R.id.radioAscending) + R.id.radioAscending + } + DESCENDING_ORDER -> { + sortingRadioGroup.check(R.id.radioDescending) + R.id.radioDescending + } + else -> { + sortingRadioGroup.check(R.id.radioAscending) + R.id.radioAscending + } + } + + // Set the labels for the radio buttons + sortingRadioGroup.findViewById(R.id.radioAscending).text = ascendingLabel + sortingRadioGroup.findViewById(R.id.radioDescending).text = descendingLabel + + // Set the checked radio button in the RadioGroup + sortingRadioGroup.check(checkedId) //Set up the alert builder with the custom layout.. AlertDialog.Builder(requireContext()).apply { - setTitle(R.string.sort_by_date) + setTitle(MultiLangModel.Sorting.sortByDate) setView(customDialogView) - setPositiveButton(android.R.string.ok) { _, _ -> + setPositiveButton(MultiLangModel.Common.ok) { _, _ -> val checkedRadioButtonId = sortingRadioGroup.checkedRadioButtonId val selectedOption = if (checkedRadioButtonId == R.id.radioAscending) ASCENDING_ORDER else DESCENDING_ORDER @@ -315,7 +343,7 @@ class MediaFragment : } } } - setNegativeButton(android.R.string.cancel, null) + setNegativeButton(MultiLangModel.Common.cancel, null) create().show() } } diff --git a/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt b/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt index 576db90..0da061a 100644 --- a/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt @@ -29,6 +29,7 @@ import com.lassi.databinding.FragmentMediaPickerBinding import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.media.MediaFragment @@ -126,6 +127,7 @@ class FolderFragment : LassiBaseViewModelFragment @@ -183,15 +185,15 @@ class FolderFragment : LassiBaseViewModelFragment + alertDialog.setPositiveButton(MultiLangModel.Common.ok) { _, _ -> val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS data = Uri.fromParts("package", activity?.packageName, null) } permissionSettingResult.launch(intent) } - alertDialog.setNegativeButton(R.string.cancel) { _, _ -> + + alertDialog.setNegativeButton(MultiLangModel.Common.cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt b/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt index 9401d0d..bbda4b0 100644 --- a/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt +++ b/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt @@ -26,6 +26,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType +import com.lassi.domain.media.MultiLangModel import com.lassi.presentation.camera.CameraFragment import com.lassi.presentation.common.LassiBaseViewModelActivity import com.lassi.presentation.docs.DocsFragment @@ -56,7 +57,7 @@ class LassiMediaPickerActivity : if (list.size > LassiConfig.getConfig().maxCount) { ToastUtils.showToast( this, - this.resources.getString(LassiConfig.getConfig().customLimitExceedingErrorMessage) + LassiConfig.getConfig().customLimitExceedingErrorMessage ) finish() }else{ @@ -241,7 +242,7 @@ class LassiMediaPickerActivity : private fun initCamera() { if (viewModel.selectedMediaLiveData.value?.size == LassiConfig.getConfig().maxCount) { - ToastUtils.showToast(this, R.string.already_selected_max_items) + ToastUtils.showToast(this, MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems) } else { supportFragmentManager.beginTransaction() .add(R.id.ftContainer, CameraFragment()) From 2abc1c30c1968c0d051b5d499e774ed394e02484 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Fri, 9 Feb 2024 17:04:24 +0530 Subject: [PATCH 04/20] - Set defaults set by the user instead of string resources - Updated MultiLangModel approach and removed setters which were causing signature related error - Changed the approach of setting data in Lassi - Changed approach to data class and companion from object singleton --- .../main/java/com/lassi/app/MainActivity.kt | 228 ++++++-------- .../media/repository/MediaRepositoryImpl.kt | 5 +- .../com/lassi/domain/media/LassiConfig.kt | 5 +- .../com/lassi/domain/media/MultiLangModel.kt | 284 ++++++------------ .../com/lassi/presentation/builder/Lassi.kt | 123 +++++--- .../presentation/camera/CameraFragment.kt | 15 +- .../presentation/cropper/CropImageActivity.kt | 8 +- .../cropper/CropImageIntentChooser.kt | 4 +- .../lassi/presentation/docs/DocsFragment.kt | 8 +- .../lassi/presentation/media/MediaFragment.kt | 12 +- .../mediadirectory/FolderFragment.kt | 16 +- .../LassiMediaPickerActivity.kt | 4 +- 12 files changed, 293 insertions(+), 419 deletions(-) diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index 8f41536..f41decd 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -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 @@ -21,7 +20,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.MultiLangModel +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 @@ -35,6 +34,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { private val selectedMediaAdapter by lazy { SelectedMediaAdapter(this::onItemClicked) } + lateinit var lassi: Lassi + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) _binding = ActivityMainBinding.inflate(layoutInflater) @@ -51,11 +52,10 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { it.rvSelectedMedia.adapter = selectedMediaAdapter it.rvSelectedMedia.addItemDecoration(GridSpacingItemDecoration(2, 10)) } + lassi = Lassi(this) - Log.d("TAG", "!@# OCCURRENCE: MAINACTIVITY") - - //TODO - For now this method calling is must or else string defaults won't set - Lassi(this).getMultiLngBuilder( + // Use getMultiLngBuilder in onCreate to set your desired language + 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.", @@ -74,12 +74,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { 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) .setPlaceHolder(R.drawable.ic_image_placeholder) .setErrorDrawable(R.drawable.ic_image_placeholder) .setSelectionDrawable(R.drawable.ic_checked_media) @@ -90,50 +86,34 @@ 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(10000) .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(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() receiveData.launch(intent) } R.id.btnAudioPicker -> { - val intent = Lassi(this) - .setMediaType(MediaType.AUDIO) - .setMaxCount(4) - .setGridSize(2) + val intent = lassi.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) @@ -141,8 +121,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) } @@ -151,43 +130,38 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } R.id.btnDocumentSystemIntent -> { - val intent = Lassi(this) - .setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW) - .setSupportedFileTypes( - "jpg", - "jpeg", - "png", - "webp", - "gif", - "mp4", - "mkv", - "webm", - "avi", - "flv", - "3gp", - "pdf", - "odt", - "doc", - "docs", - "docx", - "txt", - "ppt", - "pptx", - "rtf", - "xlsx", - "xls" - ) - .setMaxCount(3) - .setCustomLimitExceedingErrorMessage(MultiLangModel.ErrorOrAlertMessage.errorExceedMsg) - .build() + val intent = + lassi.setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW).setSupportedFileTypes( + "jpg", + "jpeg", + "png", + "webp", + "gif", + "mp4", + "mkv", + "webm", + "avi", + "flv", + "3gp", + "pdf", + "odt", + "doc", + "docs", + "docx", + "txt", + "ppt", + "pptx", + "rtf", + "xlsx", + "xls" + ).setMaxCount(3) + .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) + .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) @@ -198,82 +172,49 @@ 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(1000000).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) - .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) - .enableActualCircleCrop() - .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif") - .enableFlip() - .enableRotate() - .build() + 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(10000) + .enableActualCircleCrop() + .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip() + .enableRotate().build() receiveData.launch(intent) } } } private fun launchDocPicker() { - val intent = Lassi(this) - .setMediaType(MediaType.DOC) - .setMaxCount(4) - .setGridSize(2) + val intent = lassi.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) } @@ -309,8 +250,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/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt b/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt index 539bb83..41a10ad 100644 --- a/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt +++ b/lassi/src/main/java/com/lassi/data/media/repository/MediaRepositoryImpl.kt @@ -7,7 +7,6 @@ import android.os.Build import android.provider.MediaStore import android.util.Log import android.webkit.MimeTypeMap -import com.lassi.R import com.lassi.common.extenstions.catch import com.lassi.common.utils.KeyUtils import com.lassi.common.utils.Logger @@ -21,7 +20,7 @@ import com.lassi.data.media.entity.MediaFileEntity import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.MediaRepository import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers.IO @@ -225,7 +224,7 @@ class MediaRepositoryImpl(private val context: Context) : MediaRepository { dateAdded: Long, mediaType: MediaType, ) { - val bucketName = bucket ?: MultiLangModel.Common.lassiAll + val bucketName = bucket ?: MultiLangConfig.getConfig().lassiAll if (isFileTypeSupported(miMedia.path)) { CoroutineScope(IO).launch { miMedia.path?.let { path -> diff --git a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt index a387092..f7731c9 100644 --- a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt +++ b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt @@ -1,6 +1,5 @@ package com.lassi.domain.media -import android.content.res.Resources import android.graphics.Color import android.os.Parcelable import androidx.annotation.DrawableRes @@ -41,7 +40,7 @@ data class LassiConfig( var isCrop: Boolean = true, var alertDialogNegativeButtonColor: Int = Color.BLACK, var alertDialogPositiveButtonColor: Int = Color.BLACK, - var customLimitExceedingErrorMessage: String = MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg + var customLimitExceedingErrorMessage: String = MultiLangConfig.getConfig().defaultExceedErrorMsg ) : Parcelable { companion object { @@ -57,7 +56,7 @@ data class LassiConfig( selectedMedias = lassiConfig.selectedMedias mediaType = lassiConfig.mediaType maxCount = lassiConfig.maxCount - ascFlag= lassiConfig.ascFlag + ascFlag = lassiConfig.ascFlag gridSize = lassiConfig.gridSize lassiOption = lassiConfig.lassiOption minTime = lassiConfig.minTime diff --git a/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt index d13a336..e5e778b 100644 --- a/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt +++ b/lassi/src/main/java/com/lassi/domain/media/MultiLangModel.kt @@ -1,196 +1,100 @@ package com.lassi.domain.media -import android.content.Context -import com.lassi.R -import com.lassi.domain.media.MultiLangModel.Common.cancel -import com.lassi.domain.media.MultiLangModel.Common.lassiAll -import com.lassi.domain.media.MultiLangModel.Common.ok -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageActivityNoPermissions -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageActivityTitle -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlip -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlipHorizontally -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuFlipVertically -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuRotateLeft -import com.lassi.domain.media.MultiLangModel.CropImage.cropImageMenuRotateRight -import com.lassi.domain.media.MultiLangModel.CropImage.pickImageIntentChooserTitle -import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems -import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg -import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.errorExceedMsg -import com.lassi.domain.media.MultiLangModel.ErrorOrAlertMessage.noDataFound -import com.lassi.domain.media.MultiLangModel.ImageActions.cropImageMenuCrop -import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24 -import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24Horizontally -import com.lassi.domain.media.MultiLangModel.ImageActions.icFlip24Vertically -import com.lassi.domain.media.MultiLangModel.ImageActions.icRotateLeft24 -import com.lassi.domain.media.MultiLangModel.ImageActions.icRotateRight24 -import com.lassi.domain.media.MultiLangModel.ImageActions.mainActionCrop -import com.lassi.domain.media.MultiLangModel.ImageActions.mainActionRotate -import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageCamera -import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageChooserTitle -import com.lassi.domain.media.MultiLangModel.ImageActions.pickImageGallery -import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraAudioPermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraAudioStoragePermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraPermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.cameraStoragePermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.readMediaAudioPermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.readMediaImagesVideoPermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPermission.storagePermissionRational -import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.camera -import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.done -import com.lassi.domain.media.MultiLangModel.MediaPickerMenu.sort -import com.lassi.domain.media.MultiLangModel.Sorting.sortAscending -import com.lassi.domain.media.MultiLangModel.Sorting.sortByDate -import com.lassi.domain.media.MultiLangModel.Sorting.sortDescending +import android.os.Parcelable +import kotlinx.parcelize.Parcelize -object MultiLangModel { - object Common { - var ok: String = "" - var cancel: String = "" - var lassiAll: String = "" - } - object CropImage { - var cropImageMenuRotateLeft: String = "" - var cropImageMenuRotateRight: String = "" - var cropImageMenuFlip: String = "" - var cropImageMenuFlipHorizontally: String = "" - var cropImageMenuFlipVertically: String = "" - var pickImageIntentChooserTitle: String = "" - var cropImageActivityNoPermissions: String = "" - var cropImageActivityTitle: String = "" - } - object MediaPickerMenu { - var camera: String = "" - var sort: String = "" - var done: String = "" - } - object MediaPermission { - var cameraAudioStoragePermissionRational: String = "" - var cameraStoragePermissionRational: String = "" - var cameraAudioPermissionRational: String = "" - var cameraPermissionRational: String = "" - var storagePermissionRational: String = "" - var readMediaImagesVideoPermissionRational: String = "" - var readMediaAudioPermissionRational: String = "" - } - object ErrorOrAlertMessage { - var alreadySelectedMaxItems: String = "" - var errorExceedMsg: String = "" - var defaultExceedErrorMsg: String = "" - var noDataFound: String = "" - } - object Sorting { - var sortByDate: String = "" - var sortAscending: String = "" - var sortDescending: String = "" - } - object ImageActions { - var icRotateLeft24: String = "" - var icRotateRight24: String = "" - var cropImageMenuCrop: String = "" - var icFlip24: String = "" - var icFlip24Horizontally: String = "" - var icFlip24Vertically: String = "" - var pickImageChooserTitle: String = "" - var pickImageCamera: String = "" - var pickImageGallery: String = "" - var mainActionRotate: String = "" - var mainActionCrop: String = "" - } - - //Setting data initially - /*fun initializeDefaultValues(context: Context) { - ok = context.getString(R.string.ok) - cancel = context.getString(R.string.cancel) - lassiAll = context.getString(R.string.lassi_all) +@Parcelize +data class MultiLangConfig( + var ok: String = "", + var cancel: String = "", + var lassiAll: String = "", + var cropImageMenuRotateLeft: String = "", + var cropImageMenuRotateRight: String = "", + var cropImageMenuFlip: String = "", + var cropImageMenuFlipHorizontally: String = "", + var cropImageMenuFlipVertically: String = "", + var pickImageIntentChooserTitle: String = "", + var cropImageActivityNoPermissions: String = "", + var cropImageActivityTitle: String = "", + var camera: String = "", + var sort: String = "", + var done: String = "", + var cameraAudioStoragePermissionRational: String = "", + var cameraStoragePermissionRational: String = "", + var cameraAudioPermissionRational: String = "", + var cameraPermissionRational: String = "", + var storagePermissionRational: String = "", + var readMediaImagesVideoPermissionRational: String = "", + var readMediaAudioPermissionRational: String = "", + var alreadySelectedMaxItems: String = "", + var errorExceedMsg: String = "", + var defaultExceedErrorMsg: String = "", + var noDataFound: String = "", + var sortByDate: String = "", + var sortAscending: String = "", + var sortDescending: String = "", + var icRotateLeft24: String = "", + var icRotateRight24: String = "", + var cropImageMenuCrop: String = "", + var icFlip24: String = "", + var icFlip24Horizontally: String = "", + var icFlip24Vertically: String = "", + var pickImageChooserTitle: String = "", + var pickImageCamera: String = "", + var pickImageGallery: String = "", + var mainActionRotate: String = "", + var mainActionCrop: String = "" +) : Parcelable { + companion object { + private var multiLangConfig = MultiLangConfig() - cropImageMenuRotateLeft = context.getString(R.string.crop_image_menu_rotate_left) - cropImageMenuRotateRight = context.getString(R.string.crop_image_menu_rotate_right) - cropImageMenuFlip = context.getString(R.string.crop_image_menu_flip) - cropImageMenuFlipHorizontally = context.getString(R.string.crop_image_menu_flip_horizontally) - cropImageMenuFlipVertically = context.getString(R.string.crop_image_menu_flip_vertically) - pickImageIntentChooserTitle = context.getString(R.string.pick_image_intent_chooser_title) - cropImageActivityNoPermissions = context.getString(R.string.crop_image_activity_no_permissions) - cropImageActivityTitle = context.getString(R.string.crop_image_activity_title) + fun setMultiLangConfig(config: MultiLangConfig) { + multiLangConfig.apply { + ok = config.ok + cancel = config.cancel + lassiAll = config.lassiAll + cropImageMenuRotateLeft = config.cropImageMenuRotateLeft + cropImageMenuRotateRight = config.cropImageMenuRotateRight + cropImageMenuFlip = config.cropImageMenuFlip + cropImageMenuFlipHorizontally = config.cropImageMenuFlipHorizontally + cropImageMenuFlipVertically = config.cropImageMenuFlipVertically + pickImageIntentChooserTitle = config.pickImageIntentChooserTitle + cropImageActivityNoPermissions = config.cropImageActivityNoPermissions + cropImageActivityTitle = config.cropImageActivityTitle + camera = config.camera + sort = config.sort + done = config.done + cameraAudioStoragePermissionRational = config.cameraAudioStoragePermissionRational + cameraStoragePermissionRational = config.cameraStoragePermissionRational + cameraAudioPermissionRational = config.cameraAudioPermissionRational + cameraPermissionRational = config.cameraPermissionRational + storagePermissionRational = config.storagePermissionRational + readMediaImagesVideoPermissionRational = + config.readMediaImagesVideoPermissionRational + readMediaAudioPermissionRational = config.readMediaAudioPermissionRational + alreadySelectedMaxItems = config.alreadySelectedMaxItems + errorExceedMsg = config.errorExceedMsg + defaultExceedErrorMsg = config.defaultExceedErrorMsg + noDataFound = config.noDataFound + sortByDate = config.sortByDate + sortAscending = config.sortAscending + sortDescending = config.sortDescending + icRotateLeft24 = config.icRotateLeft24 + icRotateRight24 = config.icRotateRight24 + cropImageMenuCrop = config.cropImageMenuCrop + icFlip24 = config.icFlip24 + icFlip24Horizontally = config.icFlip24Horizontally + icFlip24Vertically = config.icFlip24Vertically + pickImageChooserTitle = config.pickImageChooserTitle + pickImageCamera = config.pickImageCamera + pickImageGallery = config.pickImageGallery + mainActionRotate = config.mainActionRotate + mainActionCrop = config.mainActionCrop + } + } - camera = context.getString(R.string.camera) - sort = context.getString(R.string.sort) - done = context.getString(R.string.done) - - cameraAudioStoragePermissionRational = context.getString(R.string.camera_audio_storage_permission_rational) - cameraStoragePermissionRational = context.getString(R.string.camera_storage_permission_rational) - cameraAudioPermissionRational = context.getString(R.string.camera_audio_permission_rational) - cameraPermissionRational = context.getString(R.string.camera_permission_rational) - storagePermissionRational = context.getString(R.string.storage_permission_rational) - readMediaImagesVideoPermissionRational = context.getString(R.string.read_media_images_video_permission_rational) - readMediaAudioPermissionRational = context.getString(R.string.read_media_audio_permission_rational) - - alreadySelectedMaxItems = context.getString(R.string.already_selected_max_items) - errorExceedMsg = context.getString(R.string.error_exceed_msg) - defaultExceedErrorMsg = context.getString(R.string.default_exceed_error_msg) - noDataFound = context.getString(R.string.no_data_found) - - sortByDate = context.getString(R.string.sort_by_date) - sortAscending = context.getString(R.string.sort_ascending) - sortDescending = context.getString(R.string.sort_descending) - - icRotateLeft24 = context.getString(R.string.ic_rotate_left_24) - icRotateRight24 = context.getString(R.string.ic_rotate_right_24) - cropImageMenuCrop = context.getString(R.string.crop_image_menu_crop) - icFlip24 = context.getString(R.string.ic_flip_24) - icFlip24Horizontally = context.getString(R.string.ic_flip_24_horizontally) - icFlip24Vertically = context.getString(R.string.ic_flip_24_vertically) - pickImageChooserTitle = context.getString(R.string.pick_image_chooser_title) - pickImageCamera = context.getString(R.string.pick_image_camera) - pickImageGallery = context.getString(R.string.pick_image_gallery) - mainActionRotate = context.getString(R.string.main_action_rotate) - mainActionCrop = context.getString(R.string.main_action_crop) - }*/ + fun getConfig(): MultiLangConfig { + return multiLangConfig + } + } } - - -/* -data class MultiLangModel( - val ok: String, - val cancel: String, - val selectedItems: String, - val directoryWithItemCount: String, - val lassiAll: String, - val cropImageMenuRotateLeft: String, - val cropImageMenuRotateRight: String, - val cropImageMenuFlip: String, - val cropImageMenuFlipHorizontally: String, - val cropImageMenuFlipVertically: String, - val pickImageIntentChooserTitle: String, - val cropImageActivityNoPermissions: String, - val cropImageActivityTitle: String, - val camera: String, - val sort: String, - val done: String, - val alreadySelectedMaxItems: String, - val cameraAudioStoragePermissionRational: String, - val cameraStoragePermissionRational: String, - val cameraAudioPermissionRational: String, - val cameraPermissionRational: String, - val storagePermissionRational: String, - val readMediaImagesVideoPermissionRational: String, - val readMediaAudioPermissionRational: String, -// val minVideoRecordingTimeError: String, - val errorExceedMsg: String, - val defaultExceedErrorMsg: String, - val icRotateLeft24: String, - val icRotateRight24: String, - val cropImageMenuCrop: String, - val icFlip24: String, - val icFlip24Horizontally: String, - val icFlip24Vertically: String, - val pickImageChooserTitle: String, - val pickImageCamera: String, - val pickImageGallery: String, - val mainActionRotate: String, - val mainActionCrop: String, - val noDataFound: String, - val sortByDate: String, - val sortAscending: String, - val sortDescending: String, -// val sortingOptions: Array -)*/ diff --git a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt index 3bced02..19b0362 100644 --- a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt +++ b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt @@ -12,7 +12,7 @@ import com.lassi.common.utils.KeyUtils import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.domain.media.SortingOption import com.lassi.presentation.cameraview.controls.AspectRatio import com.lassi.presentation.cropper.CropImageView @@ -21,13 +21,10 @@ import com.lassi.presentation.mediadirectory.LassiMediaPickerActivity class Lassi(private val context: Context) { private var lassiConfig = LassiConfig() + private var multiLangConfig = MultiLangConfig() init { - //To set default language - Log.d("TAG", "!@# OCCURRENCE: Lassi INIT") - - //TODO - Need to remove this call and call it from UI side -// getMultiLngBuilder() + getMultiLngBuilder() } /** @@ -74,45 +71,80 @@ class Lassi(private val context: Context) { setMainActionRotateLbl: String? = null, setMainActionCropLbl: String? = null, ): Lassi { - MultiLangModel.Common.ok = setOkLbl ?: context.getString(R.string.ok) - MultiLangModel.Common.cancel = setCancelLbl ?: context.getString(R.string.cancel) - MultiLangModel.Common.lassiAll = setLassiAllLbl ?: context.getString(R.string.lassi_all) - MultiLangModel.CropImage.cropImageMenuRotateLeft = setCropImageMenuRotateLeftLbl ?: context.getString(R.string.crop_image_menu_rotate_left) - MultiLangModel.CropImage.cropImageMenuRotateRight = setCropImageMenuRotateRightLbl ?: context.getString(R.string.crop_image_menu_rotate_right) - MultiLangModel.CropImage.cropImageMenuFlip = setCropImageMenuFlipLbl ?: context.getString(R.string.crop_image_menu_flip) - MultiLangModel.CropImage.cropImageMenuFlipHorizontally = setCropImageMenuFlipHorizontallyLbl ?: context.getString(R.string.crop_image_menu_flip_horizontally) - MultiLangModel.CropImage.cropImageMenuFlipVertically = setCropImageMenuFlipVerticallyLbl ?: context.getString(R.string.crop_image_menu_flip_vertically) - MultiLangModel.CropImage.pickImageIntentChooserTitle = setPickImageIntentChooserTitleLbl ?: context.getString(R.string.pick_image_intent_chooser_title) - MultiLangModel.CropImage.cropImageActivityNoPermissions = setCropImageActivityNoPermissionsLbl ?: context.getString(R.string.crop_image_activity_no_permissions) - MultiLangModel.CropImage.cropImageActivityTitle = setCropImageActivityTitleLbl ?: context.getString(R.string.crop_image_activity_title) - MultiLangModel.MediaPickerMenu.camera = setCameraLbl ?: context.getString(R.string.camera) - MultiLangModel.MediaPickerMenu.sort = setSortLbl ?: context.getString(R.string.sort) - MultiLangModel.MediaPickerMenu.done = setDoneLbl ?: context.getString(R.string.done) - MultiLangModel.MediaPermission.cameraAudioStoragePermissionRational = setCameraAudioStoragePermissionRationalLbl ?: context.getString(R.string.camera_audio_storage_permission_rational) - MultiLangModel.MediaPermission.cameraStoragePermissionRational = setCameraStoragePermissionRationalLbl ?: context.getString(R.string.camera_storage_permission_rational) - MultiLangModel.MediaPermission.cameraAudioPermissionRational = setCameraAudioPermissionRationalLbl ?: context.getString(R.string.camera_audio_permission_rational) - MultiLangModel.MediaPermission.cameraPermissionRational = setCameraPermissionRationalLbl ?: context.getString(R.string.camera_permission_rational) - MultiLangModel.MediaPermission.storagePermissionRational = setStoragePermissionRationalLbl ?: context.getString(R.string.storage_permission_rational) - MultiLangModel.MediaPermission.readMediaImagesVideoPermissionRational = setReadMediaImagesVideoPermissionRationalLbl ?: context.getString(R.string.read_media_images_video_permission_rational) - MultiLangModel.MediaPermission.readMediaAudioPermissionRational = setReadMediaAudioPermissionRationalLbl ?: context.getString(R.string.read_media_audio_permission_rational) - MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems = setAlreadySelectedMaxItemsLbl ?: context.getString(R.string.already_selected_max_items) - MultiLangModel.ErrorOrAlertMessage.errorExceedMsg = setErrorExceedMsgLbl ?: context.getString(R.string.error_exceed_msg) - MultiLangModel.ErrorOrAlertMessage.defaultExceedErrorMsg = setDefaultExceedErrorMsgLbl ?: context.getString(R.string.default_exceed_error_msg) - MultiLangModel.ErrorOrAlertMessage.noDataFound = setNoDataFoundLbl ?: context.getString(R.string.no_data_found) - MultiLangModel.Sorting.sortByDate = setSortByDateLbl ?: context.getString(R.string.sort_by_date) - MultiLangModel.Sorting.sortAscending = setSortAscendingLbl ?: context.getString(R.string.sort_ascending) - MultiLangModel.Sorting.sortDescending = setSortDescendingLbl ?: context.getString(R.string.sort_descending) - MultiLangModel.ImageActions.icRotateLeft24 = setIcRotateLeft24Lbl ?: context.getString(R.string.ic_rotate_left_24) - MultiLangModel.ImageActions.icRotateRight24 = setIcRotateRight24Lbl ?: context.getString(R.string.ic_rotate_right_24) - MultiLangModel.ImageActions.cropImageMenuCrop = setCropImageMenuCropLbl ?: context.getString(R.string.crop_image_menu_crop) - MultiLangModel.ImageActions.icFlip24 = setIcFlip24Lbl ?: context.getString(R.string.ic_flip_24) - MultiLangModel.ImageActions.icFlip24Horizontally = setIcFlip24HorizontallyLbl ?: context.getString(R.string.ic_flip_24_horizontally) - MultiLangModel.ImageActions.icFlip24Vertically = setIcFlip24VerticallyLbl ?: context.getString(R.string.ic_flip_24_vertically) - MultiLangModel.ImageActions.pickImageChooserTitle = setPickImageChooserTitleLbl ?: context.getString(R.string.pick_image_chooser_title) - MultiLangModel.ImageActions.pickImageCamera = setPickImageCameraLbl ?: context.getString(R.string.pick_image_camera) - MultiLangModel.ImageActions.pickImageGallery = setPickImageGalleryLbl ?: context.getString(R.string.pick_image_gallery) - MultiLangModel.ImageActions.mainActionRotate = setMainActionRotateLbl ?: context.getString(R.string.main_action_rotate) - MultiLangModel.ImageActions.mainActionCrop = setMainActionCropLbl ?: context.getString(R.string.main_action_crop) + Log.d("TAG", "!@# setOkLbl:: LASSI: $setOkLbl ") + multiLangConfig.ok = setOkLbl ?: context.getString(R.string.ok) + multiLangConfig.cancel = setCancelLbl ?: context.getString(R.string.cancel) + multiLangConfig.lassiAll = setLassiAllLbl ?: context.getString(R.string.lassi_all) + multiLangConfig.cropImageMenuRotateLeft = + setCropImageMenuRotateLeftLbl ?: context.getString(R.string.crop_image_menu_rotate_left) + multiLangConfig.cropImageMenuRotateRight = setCropImageMenuRotateRightLbl + ?: context.getString(R.string.crop_image_menu_rotate_right) + multiLangConfig.cropImageMenuFlip = + setCropImageMenuFlipLbl ?: context.getString(R.string.crop_image_menu_flip) + multiLangConfig.cropImageMenuFlipHorizontally = setCropImageMenuFlipHorizontallyLbl + ?: context.getString(R.string.crop_image_menu_flip_horizontally) + multiLangConfig.cropImageMenuFlipVertically = setCropImageMenuFlipVerticallyLbl + ?: context.getString(R.string.crop_image_menu_flip_vertically) + multiLangConfig.pickImageIntentChooserTitle = setPickImageIntentChooserTitleLbl + ?: context.getString(R.string.pick_image_intent_chooser_title) + multiLangConfig.cropImageActivityNoPermissions = setCropImageActivityNoPermissionsLbl + ?: context.getString(R.string.crop_image_activity_no_permissions) + multiLangConfig.cropImageActivityTitle = + setCropImageActivityTitleLbl ?: context.getString(R.string.crop_image_activity_title) + multiLangConfig.camera = setCameraLbl ?: context.getString(R.string.camera) + multiLangConfig.sort = setSortLbl ?: context.getString(R.string.sort) + multiLangConfig.done = setDoneLbl ?: context.getString(R.string.done) + multiLangConfig.cameraAudioStoragePermissionRational = + setCameraAudioStoragePermissionRationalLbl + ?: context.getString(R.string.camera_audio_storage_permission_rational) + multiLangConfig.cameraStoragePermissionRational = setCameraStoragePermissionRationalLbl + ?: context.getString(R.string.camera_storage_permission_rational) + multiLangConfig.cameraAudioPermissionRational = setCameraAudioPermissionRationalLbl + ?: context.getString(R.string.camera_audio_permission_rational) + multiLangConfig.cameraPermissionRational = + setCameraPermissionRationalLbl ?: context.getString(R.string.camera_permission_rational) + multiLangConfig.storagePermissionRational = setStoragePermissionRationalLbl + ?: context.getString(R.string.storage_permission_rational) + multiLangConfig.readMediaImagesVideoPermissionRational = + setReadMediaImagesVideoPermissionRationalLbl + ?: context.getString(R.string.read_media_images_video_permission_rational) + multiLangConfig.readMediaAudioPermissionRational = setReadMediaAudioPermissionRationalLbl + ?: context.getString(R.string.read_media_audio_permission_rational) + multiLangConfig.alreadySelectedMaxItems = + setAlreadySelectedMaxItemsLbl ?: context.getString(R.string.already_selected_max_items) + multiLangConfig.errorExceedMsg = + setErrorExceedMsgLbl ?: context.getString(R.string.error_exceed_msg) + multiLangConfig.defaultExceedErrorMsg = + setDefaultExceedErrorMsgLbl ?: context.getString(R.string.default_exceed_error_msg) + multiLangConfig.noDataFound = setNoDataFoundLbl ?: context.getString(R.string.no_data_found) + multiLangConfig.sortByDate = setSortByDateLbl ?: context.getString(R.string.sort_by_date) + multiLangConfig.sortAscending = + setSortAscendingLbl ?: context.getString(R.string.sort_ascending) + multiLangConfig.sortDescending = + setSortDescendingLbl ?: context.getString(R.string.sort_descending) + multiLangConfig.icRotateLeft24 = + setIcRotateLeft24Lbl ?: context.getString(R.string.ic_rotate_left_24) + multiLangConfig.icRotateRight24 = + setIcRotateRight24Lbl ?: context.getString(R.string.ic_rotate_right_24) + multiLangConfig.cropImageMenuCrop = + setCropImageMenuCropLbl ?: context.getString(R.string.crop_image_menu_crop) + multiLangConfig.icFlip24 = setIcFlip24Lbl ?: context.getString(R.string.ic_flip_24) + multiLangConfig.icFlip24Horizontally = + setIcFlip24HorizontallyLbl ?: context.getString(R.string.ic_flip_24_horizontally) + multiLangConfig.icFlip24Vertically = + setIcFlip24VerticallyLbl ?: context.getString(R.string.ic_flip_24_vertically) + multiLangConfig.pickImageChooserTitle = + setPickImageChooserTitleLbl ?: context.getString(R.string.pick_image_chooser_title) + multiLangConfig.pickImageCamera = + setPickImageCameraLbl ?: context.getString(R.string.pick_image_camera) + multiLangConfig.pickImageGallery = + setPickImageGalleryLbl ?: context.getString(R.string.pick_image_gallery) + multiLangConfig.mainActionRotate = + setMainActionRotateLbl ?: context.getString(R.string.main_action_rotate) + multiLangConfig.mainActionCrop = + setMainActionCropLbl ?: context.getString(R.string.main_action_crop) + + MultiLangConfig.setMultiLangConfig(multiLangConfig) return this } @@ -414,6 +446,7 @@ class Lassi(private val context: Context) { */ fun build(): Intent { LassiConfig.setConfig(lassiConfig) +// MultiLangConfig.setMultiLangConfig(multiLangConfig) return Intent(context, LassiMediaPickerActivity::class.java) } } diff --git a/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt b/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt index d2c4832..f2fe9b6 100644 --- a/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/camera/CameraFragment.kt @@ -31,7 +31,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.cameraview.audio.Audio import com.lassi.presentation.cameraview.audio.Flash import com.lassi.presentation.cameraview.audio.Mode @@ -327,24 +327,23 @@ class CameraFragment : LassiBaseViewModelFragment= Build.VERSION_CODES.TIRAMISU ) { - MultiLangModel.MediaPermission.cameraAudioPermissionRational + MultiLangConfig.getConfig().cameraAudioPermissionRational } else if (LassiConfig.getConfig().mediaType == MediaType.IMAGE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) { - MultiLangModel.MediaPermission.cameraPermissionRational + MultiLangConfig.getConfig().cameraPermissionRational } else { - MultiLangModel.MediaPermission.cameraStoragePermissionRational + MultiLangConfig.getConfig().cameraStoragePermissionRational } - Log.d("TAG", "!@# LASSI:: CAMERA: MultiLangModel.Common.ok: ${MultiLangModel.Common.ok}") val alertDialog = AlertDialog.Builder(requireContext(), R.style.dialogTheme) .setMessage(alertMessage) .setCancelable(false) - .setPositiveButton(MultiLangModel.Common.ok) { _, _ -> + .setPositiveButton(MultiLangConfig.getConfig().ok) { _, _ -> val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS @@ -352,7 +351,7 @@ class CameraFragment : LassiBaseViewModelFragment + .setNegativeButton(MultiLangConfig.getConfig().cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt index 266be34..6f2c413 100644 --- a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt +++ b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageActivity.kt @@ -27,7 +27,7 @@ import com.lassi.common.utils.KeyUtils import com.lassi.common.utils.Logger import com.lassi.data.media.MiMedia import com.lassi.databinding.CropImageActivityBinding -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.cropper.utils.getUriForFile import java.io.File @@ -177,11 +177,11 @@ open class CropImageActivity : AppCompatActivity(), CropImageView.OnSetImageUriC } true } - .setTitle(MultiLangModel.ImageActions.pickImageChooserTitle) + .setTitle(MultiLangConfig.getConfig().pickImageChooserTitle) .setItems( arrayOf( - MultiLangModel.ImageActions.pickImageCamera, - MultiLangModel.ImageActions.pickImageGallery + MultiLangConfig.getConfig().pickImageCamera, + MultiLangConfig.getConfig().pickImageGallery ), ) { _, position -> openSource(if (position == 0) Source.CAMERA else Source.GALLERY) } .show() diff --git a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt index 6d3b6e5..f76f99f 100644 --- a/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt +++ b/lassi/src/main/java/com/lassi/presentation/cropper/CropImageIntentChooser.kt @@ -14,7 +14,7 @@ import android.provider.MediaStore import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts import com.lassi.R -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig internal class CropImageIntentChooser( private val activity: ComponentActivity, @@ -33,7 +33,7 @@ internal class CropImageIntentChooser( const val MIUI_GALLERY = "com.miui.gallery" } - private var title: String = MultiLangModel.ImageActions.pickImageChooserTitle + private var title: String = MultiLangConfig.getConfig().pickImageChooserTitle private var priorityIntentList = listOf( GOOGLE_PHOTOS, GOOGLE_PHOTOS_GO, diff --git a/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt b/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt index f362626..e438547 100644 --- a/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/docs/DocsFragment.kt @@ -26,7 +26,7 @@ import com.lassi.data.media.MiMedia import com.lassi.databinding.FragmentMediaPickerBinding import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.media.SelectedMediaViewModel @@ -235,16 +235,16 @@ class DocsFragment : LassiBaseViewModelFragment + alertDialog.setPositiveButton(MultiLangConfig.getConfig().ok) { _, _ -> val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS data = Uri.fromParts("package", activity?.packageName, null) } mPermissionSettingResult.launch(intent) } - alertDialog.setNegativeButton(MultiLangModel.Common.cancel) { _, _ -> + alertDialog.setNegativeButton(MultiLangConfig.getConfig().cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt index be0fd56..6fac511 100644 --- a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt @@ -30,7 +30,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.cropper.CropImageContract @@ -279,8 +279,8 @@ class MediaFragment : )*/ val currentSortingOption = viewModel.currentSortingOption.value - val ascendingLabel = MultiLangModel.Sorting.sortAscending - val descendingLabel = MultiLangModel.Sorting.sortDescending + val ascendingLabel = MultiLangConfig.getConfig().sortAscending + val descendingLabel = MultiLangConfig.getConfig().sortDescending val checkedId = when (currentSortingOption) { ASCENDING_ORDER -> { @@ -306,9 +306,9 @@ class MediaFragment : //Set up the alert builder with the custom layout.. AlertDialog.Builder(requireContext()).apply { - setTitle(MultiLangModel.Sorting.sortByDate) + setTitle(MultiLangConfig.getConfig().sortByDate) setView(customDialogView) - setPositiveButton(MultiLangModel.Common.ok) { _, _ -> + setPositiveButton(MultiLangConfig.getConfig().ok) { _, _ -> val checkedRadioButtonId = sortingRadioGroup.checkedRadioButtonId val selectedOption = if (checkedRadioButtonId == R.id.radioAscending) ASCENDING_ORDER else DESCENDING_ORDER @@ -343,7 +343,7 @@ class MediaFragment : } } } - setNegativeButton(MultiLangModel.Common.cancel, null) + setNegativeButton(MultiLangConfig.getConfig().cancel, null) create().show() } } diff --git a/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt b/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt index 0da061a..c515cba 100644 --- a/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/mediadirectory/FolderFragment.kt @@ -29,7 +29,7 @@ import com.lassi.databinding.FragmentMediaPickerBinding import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.common.LassiBaseViewModelFragment import com.lassi.presentation.common.decoration.GridSpacingItemDecoration import com.lassi.presentation.media.MediaFragment @@ -127,7 +127,7 @@ class FolderFragment : LassiBaseViewModelFragment @@ -185,15 +185,15 @@ class FolderFragment : LassiBaseViewModelFragment + alertDialog.setPositiveButton(MultiLangConfig.getConfig().ok) { _, _ -> val intent = Intent().apply { action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS data = Uri.fromParts("package", activity?.packageName, null) @@ -211,7 +211,7 @@ class FolderFragment : LassiBaseViewModelFragment + alertDialog.setNegativeButton(MultiLangConfig.getConfig().cancel) { _, _ -> activity?.onBackPressed() } val permissionDialog = alertDialog.create() diff --git a/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt b/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt index bbda4b0..7027398 100644 --- a/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt +++ b/lassi/src/main/java/com/lassi/presentation/mediadirectory/LassiMediaPickerActivity.kt @@ -26,7 +26,7 @@ import com.lassi.domain.common.SafeObserver import com.lassi.domain.media.LassiConfig import com.lassi.domain.media.LassiOption import com.lassi.domain.media.MediaType -import com.lassi.domain.media.MultiLangModel +import com.lassi.domain.media.MultiLangConfig import com.lassi.presentation.camera.CameraFragment import com.lassi.presentation.common.LassiBaseViewModelActivity import com.lassi.presentation.docs.DocsFragment @@ -242,7 +242,7 @@ class LassiMediaPickerActivity : private fun initCamera() { if (viewModel.selectedMediaLiveData.value?.size == LassiConfig.getConfig().maxCount) { - ToastUtils.showToast(this, MultiLangModel.ErrorOrAlertMessage.alreadySelectedMaxItems) + ToastUtils.showToast(this, MultiLangConfig.getConfig().alreadySelectedMaxItems) } else { supportFragmentManager.beginTransaction() .add(R.id.ftContainer, CameraFragment()) From 931e147ebe6282bd1629858b5a9f29fe5a0b8b32 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Mon, 12 Feb 2024 15:30:44 +0530 Subject: [PATCH 05/20] - Added color resources - Media sorting customization for radio button and respective text for active and non-active states --- README.md | 20 ++++- app/src/main/res/values/colors.xml | 2 + .../com/lassi/domain/media/LassiConfig.kt | 9 ++ .../com/lassi/presentation/builder/Lassi.kt | 37 ++++++++ .../lassi/presentation/media/MediaFragment.kt | 86 ++++++++++++++----- 5 files changed, 132 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d192e21..3155cae 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) @@ -124,6 +128,18 @@ Lassi is simplest way to pick media (either image, video, audio or doc) } ``` +* To enable multi-language capabilities, define the required text variations using the parameters accessible within the builder. + + ```kotlin + Lassi(this).getMultiLngBuilder( + setOkLbl = "d'accord", + setCancelLbl = "Annuler", + setSortAscendingLbl = "Ascendant", + setSortDescendingLbl = "Descendant", + setSortByDateLbl = "Trier par date" + ) + ``` + ### 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. If you don't want to give Manage External Storage permission and wants to get files with system default view then You can use `OR` option from Step 1 and give required file type of document. diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index b976e26..bd9d544 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -8,4 +8,6 @@ #E9333C #DFFF00 #50C878 + #22223b + #98c1d9 diff --git a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt index f7731c9..01001b3 100644 --- a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt +++ b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt @@ -2,6 +2,7 @@ package com.lassi.domain.media import android.graphics.Color import android.os.Parcelable +import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import com.lassi.R import com.lassi.common.utils.KeyUtils @@ -17,6 +18,10 @@ data class LassiConfig( var toolbarResourceColor: Int = Color.WHITE, var progressBarColor: Int = Color.BLACK, var galleryBackgroundColor: Int = Color.WHITE, + @ColorRes var sortingCheckedRadioButtonColor: Int = R.color.darkYellow, + @ColorRes var sortingUncheckedRadioButtonColor: Int = R.color.blackTrans50, + @ColorRes var setSortingCheckedTextColor: Int = R.color.darkYellow, + @ColorRes var setSortingUncheckedTextColor: Int = R.color.blackTrans50, @DrawableRes var placeHolder: Int = R.drawable.ic_image_placeholder, @DrawableRes var errorDrawable: Int = R.drawable.ic_image_placeholder, @DrawableRes var selectionDrawable: Int = R.drawable.ic_checked_media, @@ -53,6 +58,10 @@ data class LassiConfig( toolbarResourceColor = lassiConfig.toolbarResourceColor progressBarColor = lassiConfig.progressBarColor galleryBackgroundColor = lassiConfig.galleryBackgroundColor + sortingCheckedRadioButtonColor = lassiConfig.sortingCheckedRadioButtonColor + sortingUncheckedRadioButtonColor = lassiConfig.sortingUncheckedRadioButtonColor + setSortingCheckedTextColor = lassiConfig.setSortingCheckedTextColor + setSortingUncheckedTextColor = lassiConfig.setSortingUncheckedTextColor selectedMedias = lassiConfig.selectedMedias mediaType = lassiConfig.mediaType maxCount = lassiConfig.maxCount diff --git a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt index 19b0362..2fd7ff7 100644 --- a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt +++ b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt @@ -1,5 +1,6 @@ package com.lassi.presentation.builder +import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.graphics.Color @@ -300,6 +301,42 @@ class Lassi(private val context: Context) { return this } + /** + * Set sorting checked state radio button color resource + */ + @SuppressLint("ResourceAsColor") + fun setSortingCheckedRadioButtonColor(@ColorRes color: Int): Lassi { + lassiConfig.sortingCheckedRadioButtonColor = color + return this + } + + /** + * Set sorting unchecked state radio button color resource + */ + @SuppressLint("ResourceAsColor") + fun setSortingUncheckedRadioButtonColor(@ColorRes color: Int): Lassi { + lassiConfig.sortingUncheckedRadioButtonColor = color + return this + } + + /** + * Set sorting checked state radio button color resource + */ + @SuppressLint("ResourceAsColor") + fun setSortingCheckedTextColor(@ColorRes color: Int): Lassi { + lassiConfig.setSortingCheckedTextColor = color + return this + } + + /** + * Set sorting unchecked state radio button color resource + */ + @SuppressLint("ResourceAsColor") + fun setSortingUncheckedTextColor(@ColorRes color: Int): Lassi { + lassiConfig.setSortingUncheckedTextColor = color + return this + } + /** * Set progressbar color hex */ diff --git a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt index 6fac511..751f5fa 100644 --- a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt @@ -3,14 +3,17 @@ package com.lassi.presentation.media import android.app.Activity import android.app.AlertDialog import android.content.Intent +import android.content.res.ColorStateList import android.net.Uri import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem +import android.view.View import android.widget.RadioButton import android.widget.RadioGroup import android.widget.Toast +import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat import androidx.lifecycle.ViewModelProvider @@ -43,6 +46,7 @@ import com.lassi.presentation.mediadirectory.FolderViewModelFactory import com.lassi.presentation.mediadirectory.SelectedMediaViewModelFactory import java.io.File + class MediaFragment : LassiBaseViewModelFragment(), CropImageView.OnSetImageUriCompleteListener, CropImageView.OnCropImageCompleteListener { @@ -51,6 +55,8 @@ class MediaFragment : private var mediaPickerConfig = LassiConfig.getConfig() private var uri: Uri? = null private var menu: Menu? = null + var customDialogView: View? = null + var sortingRadioGroup: RadioGroup? = null companion object { fun getInstance(bucket: MiItemMedia): MediaFragment { @@ -102,6 +108,57 @@ class MediaFragment : override fun initViews() { super.initViews() + + customDialogView = + LayoutInflater.from(requireContext()).inflate(R.layout.sorting_option, null) + sortingRadioGroup = customDialogView?.findViewById(R.id.sortingRadioGroup) + + val rbColorStateList = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) + ), intArrayOf( + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().sortingCheckedRadioButtonColor, + null + ), //Checked color + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().sortingUncheckedRadioButtonColor, + null + ) // Unchecked color + ) + ) + + val rbTextColorStateList = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) + ), intArrayOf( + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().setSortingCheckedTextColor, + null + ), //Checked text color + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().setSortingUncheckedTextColor, + null + ) // Unchecked text color + ) + ) + + //Radio button color + sortingRadioGroup?.findViewById(R.id.radioAscending)?.buttonTintList = + rbColorStateList + sortingRadioGroup?.findViewById(R.id.radioDescending)?.buttonTintList = + rbColorStateList + + //Radio button text color + sortingRadioGroup?.findViewById(R.id.radioAscending) + ?.setTextColor(rbTextColorStateList) + sortingRadioGroup?.findViewById(R.id.radioDescending) + ?.setTextColor(rbTextColorStateList) + bucket?.let { it.bucketName?.let { bucketName -> when (viewModel.currentSortingOption.value) { @@ -265,51 +322,40 @@ class MediaFragment : } private fun handleSorting() { - val customDialogView = - LayoutInflater.from(requireContext()).inflate(R.layout.sorting_option, null) - val sortingRadioGroup = customDialogView.findViewById(R.id.sortingRadioGroup) - - //To set the previously selected option as checked. - /*sortingRadioGroup.check( - when (viewModel.currentSortingOption.value) { - ASCENDING_ORDER -> R.id.radioAscending - DESCENDING_ORDER -> R.id.radioDescending - else -> R.id.radioAscending - } - )*/ - val currentSortingOption = viewModel.currentSortingOption.value val ascendingLabel = MultiLangConfig.getConfig().sortAscending val descendingLabel = MultiLangConfig.getConfig().sortDescending val checkedId = when (currentSortingOption) { ASCENDING_ORDER -> { - sortingRadioGroup.check(R.id.radioAscending) + sortingRadioGroup?.check(R.id.radioAscending) R.id.radioAscending } + DESCENDING_ORDER -> { - sortingRadioGroup.check(R.id.radioDescending) + sortingRadioGroup?.check(R.id.radioDescending) R.id.radioDescending } + else -> { - sortingRadioGroup.check(R.id.radioAscending) + sortingRadioGroup?.check(R.id.radioAscending) R.id.radioAscending } } // Set the labels for the radio buttons - sortingRadioGroup.findViewById(R.id.radioAscending).text = ascendingLabel - sortingRadioGroup.findViewById(R.id.radioDescending).text = descendingLabel + sortingRadioGroup?.findViewById(R.id.radioAscending)?.text = ascendingLabel + sortingRadioGroup?.findViewById(R.id.radioDescending)?.text = descendingLabel // Set the checked radio button in the RadioGroup - sortingRadioGroup.check(checkedId) + sortingRadioGroup?.check(checkedId) //Set up the alert builder with the custom layout.. AlertDialog.Builder(requireContext()).apply { setTitle(MultiLangConfig.getConfig().sortByDate) setView(customDialogView) setPositiveButton(MultiLangConfig.getConfig().ok) { _, _ -> - val checkedRadioButtonId = sortingRadioGroup.checkedRadioButtonId + val checkedRadioButtonId = sortingRadioGroup?.checkedRadioButtonId val selectedOption = if (checkedRadioButtonId == R.id.radioAscending) ASCENDING_ORDER else DESCENDING_ORDER From 7bd005e0d1efaa6dbd95481d6219a5fde3b4ab42 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Mon, 19 Feb 2024 11:44:43 +0530 Subject: [PATCH 06/20] - Fixed illegal state exception error - Created spanish versioned string resource file - Added string resources in order to showcase multi-language support feature - Updated readme file --- README.md | 28 +++-- .../main/java/com/lassi/app/MainActivity.kt | 81 +++++++------- app/src/main/res/values-es/strings.xml | 18 +++ app/src/main/res/values/strings.xml | 6 + .../lassi/presentation/media/MediaFragment.kt | 104 +++++++++--------- 5 files changed, 133 insertions(+), 104 deletions(-) create mode 100644 app/src/main/res/values-es/strings.xml diff --git a/README.md b/README.md index 3155cae..5d4c06a 100644 --- a/README.md +++ b/README.md @@ -127,18 +127,26 @@ Lassi is simplest way to pick media (either image, video, audio or doc) } } ``` - -* To enable multi-language capabilities, define the required text variations using the parameters accessible within the builder. - + +* 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 - Lassi(this).getMultiLngBuilder( - setOkLbl = "d'accord", - setCancelLbl = "Annuler", - setSortAscendingLbl = "Ascendant", - setSortDescendingLbl = "Descendant", - setSortByDateLbl = "Trier par date" - ) + 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. + ``` + 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 f41decd..9fb29a8 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -31,15 +31,12 @@ 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) _binding = ActivityMainBinding.inflate(layoutInflater) -// Lassi(this).getMultiLngBuilder() //Initially set it binding.also { setContentView(it.root) it.btnImagePicker.setOnClickListener(this) @@ -55,20 +52,24 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { lassi = Lassi(this) // Use getMultiLngBuilder in onCreate to set your desired language - 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" - ) + // 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" + ) + } } override fun onClick(v: View?) { @@ -132,29 +133,29 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { R.id.btnDocumentSystemIntent -> { val intent = lassi.setMediaType(MediaType.FILE_TYPE_WITH_SYSTEM_VIEW).setSupportedFileTypes( - "jpg", - "jpeg", - "png", - "webp", - "gif", - "mp4", - "mkv", - "webm", - "avi", - "flv", - "3gp", - "pdf", - "odt", - "doc", - "docs", - "docx", - "txt", - "ppt", - "pptx", - "rtf", - "xlsx", - "xls" - ).setMaxCount(3) + "jpg", + "jpeg", + "png", + "webp", + "gif", + "mp4", + "mkv", + "webm", + "avi", + "flv", + "3gp", + "pdf", + "odt", + "doc", + "docs", + "docx", + "txt", + "ppt", + "pptx", + "rtf", + "xlsx", + "xls" + ).setMaxCount(3) .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) .build() receiveData.launch(intent) diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml new file mode 100644 index 0000000..999c7e9 --- /dev/null +++ b/app/src/main/res/values-es/strings.xml @@ -0,0 +1,18 @@ + + + Lassi sample + Medios seleccionados + Abrir selector de vídeos + Abrir selector de imágenes + Imagen + Video + Documento + Audio + "Abrir vista del sistema " + + Ordenar por fecha + Ascendente + Descendente + No se concede el permiso de la cámara. Por favor, permita que se configure. + Cultivo + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0ee65f1..73feeaa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,4 +8,10 @@ Document Audio Open System View + + Sort by Date + Ascending + Descending + Camera permission is not granted. Please allow it from setting. + Crop diff --git a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt index 751f5fa..002d88b 100644 --- a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt @@ -9,7 +9,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuItem -import android.view.View import android.widget.RadioButton import android.widget.RadioGroup import android.widget.Toast @@ -55,8 +54,6 @@ class MediaFragment : private var mediaPickerConfig = LassiConfig.getConfig() private var uri: Uri? = null private var menu: Menu? = null - var customDialogView: View? = null - var sortingRadioGroup: RadioGroup? = null companion object { fun getInstance(bucket: MiItemMedia): MediaFragment { @@ -108,57 +105,6 @@ class MediaFragment : override fun initViews() { super.initViews() - - customDialogView = - LayoutInflater.from(requireContext()).inflate(R.layout.sorting_option, null) - sortingRadioGroup = customDialogView?.findViewById(R.id.sortingRadioGroup) - - val rbColorStateList = ColorStateList( - arrayOf( - intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) - ), intArrayOf( - ResourcesCompat.getColor( - resources, - LassiConfig.getConfig().sortingCheckedRadioButtonColor, - null - ), //Checked color - ResourcesCompat.getColor( - resources, - LassiConfig.getConfig().sortingUncheckedRadioButtonColor, - null - ) // Unchecked color - ) - ) - - val rbTextColorStateList = ColorStateList( - arrayOf( - intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) - ), intArrayOf( - ResourcesCompat.getColor( - resources, - LassiConfig.getConfig().setSortingCheckedTextColor, - null - ), //Checked text color - ResourcesCompat.getColor( - resources, - LassiConfig.getConfig().setSortingUncheckedTextColor, - null - ) // Unchecked text color - ) - ) - - //Radio button color - sortingRadioGroup?.findViewById(R.id.radioAscending)?.buttonTintList = - rbColorStateList - sortingRadioGroup?.findViewById(R.id.radioDescending)?.buttonTintList = - rbColorStateList - - //Radio button text color - sortingRadioGroup?.findViewById(R.id.radioAscending) - ?.setTextColor(rbTextColorStateList) - sortingRadioGroup?.findViewById(R.id.radioDescending) - ?.setTextColor(rbTextColorStateList) - bucket?.let { it.bucketName?.let { bucketName -> when (viewModel.currentSortingOption.value) { @@ -322,6 +268,56 @@ class MediaFragment : } private fun handleSorting() { + val customDialogView = + LayoutInflater.from(requireContext()).inflate(R.layout.sorting_option, null) + val sortingRadioGroup = customDialogView?.findViewById(R.id.sortingRadioGroup) + + val rbColorStateList = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) + ), intArrayOf( + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().sortingCheckedRadioButtonColor, + null + ), //Checked color + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().sortingUncheckedRadioButtonColor, + null + ) // Unchecked color + ) + ) + + val rbTextColorStateList = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked) + ), intArrayOf( + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().setSortingCheckedTextColor, + null + ), //Checked text color + ResourcesCompat.getColor( + resources, + LassiConfig.getConfig().setSortingUncheckedTextColor, + null + ) // Unchecked text color + ) + ) + + //Radio button color + sortingRadioGroup?.findViewById(R.id.radioAscending)?.buttonTintList = + rbColorStateList + sortingRadioGroup?.findViewById(R.id.radioDescending)?.buttonTintList = + rbColorStateList + + //Radio button text color + sortingRadioGroup?.findViewById(R.id.radioAscending) + ?.setTextColor(rbTextColorStateList) + sortingRadioGroup?.findViewById(R.id.radioDescending) + ?.setTextColor(rbTextColorStateList) + val currentSortingOption = viewModel.currentSortingOption.value val ascendingLabel = MultiLangConfig.getConfig().sortAscending val descendingLabel = MultiLangConfig.getConfig().sortDescending From 576563c4e8d34d63a226426cfe89d497a1d1cfd4 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Tue, 20 Feb 2024 17:56:38 +0530 Subject: [PATCH 07/20] - Renamed variables - Code clean up --- lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt | 8 ++++---- .../src/main/java/com/lassi/presentation/builder/Lassi.kt | 7 ++----- .../java/com/lassi/presentation/media/MediaFragment.kt | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt index 01001b3..0fdd57c 100644 --- a/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt +++ b/lassi/src/main/java/com/lassi/domain/media/LassiConfig.kt @@ -20,8 +20,8 @@ data class LassiConfig( var galleryBackgroundColor: Int = Color.WHITE, @ColorRes var sortingCheckedRadioButtonColor: Int = R.color.darkYellow, @ColorRes var sortingUncheckedRadioButtonColor: Int = R.color.blackTrans50, - @ColorRes var setSortingCheckedTextColor: Int = R.color.darkYellow, - @ColorRes var setSortingUncheckedTextColor: Int = R.color.blackTrans50, + @ColorRes var sortingCheckedTextColor: Int = R.color.darkYellow, + @ColorRes var sortingUncheckedTextColor: Int = R.color.blackTrans50, @DrawableRes var placeHolder: Int = R.drawable.ic_image_placeholder, @DrawableRes var errorDrawable: Int = R.drawable.ic_image_placeholder, @DrawableRes var selectionDrawable: Int = R.drawable.ic_checked_media, @@ -60,8 +60,8 @@ data class LassiConfig( galleryBackgroundColor = lassiConfig.galleryBackgroundColor sortingCheckedRadioButtonColor = lassiConfig.sortingCheckedRadioButtonColor sortingUncheckedRadioButtonColor = lassiConfig.sortingUncheckedRadioButtonColor - setSortingCheckedTextColor = lassiConfig.setSortingCheckedTextColor - setSortingUncheckedTextColor = lassiConfig.setSortingUncheckedTextColor + sortingCheckedTextColor = lassiConfig.sortingCheckedTextColor + sortingUncheckedTextColor = lassiConfig.sortingUncheckedTextColor selectedMedias = lassiConfig.selectedMedias mediaType = lassiConfig.mediaType maxCount = lassiConfig.maxCount diff --git a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt index 2fd7ff7..6e8c576 100644 --- a/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt +++ b/lassi/src/main/java/com/lassi/presentation/builder/Lassi.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.graphics.Color -import android.util.Log import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat @@ -72,7 +71,6 @@ class Lassi(private val context: Context) { setMainActionRotateLbl: String? = null, setMainActionCropLbl: String? = null, ): Lassi { - Log.d("TAG", "!@# setOkLbl:: LASSI: $setOkLbl ") multiLangConfig.ok = setOkLbl ?: context.getString(R.string.ok) multiLangConfig.cancel = setCancelLbl ?: context.getString(R.string.cancel) multiLangConfig.lassiAll = setLassiAllLbl ?: context.getString(R.string.lassi_all) @@ -324,7 +322,7 @@ class Lassi(private val context: Context) { */ @SuppressLint("ResourceAsColor") fun setSortingCheckedTextColor(@ColorRes color: Int): Lassi { - lassiConfig.setSortingCheckedTextColor = color + lassiConfig.sortingCheckedTextColor = color return this } @@ -333,7 +331,7 @@ class Lassi(private val context: Context) { */ @SuppressLint("ResourceAsColor") fun setSortingUncheckedTextColor(@ColorRes color: Int): Lassi { - lassiConfig.setSortingUncheckedTextColor = color + lassiConfig.sortingUncheckedTextColor = color return this } @@ -483,7 +481,6 @@ class Lassi(private val context: Context) { */ fun build(): Intent { LassiConfig.setConfig(lassiConfig) -// MultiLangConfig.setMultiLangConfig(multiLangConfig) return Intent(context, LassiMediaPickerActivity::class.java) } } diff --git a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt index 002d88b..6c29fc0 100644 --- a/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt +++ b/lassi/src/main/java/com/lassi/presentation/media/MediaFragment.kt @@ -295,12 +295,12 @@ class MediaFragment : ), intArrayOf( ResourcesCompat.getColor( resources, - LassiConfig.getConfig().setSortingCheckedTextColor, + LassiConfig.getConfig().sortingCheckedTextColor, null ), //Checked text color ResourcesCompat.getColor( resources, - LassiConfig.getConfig().setSortingUncheckedTextColor, + LassiConfig.getConfig().sortingUncheckedTextColor, null ) // Unchecked text color ) From 773fcea46832492f3972cc40af36da781eff5096 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Tue, 20 Feb 2024 18:58:55 +0530 Subject: [PATCH 08/20] - Set lassi option type in case of open system view --- app/src/main/java/com/lassi/app/MainActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index 9fb29a8..cb6dede 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -131,8 +131,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { } R.id.btnDocumentSystemIntent -> { - val intent = - lassi.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", @@ -156,8 +156,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { "xlsx", "xls" ).setMaxCount(3) - .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) - .build() + .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) + .build() receiveData.launch(intent) } From 39ab939945b05825e66402d9146f6f1f90656be5 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Wed, 21 Feb 2024 14:52:04 +0530 Subject: [PATCH 09/20] - Set lassi option type in case of open system view --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d4c06a..ac7b8c3 100644 --- a/README.md +++ b/README.md @@ -144,9 +144,7 @@ Lassi is simplest way to pick media (either image, video, audio or doc) } ``` * 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. - ``` - https://github.com/Mindinventory/Lassi-Android/blob/931e147ebe6282bd1629858b5a9f29fe5a0b8b32/lassi/src/main/res/values/strings.xml - ``` + * [Lassi params](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. From 93617ebda6ea1030a4cb17188c464995b1621def Mon Sep 17 00:00:00 2001 From: Sanjay Prajapati <82382452+sanjay-mi@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:51:03 +0530 Subject: [PATCH 10/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac7b8c3..74fb6de 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Lassi is simplest way to pick media (either image, video, audio or doc) } ``` * 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 params](https://github.com/Mindinventory/Lassi-Android/blob/931e147ebe6282bd1629858b5a9f29fe5a0b8b32/lassi/src/main/res/values/strings.xml) + * [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. From e4066945b1207049dcc18eeb2eb30f71bcd2d648 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Wed, 21 Feb 2024 17:48:45 +0530 Subject: [PATCH 11/20] - Library version updated from v1.3.0(26) to v1.4.0(27) --- lassi/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lassi/build.gradle b/lassi/build.gradle index c8d4787..dac135d 100644 --- a/lassi/build.gradle +++ b/lassi/build.gradle @@ -14,8 +14,8 @@ android { defaultConfig { minSdk 21 targetSdk 34 - versionCode 26 - versionName "1.3.0" + versionCode 27 + versionName "1.4.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true From 6510029280e1e8aea20ab1210f592fb019524ad9 Mon Sep 17 00:00:00 2001 From: Vrajendra Date: Thu, 29 Feb 2024 11:50:23 +0530 Subject: [PATCH 12/20] - Implemented a way to store media(Video for now) within DB and handle according to the existing approach - Implemented a way to showcase picked video in case of Android 14 default photo picker case --- .../main/java/com/lassi/app/MainActivity.kt | 7 +- lassi/src/main/AndroidManifest.xml | 3 + .../mediadirectory/FolderFragment.kt | 169 +++++++++++++++++- .../mediadirectory/FolderViewModel.kt | 9 + 4 files changed, 183 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index cb6dede..966abed 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 @@ -98,7 +99,9 @@ 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(3000) // 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) @@ -224,6 +227,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { if (it.resultCode == Activity.RESULT_OK) { val selectedMedia = it.data?.getSerializableExtra(KeyUtils.SELECTED_MEDIA) as ArrayList + Log.d("TAG", "!@# it.data: $selectedMedia") + Log.d("PhotoPicker", "!@# PHOTO-PICKER:: picked: selectedMedia: $selectedMedia") if (selectedMedia.isNotEmpty()) { binding.ivEmpty.isVisible = selectedMedia.isEmpty() diff --git a/lassi/src/main/AndroidManifest.xml b/lassi/src/main/AndroidManifest.xml index e5cffcb..0ab9035 100644 --- a/lassi/src/main/AndroidManifest.xml +++ b/lassi/src/main/AndroidManifest.xml @@ -9,6 +9,9 @@ + + + () { @@ -53,6 +65,11 @@ class FolderFragment : LassiBaseViewModelFragment + Log.d("TAG", "!@# MAP:: map: $map") + + if (map.entries.all { it.value }) { + viewModel.addPhotoPickerDataInDatabase() + } else { +// showPermissionDisableAlert() + viewModel.addPhotoPickerDataInDatabase() + } + } + + /** + * Video picker in case of Android 14 will be handled here + * Need to modifty + */ + private val photoPickerLauncher = registerForActivityResult(ActivityResultContracts.PickMultipleVisualMedia()) { uris -> + if (uris.isNotEmpty()) { + Log.d("PhotoPicker", "!@# PHOTO-PICKER:: URIs: ${uris.toString()}") +// val realPath = context?.let { getRealPathFromURI(it, uris.first()) } + val realPath = context?.let { copyFileFromUri(it, uris.first()) } + Log.d("PhotoPicker", "!@# PHOTO-PICKER:: picked: URIs realPath: $realPath") + setResultOk(arrayListOf(MiMedia(path = realPath))) + } else { + Log.d("PhotoPicker", "!@# PHOTO-PICKER:: No media selected") + } + } + + private fun setResultOk(selectedMedia: ArrayList?) { + val intent = Intent().apply { + putExtra(KeyUtils.SELECTED_MEDIA, selectedMedia) + } + activity?.setResult(Activity.RESULT_OK, intent) + activity?.finish() + } + private val folderAdapter by lazy { FolderAdapter(this::onItemClick) } override fun buildViewModel(): FolderViewModel { @@ -145,10 +202,21 @@ class FolderFragment : LassiBaseViewModelFragment= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + needsStorage = needsStorage && ActivityCompat.checkSelfPermission( + requireContext(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED + ) != PackageManager.PERMISSION_GRANTED +// requestAnd14Permission.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.VideoOnly)) +// requestPhotoPickerPermission.launch(vidPermissionAnd14.toTypedArray()) + photoPickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.VideoOnly)) + } else { + needsStorage = needsStorage && ActivityCompat.checkSelfPermission( + requireContext(), Manifest.permission.READ_MEDIA_VIDEO + ) != PackageManager.PERMISSION_GRANTED + requestPermission.launch(vidPermission.toTypedArray()) + } } else { if (LassiConfig.getConfig().mediaType == MediaType.AUDIO) { needsStorage = needsStorage && ActivityCompat.checkSelfPermission( @@ -171,6 +239,98 @@ class FolderFragment : LassiBaseViewModelFragment + val outputFile = File(context.getExternalFilesDir(Environment.DIRECTORY_MOVIES), fileName) + FileOutputStream(outputFile).use { output -> + val buffer = ByteArray(4 * 1024) // buffer size + var read: Int + while (input.read(buffer).also { read = it } != -1) { + output.write(buffer, 0, read) + } + output.flush() + return outputFile.absolutePath + } + } + return null + } + + private fun getFileName(contentResolver: ContentResolver, uri: Uri): String { + var fileName = "temp_media" + contentResolver.query(uri, null, null, null, null)?.use { cursor -> + if (cursor.moveToFirst()) { + val displayNameIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME) + fileName = cursor.getString(displayNameIndex) + } + } + return fileName + } + + + /** + * Working properly and file is opening from sample as well, but file name is static + */ + /*fun copyFileFromUri(context: Context, uri: Uri): String? { + val inputStream: InputStream? = context.contentResolver.openInputStream(uri) + inputStream?.use { input -> + val outputFile = File(context.getExternalFilesDir(Environment.DIRECTORY_MOVIES), "copied_media.mp4") + FileOutputStream(outputFile).use { output -> + val buffer = ByteArray(4 * 1024) // buffer size + var read: Int + while (input.read(buffer).also { read = it } != -1) { + output.write(buffer, 0, read) + } + output.flush() + return outputFile.absolutePath + } + } + return null + }*/ + + /** + * Working but getting improper path + */ + fun getRealPathFromURI(context: Context, uri: Uri): String? { + var cursor: Cursor? = null + try { + val projection = arrayOf( + MediaStore.Images.Media.DATA, + MediaStore.Video.Media.DATA + ) + cursor = context.contentResolver.query(uri, projection, null, null, null) + if (cursor != null && cursor.moveToFirst()) { + val columnIndexImage = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) + val columnIndexVideo = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA) + return if (columnIndexImage != -1) { + cursor.getString(columnIndexImage) + } else { + cursor.getString(columnIndexVideo) + } + } + } finally { + cursor?.close() + } + return null + } + + /*fun getRealPathFromURI(context: Context, uri: Uri): String? { + var cursor: Cursor? = null + try { + val projection = arrayOf(MediaStore.Images.Media.DATA) + cursor = context.contentResolver.query(uri, projection, null, null, null) + if (cursor != null && cursor.moveToFirst()) { + val columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA) + return cursor.getString(columnIndex) + } + } finally { + cursor?.close() + } + return null + }*/ + override fun onResume() { super.onResume() viewModel.checkRemoval() @@ -241,3 +401,4 @@ class FolderFragment : LassiBaseViewModelFragment Date: Fri, 1 Mar 2024 19:28:45 +0530 Subject: [PATCH 13/20] - Code optimization and changes as per the permission requirement - Added photo picker feature and its UI --- .../main/java/com/lassi/app/MainActivity.kt | 32 ++++- app/src/main/res/layout/activity_main.xml | 19 +++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../java/com/lassi/domain/media/MediaType.kt | 3 +- .../mediadirectory/FolderFragment.kt | 132 ++++++++++++++---- 6 files changed, 155 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/lassi/app/MainActivity.kt b/app/src/main/java/com/lassi/app/MainActivity.kt index 966abed..e8b1f95 100644 --- a/app/src/main/java/com/lassi/app/MainActivity.kt +++ b/app/src/main/java/com/lassi/app/MainActivity.kt @@ -47,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)) } @@ -71,6 +72,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { setSortByDateLbl = "Trier par date" ) } +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + binding.btnPhotoPicker.visibility = View.VISIBLE +// } } override fun onClick(v: View?) { @@ -78,6 +82,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { 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) @@ -91,6 +96,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .setCropType(CropImageView.CropShape.OVAL).setCropAspectRatio(1, 1) .setCompressionRatio(10).setMinFileSize(0).setMaxFileSize(10000) .enableActualCircleCrop() + .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif").enableFlip() .enableRotate().build() receiveData.launch(intent) @@ -99,7 +105,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { R.id.btnVideoPicker -> { val intent = lassi.with(LassiOption.CAMERA_AND_GALLERY).setMaxCount(4).setGridSize(3) - .setMinTime(5).setMaxTime(3000) // Set time larger to let file be visible + .setMinTime(5).setMaxTime(30000000) // 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) @@ -112,6 +118,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .setPlaceHolder(R.drawable.ic_video_placeholder) .setErrorDrawable(R.drawable.ic_video_placeholder) .setSelectionDrawable(R.drawable.ic_checked_media) + .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) .setSupportedFileTypes("mp4", "mkv", "webm", "avi", "flv", "3gp").build() receiveData.launch(intent) } @@ -204,6 +211,29 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { .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(10000) + .enableActualCircleCrop() + .setCustomLimitExceedingErrorMessage(MultiLangConfig.getConfig().errorExceedMsg) + .setSupportedFileTypes("jpg", "jpeg", "png", "webp", "gif", "mp4", "mkv", "webm", "avi", "flv", "3gp").enableFlip() + .enableRotate().build() + receiveData.launch(intent) + } } } 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" /> + +