diff --git a/app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt b/app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt index 5a88c35..c4071fe 100644 --- a/app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt +++ b/app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt @@ -17,6 +17,7 @@ import com.bumptech.glide.Glide import com.crazylegend.audiopicker.audios.AudioModel import com.crazylegend.audiopicker.pickers.MultiAudioPicker import com.crazylegend.audiopicker.pickers.SingleAudioPicker +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.TitleTextModifier import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.imagepicker.images.ImageModel @@ -42,43 +43,42 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe private var clickedID = R.id.singleImageBottomSheetPick - private val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - when (clickedID) { - //images - R.id.singleImageBottomSheetPick -> { - showSingleImageBottomSheetPicker() - } - - R.id.imageBottomSheetMultiPick -> { - showImageMultiBottomSheetPicker() - } + private val askForStoragePermission = registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + when (clickedID) { + //images + R.id.singleImageBottomSheetPick -> { + showSingleImageBottomSheetPicker() + } + R.id.imageBottomSheetMultiPick -> { + showImageMultiBottomSheetPicker() + } - //videos - R.id.singleVideoBottomSheetPick -> { - showSingleVideoBottomSheetPicker() - } - R.id.videoBottomSheetMultiPick -> { - showVideoMultiBottomSheetPicker() - } + //videos + R.id.singleVideoBottomSheetPick -> { + showSingleVideoBottomSheetPicker() + } - //audios - R.id.singleAudioBottomSheetPick -> { - showSingleAudioBottomSheetPicker() - } + R.id.videoBottomSheetMultiPick -> { + showVideoMultiBottomSheetPicker() + } - R.id.audioBottomSheetMultiPick -> { - showAudioMultiBottomSheetPicker() - } + //audios + R.id.singleAudioBottomSheetPick -> { + showSingleAudioBottomSheetPicker() + } + R.id.audioBottomSheetMultiPick -> { + showAudioMultiBottomSheetPicker() } - } else { - Log.e("PERMISSION", "NOT ALLOWED!") + } + } else { + Log.e("PERMISSION", "NOT ALLOWED!") } + } //audios @SuppressLint("MissingPermission") @@ -88,21 +88,17 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe textColor = Color.BLACK textPadding = 10 // use dp or sp this is only for demonstration purposes } - setupBaseModifier( - loadingIndicatorColor = R.color.minusColor, - titleTextModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick an audio" - }, - placeHolderModifications = { - resID = R.drawable.ic_image - } - ) + setupBaseModifier(loadingIndicatorColor = R.color.minusColor, titleTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick an audio" + }, placeHolderModifications = { + resID = R.drawable.ic_image + }) }) } @@ -115,41 +111,28 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe textStyle = TitleTextModifier.TextStyle.BOLD textPadding = 10 // use dp or sp this is only for demonstration purposes } - setupBaseMultiPicker( - tintForLoadingProgressBar = ContextCompat.getColor( - requireContext(), - R.color.colorPrimaryDark - ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.BOTTOM_LEFT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple songs" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_album_second - } - ) + setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark), gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.BOTTOM_LEFT, titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple songs" + }, selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, viewHolderPlaceholderModifications = { + resID = R.drawable.ic_album_second + }) }) } private fun loadAudio(audioModel: AudioModel) { - Glide.with(this) - .load(audioModel.loadThumbnail(requireContext().contentResolver)) - .error(R.drawable.ic_album) - .into(binding!!.audio) + Glide.with(this).load(audioModel.loadThumbnail(requireContext().contentResolver)).error(R.drawable.ic_album).into(binding!!.audio) binding!!.audioTitle.text = audioModel.displayName Log.d("AUDIO_PICKED ${audioModel.thumbnail?.isRecycled}", audioModel.toString()) } @@ -164,34 +147,24 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe @SuppressLint("MissingPermission") private fun showVideoMultiBottomSheetPicker() { - MultiVideoPicker.showPicker(requireContext(), arrayOf(), { - setupBaseMultiPicker( - tintForLoadingProgressBar = ContextCompat.getColor( - requireContext(), - R.color.colorPrimaryDark - ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_CENTER - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple videos" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_close - } - ) + MultiVideoPicker.showPicker(requireContext(), arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { + setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark), gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT, titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_CENTER + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple videos" + }, selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, viewHolderPlaceholderModifications = { + resID = R.drawable.ic_close + }) }) } @@ -200,30 +173,24 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe private fun showSingleVideoBottomSheetPicker() { //SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo) - SingleVideoPicker.showPicker(requireContext(), extensions = arrayOf(), { - setupBaseModifier( - loadingIndicatorColor = R.color.minusColor, - titleTextModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick a video" - }, - placeHolderModifications = { - resID = R.drawable.ic_image - } - ) + SingleVideoPicker.showPicker(requireContext(), extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = false), { + setupBaseModifier(loadingIndicatorColor = R.color.minusColor, titleTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick a video" + }, placeHolderModifications = { + resID = R.drawable.ic_image + }) }) } private fun loadVideo(videoModel: VideoModel) { - Glide.with(this) - .load(videoModel.contentUri) - .into(binding!!.video) + Glide.with(this).load(videoModel.contentUri).into(binding!!.video) Log.d("VIDEO_PICKED", videoModel.toString()) } @@ -236,42 +203,31 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe //images @SuppressLint("MissingPermission") private fun showImageMultiBottomSheetPicker() { - MultiImagePicker.showPicker(requireContext(), extensions = arrayOf(), { - setupBaseMultiPicker( - tintForLoadingProgressBar = ContextCompat.getColor( - requireContext(), - R.color.colorPrimaryDark - ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_LEFT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple images" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_image - } - ) + MultiImagePicker.showPicker(requireContext(), extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = false), { + setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark), gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_LEFT, titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple images" + }, selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, viewHolderPlaceholderModifications = { + resID = R.drawable.ic_image + }) }) } @SuppressLint("MissingPermission") private fun showSingleImageBottomSheetPicker() { - SingleImagePicker.showPicker(requireContext(), extensions = arrayOf(), { - loadingIndicatorTint = - ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark) + SingleImagePicker.showPicker(requireContext(), extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { + loadingIndicatorTint = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark) titleTextModifier.apply { textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC @@ -296,9 +252,7 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe } private fun loadImage(imageModel: ImageModel) { - Glide.with(this) - .load(imageModel.contentUri) - .into(binding!!.image) + Glide.with(this).load(imageModel.contentUri).into(binding!!.image) Log.d("IMAGE_PICKED", imageModel.toString()) } @@ -329,37 +283,31 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe //listeners images setFragmentResultListener(SingleImagePicker.SINGLE_IMAGE_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelable(SingleImagePicker.ON_SINGLE_IMAGE_PICK_KEY) + val loadedModel = bundle.getParcelable(SingleImagePicker.ON_SINGLE_IMAGE_PICK_KEY) loadedModel?.let { loadImage(it) } } setFragmentResultListener(MultiImagePicker.MULTI_IMAGE_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelableArrayList(MultiImagePicker.ON_MULTI_IMAGE_PICK_KEY) + val loadedModel = bundle.getParcelableArrayList(MultiImagePicker.ON_MULTI_IMAGE_PICK_KEY) loadedModel?.let { doSomethingWithImageList(it) } } //listeners video setFragmentResultListener(SingleVideoPicker.SINGLE_VIDEO_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelable(SingleVideoPicker.ON_SINGLE_VIDEO_PICK_KEY) + val loadedModel = bundle.getParcelable(SingleVideoPicker.ON_SINGLE_VIDEO_PICK_KEY) loadedModel?.let { loadVideo(it) } } setFragmentResultListener(MultiVideoPicker.MULTI_VIDEO_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelableArrayList(MultiVideoPicker.ON_MULTI_VIDEO_PICK_KEY) + val loadedModel = bundle.getParcelableArrayList(MultiVideoPicker.ON_MULTI_VIDEO_PICK_KEY) loadedModel?.let { doSomethingWithVideoList(it) } } //listeners audio setFragmentResultListener(SingleAudioPicker.SINGLE_AUDIO_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelable(SingleAudioPicker.ON_SINGLE_AUDIO_PICK_KEY) + val loadedModel = bundle.getParcelable(SingleAudioPicker.ON_SINGLE_AUDIO_PICK_KEY) loadedModel?.let { loadAudio(it) } } setFragmentResultListener(MultiAudioPicker.MULTI_AUDIO_REQUEST_KEY) { _, bundle -> - val loadedModel = - bundle.getParcelableArrayList(MultiAudioPicker.ON_MULTI_AUDIO_PICK_KEY) + val loadedModel = bundle.getParcelableArrayList(MultiAudioPicker.ON_MULTI_AUDIO_PICK_KEY) loadedModel?.let { doSomethingWithAudioList(it) } } diff --git a/app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt b/app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt index fed9cd4..310099d 100644 --- a/app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt +++ b/app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt @@ -15,6 +15,8 @@ import com.bumptech.glide.Glide import com.crazylegend.audiopicker.audios.AudioModel import com.crazylegend.audiopicker.pickers.MultiAudioPicker import com.crazylegend.audiopicker.pickers.SingleAudioPicker +import com.crazylegend.core.dto.PickerConfig +import com.crazylegend.core.modifiers.SizeTextModifier import com.crazylegend.core.modifiers.TitleTextModifier import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.imagepicker.images.ImageModel @@ -33,49 +35,49 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { private var clickedID = R.id.singleImageBottomSheetPick private val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - when (clickedID) { - //images - R.id.singleImageBottomSheetPick -> { - showSingleImageBottomSheetPicker() - } + registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + when (clickedID) { + //images + R.id.singleImageBottomSheetPick -> { + showSingleImageBottomSheetPicker() + } - R.id.imageBottomSheetMultiPick -> { - showImageMultiBottomSheetPicker() - } + R.id.imageBottomSheetMultiPick -> { + showImageMultiBottomSheetPicker() + } - //videos - R.id.singleVideoBottomSheetPick -> { - showSingleVideoBottomSheetPicker() - } + //videos + R.id.singleVideoBottomSheetPick -> { + showSingleVideoBottomSheetPicker() + } - R.id.videoBottomSheetMultiPick -> { - showVideoMultiBottomSheetPicker() - } + R.id.videoBottomSheetMultiPick -> { + showVideoMultiBottomSheetPicker() + } - //audios - R.id.singleAudioBottomSheetPick -> { - showSingleAudioBottomSheetPicker() - } + //audios + R.id.singleAudioBottomSheetPick -> { + showSingleAudioBottomSheetPicker() + } - R.id.audioBottomSheetMultiPick -> { - showAudioMultiBottomSheetPicker() - } + R.id.audioBottomSheetMultiPick -> { + showAudioMultiBottomSheetPicker() + } - //fragment result - R.id.launchFragmentResult -> { - val dialog = FragmentResult() - dialog.show(supportFragmentManager, FragmentResult::class.java.name) + //fragment result + R.id.launchFragmentResult -> { + val dialog = FragmentResult() + dialog.show(supportFragmentManager, FragmentResult::class.java.name) + } } + } else { + Log.e("PERMISSION", "NOT ALLOWED!") } - } else { - Log.e("PERMISSION", "NOT ALLOWED!") } - } //audios private fun showSingleAudioBottomSheetPicker() { @@ -107,35 +109,35 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { textPadding = 10 // use dp or sp this is only for demonstration purposes } setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor( - this@MainActivity, R.color.colorPrimaryDark + this@MainActivity, R.color.colorPrimaryDark ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.BOTTOM_LEFT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple songs" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_album_second - }) + gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.BOTTOM_LEFT, + titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple songs" + }, + selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, + unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, + viewHolderPlaceholderModifications = { + resID = R.drawable.ic_album_second + }) }, ::doSomethingWithAudioList) } private fun loadAudio(audioModel: AudioModel) { Glide.with(this).load(audioModel.loadThumbnail(contentResolver)).error(R.drawable.ic_album) - .into(binding.audio) + .into(binding.audio) binding.audioTitle.text = audioModel.displayName Log.d("AUDIO_PICKED ${audioModel.thumbnail?.isRecycled}", audioModel.toString()) } @@ -149,31 +151,39 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { //videos private fun showVideoMultiBottomSheetPicker() { - MultiVideoPicker.showPicker(this, extensions = arrayOf(), { + MultiVideoPicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor( - this@MainActivity, R.color.colorPrimaryDark + this@MainActivity, R.color.colorPrimaryDark ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_CENTER - textStyle = TitleTextModifier.TextStyle.ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple videos" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_close - }) + gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT, + titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_CENTER + textStyle = TitleTextModifier.TextStyle.ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple videos" + }, + selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, + unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, + viewHolderPlaceholderModifications = { + resID = R.drawable.ic_close + }, + sizeTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_CENTER + textStyle = SizeTextModifier.TextStyle.BOLD + margin = 22 // use dp or sp this is only for demonstration purposes + textPadding = 8 // use dp or sp this is only for demonstration purposes + textSize = 10f // use sp this is only for demonstration purposes + } + ) }, ::doSomethingWithVideoList) } @@ -181,7 +191,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { private fun showSingleVideoBottomSheetPicker() { //SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo) - SingleVideoPicker.showPicker(this, extensions = arrayOf(), { + SingleVideoPicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { setupBaseModifier(loadingIndicatorColor = R.color.minusColor, titleTextModifications = { textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START textStyle = TitleTextModifier.TextStyle.ITALIC @@ -192,7 +202,16 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { textString = "Pick a video" }, placeHolderModifications = { resID = R.drawable.ic_image - }) + }, sizeTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = SizeTextModifier.TextStyle.NORMAL + margin = 22 // use dp or sp this is only for demonstration purposes + textColor = Color.BLACK + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 12f // use sp this is only for demonstration purposes + backgroundDrawable = R.drawable.rounded_bg_abstract_dialog + } + ) }, ::loadVideo) } @@ -211,31 +230,40 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { //images private fun showImageMultiBottomSheetPicker() { - MultiImagePicker.showPicker(this, extensions = arrayOf(), { + MultiImagePicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor( - this@MainActivity, R.color.colorPrimaryDark + this@MainActivity, R.color.colorPrimaryDark ), - gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_LEFT, - titleModifications = { - textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START - textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC - textColor = Color.BLACK - marginBottom = 30 // use dp or sp this is only for demonstration purposes - textPadding = 5 // use dp or sp this is only for demonstration purposes - textSize = 30f // use sp this is only for demonstration purposes - textString = "Pick multiple images" - }, - selectIconModifications = { - resID = R.drawable.ic_checked - tint = Color.BLACK - }, - unSelectIconModifications = { - resID = R.drawable.ic_unchecked - tint = Color.BLACK - }, - viewHolderPlaceholderModifications = { - resID = R.drawable.ic_image - }) + gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_LEFT, + titleModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC + textColor = Color.BLACK + marginBottom = 30 // use dp or sp this is only for demonstration purposes + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 30f // use sp this is only for demonstration purposes + textString = "Pick multiple images" + }, + selectIconModifications = { + resID = R.drawable.ic_checked + tint = Color.BLACK + }, + unSelectIconModifications = { + resID = R.drawable.ic_unchecked + tint = Color.BLACK + }, + viewHolderPlaceholderModifications = { + resID = R.drawable.ic_image + }, + sizeTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = SizeTextModifier.TextStyle.NORMAL + margin = 22 // use dp or sp this is only for demonstration purposes + textColor = Color.GREEN + textPadding = 6 // use dp or sp this is only for demonstration purposes + textSize = 12f // use sp this is only for demonstration purposes + } + ) }) { list -> doSomethingWithImageList(list) } @@ -243,9 +271,9 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { private fun showSingleImageBottomSheetPicker() { - SingleImagePicker.showPicker(this, extensions = arrayOf(), { + SingleImagePicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), { loadingIndicatorTint = - ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark) + ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark) titleTextModifier.apply { textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START textStyle = TitleTextModifier.TextStyle.BOLD_ITALIC @@ -266,6 +294,15 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { viewHolderPlaceholderModifier.apply { resID = R.drawable.ic_image } + sizeTextModifier.apply { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = SizeTextModifier.TextStyle.NORMAL + margin = 22 // use dp or sp this is only for demonstration purposes + textColor = Color.BLACK + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 12f // use sp this is only for demonstration purposes + backgroundDrawable = R.drawable.rounded_bg_abstract_dialog + } }, ::loadImage) } diff --git a/core/src/main/java/com/crazylegend/core/Extensions.kt b/core/src/main/java/com/crazylegend/core/Extensions.kt index 6d82fe8..838deff 100644 --- a/core/src/main/java/com/crazylegend/core/Extensions.kt +++ b/core/src/main/java/com/crazylegend/core/Extensions.kt @@ -19,6 +19,7 @@ import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier +import kotlin.math.pow /** * Created by crazy on 5/8/20 to long live and prosper ! @@ -141,4 +142,17 @@ internal var Float.dp: Float val metrics = Resources.getSystem().displayMetrics return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, metrics) } - set(_) {} \ No newline at end of file + set(_) {} + +internal fun Int.bytesToFormattedString(): String { + return when { + this >= 1024.0.pow(3.0) -> { + val gigabytes = this / 1024.0.pow(3.0) + "%.2f GB".format(gigabytes) + } + else -> { + val megabytes = this / 1024.0.pow(2.0) + "%.2f MB".format(megabytes) + } + } +} \ No newline at end of file diff --git a/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectAdapter.kt b/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectAdapter.kt index 60d7b29..3e14be8 100644 --- a/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectAdapter.kt +++ b/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectAdapter.kt @@ -12,10 +12,9 @@ import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier /** * Created by crazy on 5/8/20 to long live and prosper ! */ -class MultiSelectAdapter(private val modifier: BaseMultiPickerModifier?) : +class MultiSelectAdapter(private val modifier: BaseMultiPickerModifier?, private val showFileSize: Boolean) : ListAdapter(SingleDiffUtil()) { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MultiSelectViewHolder { val holder = MultiSelectViewHolder(ItemviewImageBinding.inflate(parent.inflater, parent, false), modifier) holder.itemView.setOnClickListener { @@ -29,7 +28,7 @@ class MultiSelectAdapter(private val modifier: BaseMultiPickerModifier?) : override fun onBindViewHolder(holder: MultiSelectViewHolder, position: Int) { val item = getItem(position) - holder.bind(item) + holder.bind(item, showFileSize) holder.itemView.tag = item } diff --git a/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectViewHolder.kt b/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectViewHolder.kt index 7a6bd55..b63adc4 100644 --- a/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectViewHolder.kt +++ b/core/src/main/java/com/crazylegend/core/adapters/multi/MultiSelectViewHolder.kt @@ -1,6 +1,8 @@ package com.crazylegend.core.adapters.multi +import androidx.core.view.isVisible import com.crazylegend.core.adapters.BaseViewHolder +import com.crazylegend.core.bytesToFormattedString import com.crazylegend.core.databinding.ItemviewImageBinding import com.crazylegend.core.dto.BaseCursorModel import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier @@ -24,8 +26,17 @@ class MultiSelectViewHolder( modifier?.applyGravity(binding.selection) } - fun bind(cursorModel: BaseCursorModel) { + fun bind(cursorModel: BaseCursorModel, showFileSize: Boolean) { loadImage(binding.image, cursorModel.contentUri, viewHolderPlaceholderModifier) + if (showFileSize) { + modifier?.sizeTextModifier?.applyTextParams(binding.size) + modifier?.sizeTextModifier?.applyTextParamsConstraint(binding.size) + binding.size.isVisible = false + cursorModel.size?.let { size -> + binding.size.isVisible = size > 0 + binding.size.text = size.bytesToFormattedString() + } + } if (cursorModel.isSelected) { setupSelectedImage(binding.selection, selectIconModifier) } else { @@ -34,4 +45,4 @@ class MultiSelectViewHolder( } -} \ No newline at end of file +} diff --git a/core/src/main/java/com/crazylegend/core/adapters/single/SingleAdapter.kt b/core/src/main/java/com/crazylegend/core/adapters/single/SingleAdapter.kt index 116e837..3d53f11 100644 --- a/core/src/main/java/com/crazylegend/core/adapters/single/SingleAdapter.kt +++ b/core/src/main/java/com/crazylegend/core/adapters/single/SingleAdapter.kt @@ -5,6 +5,7 @@ import androidx.recyclerview.widget.ListAdapter import com.crazylegend.core.databinding.ItemviewImageBinding import com.crazylegend.core.dto.BaseCursorModel import com.crazylegend.core.inflater +import com.crazylegend.core.modifiers.SizeTextModifier import com.crazylegend.core.modifiers.single.ImageModifier @@ -12,14 +13,17 @@ import com.crazylegend.core.modifiers.single.ImageModifier * Created by crazy on 5/8/20 to long live and prosper ! */ -open class SingleAdapter(private val viewHolderPlaceholderModifier: ImageModifier?, +open class SingleAdapter(private val showFileSize: Boolean, + private val viewHolderPlaceholderModifier: ImageModifier?, + private val sizeTextModifier: SizeTextModifier?, private val onClick: (BaseCursorModel) -> Unit) : ListAdapter(SingleDiffUtil()) { + override fun onCreateViewHolder(parent: ViewGroup, viewBaseCursorModelype: Int) = - SingleViewHolder(ItemviewImageBinding.inflate(parent.inflater, parent, false), viewHolderPlaceholderModifier, onClick) + SingleViewHolder(ItemviewImageBinding.inflate(parent.inflater, parent, false), viewHolderPlaceholderModifier, sizeTextModifier, onClick) override fun onBindViewHolder(holder: SingleViewHolder, position: Int) { val item = getItem(position) - holder.bind(item) + holder.bind(item, showFileSize) holder.itemView.tag = item } diff --git a/core/src/main/java/com/crazylegend/core/adapters/single/SingleViewHolder.kt b/core/src/main/java/com/crazylegend/core/adapters/single/SingleViewHolder.kt index 28459e4..b521cdf 100644 --- a/core/src/main/java/com/crazylegend/core/adapters/single/SingleViewHolder.kt +++ b/core/src/main/java/com/crazylegend/core/adapters/single/SingleViewHolder.kt @@ -1,9 +1,12 @@ package com.crazylegend.core.adapters.single +import androidx.core.view.isVisible import com.crazylegend.core.adapters.BaseViewHolder +import com.crazylegend.core.bytesToFormattedString import com.crazylegend.core.databinding.ItemviewImageBinding import com.crazylegend.core.dto.BaseCursorModel import com.crazylegend.core.gone +import com.crazylegend.core.modifiers.SizeTextModifier import com.crazylegend.core.modifiers.single.ImageModifier @@ -12,11 +15,20 @@ import com.crazylegend.core.modifiers.single.ImageModifier */ class SingleViewHolder(private val binding: ItemviewImageBinding, - private val viewHolderPlaceholderModifier: ImageModifier?, onClick: (BaseCursorModel) -> Unit) : + private val viewHolderPlaceholderModifier: ImageModifier?, private val sizeTextModifier: SizeTextModifier?, onClick: (BaseCursorModel) -> Unit) : BaseViewHolder(binding) { - fun bind(item: BaseCursorModel) { + fun bind(item: BaseCursorModel, showFileSize: Boolean) { loadImage(binding.image, item.contentUri, viewHolderPlaceholderModifier) + if (showFileSize) { + sizeTextModifier?.applyTextParams(binding.size) + sizeTextModifier?.applyTextParamsConstraint(binding.size) + binding.size.isVisible = false + item.size?.let { size -> + binding.size.isVisible = size > 0 + binding.size.text = size.bytesToFormattedString() + } + } } diff --git a/core/src/main/java/com/crazylegend/core/dto/PickerConfig.kt b/core/src/main/java/com/crazylegend/core/dto/PickerConfig.kt new file mode 100644 index 0000000..c87a378 --- /dev/null +++ b/core/src/main/java/com/crazylegend/core/dto/PickerConfig.kt @@ -0,0 +1,3 @@ +package com.crazylegend.core.dto + +data class PickerConfig(val showFileSize: Boolean = false) \ No newline at end of file diff --git a/core/src/main/java/com/crazylegend/core/modifiers/SizeTextModifier.kt b/core/src/main/java/com/crazylegend/core/modifiers/SizeTextModifier.kt new file mode 100644 index 0000000..9e1a087 --- /dev/null +++ b/core/src/main/java/com/crazylegend/core/modifiers/SizeTextModifier.kt @@ -0,0 +1,130 @@ +package com.crazylegend.core.modifiers + +import android.content.res.ColorStateList +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Typeface +import android.os.Parcelable +import android.widget.TextView +import androidx.appcompat.widget.AppCompatTextView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.ContextCompat +import androidx.core.view.setMargins +import androidx.core.view.setPadding +import androidx.core.view.updateLayoutParams +import kotlinx.parcelize.Parcelize + + +/** + * Created by crazy on 5/11/20 to long live and prosper ! + */ + + +@Parcelize +data class SizeTextModifier( + var textColor: Int? = null, + var textPadding: Int? = null, + var textSize: Float? = null, + var startMargin: Int? = null, + var endMargin: Int? = null, + var marginTop: Int? = null, + var marginBottom: Int? = null, + var margin: Int? = null, + var backgroundColor: Int? = null, + var backgroundDrawable: Int? = null, + var textStyle: TextStyle = TextStyle.NORMAL, + var textAlignment: Int = TextView.TEXT_ALIGNMENT_VIEW_START +) : Parcelable { + + + private val allSizeMarginCondition get() = margin != null + + enum class TextStyle { + BOLD, UNDERLINED, ITALIC, BOLD_ITALIC, NORMAL + } + + private fun updateMargins(textView: AppCompatTextView) { + textView.updateLayoutParams { + startMargin?.let { marginStart = it } + endMargin?.let { marginEnd = it } + marginTop?.let { topMargin = it } + marginBottom?.let { bottomMargin = it } + } + } + + private fun updateMarginsConstraint(textView: AppCompatTextView) { + textView.updateLayoutParams { + startMargin?.let { marginStart = it } + endMargin?.let { marginEnd = it } + marginTop?.let { topMargin = it } + marginBottom?.let { bottomMargin = it } + } + } + + private fun updateAllMargins(textView: AppCompatTextView) { + textView.updateLayoutParams { + margin?.let { setMargins(it) } + } + } + + private fun updateAllMarginsConstraint(textView: AppCompatTextView) { + textView.updateLayoutParams { + margin?.let { setMargins(it) } + } + } + + fun applyTextParams(text: AppCompatTextView) { + textSize?.let { text.textSize = it } + textPadding?.let { text.setPadding(it) } + textColor?.let { text.setTextColor(it) } + text.textAlignment = textAlignment + backgroundColor?.let { text.setBackgroundColor(it) } + applyTextStyle(text) + if (allSizeMarginCondition) { + updateAllMargins(text) + } else { + updateMargins(text) + } + } + + fun applyTextParamsConstraint(text: AppCompatTextView) { + textSize?.let { text.textSize = it } + textPadding?.let { text.setPadding(it) } + textColor?.let { text.setTextColor(it) } + text.textAlignment = textAlignment + backgroundDrawable?.let { text.background = ContextCompat.getDrawable(text.context, it) } + ?: run { + text.backgroundTintList = ColorStateList.valueOf(Color.BLACK) + } + applyTextStyle(text) + if (allSizeMarginCondition) { + updateAllMarginsConstraint(text) + } else { + updateMarginsConstraint(text) + } + } + + private fun applyTextStyle(text: AppCompatTextView) { + when (textStyle) { + TextStyle.BOLD -> { + text.setTypeface(text.typeface, Typeface.BOLD) + } + + TextStyle.UNDERLINED -> { + text.paintFlags = text.paintFlags or Paint.UNDERLINE_TEXT_FLAG + } + + TextStyle.ITALIC -> { + text.setTypeface(text.typeface, Typeface.ITALIC) + } + + TextStyle.BOLD_ITALIC -> { + text.setTypeface(text.typeface, Typeface.BOLD_ITALIC) + } + + else -> { + + } + } + } +} \ No newline at end of file diff --git a/core/src/main/java/com/crazylegend/core/modifiers/base/BaseMultiPickerModifier.kt b/core/src/main/java/com/crazylegend/core/modifiers/base/BaseMultiPickerModifier.kt index 204528d..534c27a 100644 --- a/core/src/main/java/com/crazylegend/core/modifiers/base/BaseMultiPickerModifier.kt +++ b/core/src/main/java/com/crazylegend/core/modifiers/base/BaseMultiPickerModifier.kt @@ -7,11 +7,16 @@ import androidx.core.view.marginBottom import androidx.core.view.marginLeft import androidx.core.view.marginRight import androidx.core.view.marginTop -import com.crazylegend.core.* +import com.crazylegend.core.bottom +import com.crazylegend.core.constrainBottomToTopOf +import com.crazylegend.core.left +import com.crazylegend.core.modifiers.SizeTextModifier import com.crazylegend.core.modifiers.TitleTextModifier import com.crazylegend.core.modifiers.multi.DoneButtonModifier import com.crazylegend.core.modifiers.multi.SelectIconModifier import com.crazylegend.core.modifiers.single.ImageModifier +import com.crazylegend.core.right +import com.crazylegend.core.top import kotlinx.parcelize.Parcelize @@ -28,7 +33,8 @@ open class BaseMultiPickerModifier( open var indicatorsGravity: Gravity = Gravity.BOTTOM_RIGHT, open val viewHolderPlaceholderModifier: ImageModifier = ImageModifier(), open val noContentTextModifier: TitleTextModifier = TitleTextModifier(), - open var loadingIndicatorTint: Int? = null + open var loadingIndicatorTint: Int? = null, + open val sizeTextModifier: SizeTextModifier = SizeTextModifier(), ) : Parcelable { enum class Gravity { @@ -42,7 +48,8 @@ open class BaseMultiPickerModifier( unSelectIconModifications: SelectIconModifier.() -> Unit = {}, viewHolderPlaceholderModifications: ImageModifier.() -> Unit = {}, gravityForSelectAndUnSelectIndicators: Gravity = Gravity.BOTTOM_RIGHT, - tintForLoadingProgressBar: Int? = null + tintForLoadingProgressBar: Int? = null, + sizeTextModifications: SizeTextModifier.() -> Unit = {}, ) { doneButtonModifier.doneButtonModifications() titleTextModifier.titleModifications() @@ -51,6 +58,7 @@ open class BaseMultiPickerModifier( viewHolderPlaceholderModifier.viewHolderPlaceholderModifications() indicatorsGravity = gravityForSelectAndUnSelectIndicators loadingIndicatorTint = tintForLoadingProgressBar + sizeTextModifier.sizeTextModifications() } fun applyGravity(imageView: AppCompatImageView) { @@ -59,14 +67,17 @@ open class BaseMultiPickerModifier( imageView.top(imageView.marginTop) imageView.left(imageView.marginLeft) } + Gravity.TOP_RIGHT -> { imageView.top(imageView.marginTop) imageView.right(imageView.marginRight) } + Gravity.BOTTOM_LEFT -> { imageView.bottom(imageView.marginBottom) imageView.left(imageView.marginLeft) } + Gravity.BOTTOM_RIGHT -> { imageView.bottom(imageView.marginBottom) imageView.right(imageView.marginRight) @@ -80,14 +91,17 @@ open class BaseMultiPickerModifier( imageView.top(imageView.marginTop) imageView.left(imageView.marginLeft) } + Gravity.TOP_RIGHT -> { imageView.top(imageView.marginTop) imageView.right(imageView.marginRight) } + Gravity.BOTTOM_LEFT -> { imageView.constrainBottomToTopOf(view, imageView.marginBottom) imageView.left(imageView.marginLeft) } + Gravity.BOTTOM_RIGHT -> { imageView.constrainBottomToTopOf(view, imageView.marginBottom) imageView.right(imageView.marginRight) diff --git a/core/src/main/java/com/crazylegend/core/modifiers/base/BaseSinglePickerModifier.kt b/core/src/main/java/com/crazylegend/core/modifiers/base/BaseSinglePickerModifier.kt index 5a4d4c8..4ad2e3b 100644 --- a/core/src/main/java/com/crazylegend/core/modifiers/base/BaseSinglePickerModifier.kt +++ b/core/src/main/java/com/crazylegend/core/modifiers/base/BaseSinglePickerModifier.kt @@ -1,6 +1,7 @@ package com.crazylegend.core.modifiers.base import android.os.Parcelable +import com.crazylegend.core.modifiers.SizeTextModifier import com.crazylegend.core.modifiers.TitleTextModifier import com.crazylegend.core.modifiers.single.ImageModifier import kotlinx.parcelize.Parcelize @@ -15,17 +16,21 @@ open class BaseSinglePickerModifier( open val titleTextModifier: TitleTextModifier = TitleTextModifier(), open val viewHolderPlaceholderModifier: ImageModifier = ImageModifier(), open val noContentTextModifier: TitleTextModifier = TitleTextModifier(), - open var loadingIndicatorTint: Int? = null + open var loadingIndicatorTint: Int? = null, + open val sizeTextModifier: SizeTextModifier = SizeTextModifier(), ) : Parcelable { inline fun setupBaseModifier( loadingIndicatorColor: Int? = null, titleTextModifications: TitleTextModifier.() -> Unit = {}, placeHolderModifications: ImageModifier.() -> Unit = {}, - noContentTextModifications: TitleTextModifier.() -> Unit = {}) { + noContentTextModifications: TitleTextModifier.() -> Unit = {}, + sizeTextModifications: SizeTextModifier.() -> Unit = {}, + ) { titleTextModifier.titleTextModifications() loadingIndicatorTint = loadingIndicatorColor viewHolderPlaceholderModifier.placeHolderModifications() noContentTextModifier.noContentTextModifications() + sizeTextModifier.sizeTextModifications() } } \ No newline at end of file diff --git a/core/src/main/res/layout/itemview_image.xml b/core/src/main/res/layout/itemview_image.xml index 0670f0a..3e7e824 100644 --- a/core/src/main/res/layout/itemview_image.xml +++ b/core/src/main/res/layout/itemview_image.xml @@ -2,16 +2,16 @@ @@ -23,4 +23,20 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + \ No newline at end of file diff --git a/core/src/main/res/values/colors.xml b/core/src/main/res/values/colors.xml index 9aab242..febd8a5 100644 --- a/core/src/main/res/values/colors.xml +++ b/core/src/main/res/values/colors.xml @@ -1,4 +1,6 @@ #BDBDBD + #FFFFFF + #000000 \ No newline at end of file diff --git a/extensions/src/main/java/com/crazylegend/extensions/Extensions.kt b/extensions/src/main/java/com/crazylegend/extensions/Extensions.kt index 218480f..27370bc 100644 --- a/extensions/src/main/java/com/crazylegend/extensions/Extensions.kt +++ b/extensions/src/main/java/com/crazylegend/extensions/Extensions.kt @@ -62,4 +62,8 @@ inline fun ContentResolver.registerObserver( } registerContentObserver(uri, true, contentObserver) return contentObserver -} \ No newline at end of file +} + +fun Int.bytesToMegabytes(): Double { + return this / (1024.0 * 1024.0) +} diff --git a/imagepicker/README.md b/imagepicker/README.md index f69d92c..1f498b6 100644 --- a/imagepicker/README.md +++ b/imagepicker/README.md @@ -27,7 +27,7 @@ dependencies { //customized - SingleImagePicker.showPicker(this, extensions = arrayOf(),{ + SingleImagePicker.showPicker(this, extensions = arrayOf(),config = Config(showFileSize = true),{ loadingIndicatorTint = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark) titleTextModifier.apply { textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START @@ -49,6 +49,15 @@ dependencies { viewHolderPlaceholderModifier.apply { resID = R.drawable.ic_image } + sizeTextModifier.apply { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = SizeTextModifier.TextStyle.NORMAL + margin = 22 // use dp or sp this is only for demonstration purposes + textColor = Color.BLACK + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 12f // use sp this is only for demonstration purposes + backgroundDrawable = R.drawable.rounded_bg_abstract_dialog + } }, ::loadImage) // You can filter files by passing extensions like extensions = arrayOf("png","jpeg") ``` @@ -59,7 +68,7 @@ dependencies { MultiImagePicker.showPicker(this){ doSomethingWithImageList(it) } //customized - MultiImagePicker.showPicker(this, extensions = arrayOf(), { + MultiImagePicker.showPicker(this, extensions = arrayOf(), config = Config(showFileSize = true),{ setupBaseMultiPicker( tintForLoadingProgressBar = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark), gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_LEFT, diff --git a/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/multi/MultiImagePickerBottomSheetDialog.kt b/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/multi/MultiImagePickerBottomSheetDialog.kt index 63ce38c..d4898f4 100644 --- a/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/multi/MultiImagePickerBottomSheetDialog.kt +++ b/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/multi/MultiImagePickerBottomSheetDialog.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.observe import com.crazylegend.core.abstracts.AbstractBottomSheetDialogFragment import com.crazylegend.core.adapters.multi.MultiSelectAdapter import com.crazylegend.core.databinding.FragmentImagesGalleryLayoutMultiBinding +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.extensions.viewBinding @@ -30,9 +31,10 @@ import com.google.android.material.button.MaterialButton * Created by crazy on 5/8/20 to long live and prosper ! */ internal class MultiImagePickerBottomSheetDialog : AbstractBottomSheetDialogFragment(), - MultiPickerContracts { + MultiPickerContracts { var extensions: Array? = arrayOf() + var pickerConfig: PickerConfig = PickerConfig() override val layout: Int get() = super.layout @@ -43,17 +45,17 @@ internal class MultiImagePickerBottomSheetDialog : AbstractBottomSheetDialogFrag get() = arguments?.getParcelable(modifierTag) override val multiSelectAdapter by lazy { - MultiSelectAdapter(modifier) + MultiSelectAdapter(modifier, pickerConfig.showFileSize) } override val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - imagesVM.loadImages(extensions = extensions) - } else { - Log.e(errorTag, "PERMISSION DENIED") - dismissAllowingStateLoss() + registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + imagesVM.loadImages(extensions = extensions) + } else { + Log.e(errorTag, "PERMISSION DENIED") + dismissAllowingStateLoss() + } } - } @Suppress("UNCHECKED_CAST") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -63,24 +65,23 @@ internal class MultiImagePickerBottomSheetDialog : AbstractBottomSheetDialogFrag } else { askForStoragePermission.launch(Manifest.permission.READ_MEDIA_IMAGES) } - setupUIForMultiPicker( - binding.gallery, - multiSelectAdapter, - binding.doneButton, - binding.title, - binding.loadingIndicator, - modifier?.loadingIndicatorTint, - ::applyDoneButtonModifications, - ::applyTitleModifications + binding.gallery, + multiSelectAdapter, + binding.doneButton, + binding.title, + binding.loadingIndicator, + modifier?.loadingIndicatorTint, + ::applyDoneButtonModifications, + ::applyTitleModifications ) imagesVM.images.observe(viewLifecycleOwner) { setupList( - multiSelectAdapter, - it, - binding.noContentText, - modifier?.noContentTextModifier + multiSelectAdapter, + it, + binding.noContentText, + modifier?.noContentTextModifier ) } handleUIIndicator(imagesVM.loadingIndicator, binding.loadingIndicator) @@ -88,11 +89,11 @@ internal class MultiImagePickerBottomSheetDialog : AbstractBottomSheetDialogFrag binding.doneButton.setOnClickListener { val imagesList = - multiSelectAdapter.currentList.filter { it.isSelected } as? List - ?: emptyList() + multiSelectAdapter.currentList.filter { it.isSelected } as? List + ?: emptyList() setFragmentResult( - MultiImagePicker.MULTI_IMAGE_REQUEST_KEY, - bundleOf(MultiImagePicker.ON_MULTI_IMAGE_PICK_KEY to imagesList) + MultiImagePicker.MULTI_IMAGE_REQUEST_KEY, + bundleOf(MultiImagePicker.ON_MULTI_IMAGE_PICK_KEY to imagesList) ) onImagesPicked?.onImagesPicked(imagesList) dismissAllowingStateLoss() diff --git a/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/single/SingleImagePickerBottomSheetDialog.kt b/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/single/SingleImagePickerBottomSheetDialog.kt index 77180af..c23686c 100644 --- a/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/single/SingleImagePickerBottomSheetDialog.kt +++ b/imagepicker/src/main/java/com/crazylegend/imagepicker/dialogs/single/SingleImagePickerBottomSheetDialog.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.observe import com.crazylegend.core.abstracts.AbstractBottomSheetDialogFragment import com.crazylegend.core.adapters.single.SingleAdapter import com.crazylegend.core.databinding.FragmentImagesGalleryLayoutBinding +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier import com.crazylegend.extensions.viewBinding import com.crazylegend.imagepicker.contracts.SinglePickerContracts @@ -28,7 +29,7 @@ import com.crazylegend.imagepicker.pickers.SingleImagePicker * Created by crazy on 5/8/20 to long live and prosper ! */ internal class SingleImagePickerBottomSheetDialog : AbstractBottomSheetDialogFragment(), - SinglePickerContracts { + SinglePickerContracts { override val layout: Int get() = super.layout @@ -38,13 +39,14 @@ internal class SingleImagePickerBottomSheetDialog : AbstractBottomSheetDialogFra override val modifier: BaseSinglePickerModifier? get() = arguments?.getParcelable(modifierTag) var extensions: Array? = arrayOf() + var pickerConfig: PickerConfig = PickerConfig() override val singleAdapter by lazy { - SingleAdapter(modifier?.viewHolderPlaceholderModifier) { + SingleAdapter(pickerConfig.showFileSize, modifier?.viewHolderPlaceholderModifier, modifier?.sizeTextModifier) { val image = it as ImageModel setFragmentResult( - SingleImagePicker.SINGLE_IMAGE_REQUEST_KEY, - bundleOf(SingleImagePicker.ON_SINGLE_IMAGE_PICK_KEY to image) + SingleImagePicker.SINGLE_IMAGE_REQUEST_KEY, + bundleOf(SingleImagePicker.ON_SINGLE_IMAGE_PICK_KEY to image) ) onImagePicked?.forImage(image) dismissAllowingStateLoss() @@ -52,14 +54,14 @@ internal class SingleImagePickerBottomSheetDialog : AbstractBottomSheetDialogFra } override val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - imagesVM.loadImages(extensions = extensions) - } else { - Log.e(errorTag, "PERMISSION DENIED") - dismissAllowingStateLoss() + registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + imagesVM.loadImages(extensions = extensions) + } else { + Log.e(errorTag, "PERMISSION DENIED") + dismissAllowingStateLoss() + } } - } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -70,12 +72,12 @@ internal class SingleImagePickerBottomSheetDialog : AbstractBottomSheetDialogFra askForStoragePermission.launch(Manifest.permission.READ_MEDIA_IMAGES) } setupUIForSinglePicker( - binding.gallery, - singleAdapter, - binding.title, - binding.loadingIndicator, - modifier?.loadingIndicatorTint, - ::applyTitleModifications + binding.gallery, + singleAdapter, + binding.title, + binding.loadingIndicator, + modifier?.loadingIndicatorTint, + ::applyTitleModifications ) imagesVM.images.observe(viewLifecycleOwner) { setupList(singleAdapter, it, binding.noContentText, modifier?.noContentTextModifier) diff --git a/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/MultiImagePicker.kt b/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/MultiImagePicker.kt index b56c8da..acd473f 100644 --- a/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/MultiImagePicker.kt +++ b/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/MultiImagePicker.kt @@ -3,6 +3,7 @@ package com.crazylegend.imagepicker.pickers import android.content.Context import android.util.Log import androidx.fragment.app.FragmentManager +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.core.setupModifier import com.crazylegend.extensions.setupManager @@ -38,14 +39,16 @@ object MultiImagePicker { fun showPicker( - context: Context, extensions: Array? = arrayOf(), - multiImagePickerModifier: BaseMultiPickerModifier.() -> Unit = {}, - imagesList: (list: List) -> Unit = {} + context: Context, extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + multiImagePickerModifier: BaseMultiPickerModifier.() -> Unit = {}, + imagesList: (list: List) -> Unit = {} ) { val manager = context.setupManager() val modifier = setupModifier(multiImagePickerModifier) with(MultiImagePickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onImagesPicked = onImagesDSL(imagesList) show(manager, MULTI_PICKER_BOTTOM_SHEET) @@ -53,14 +56,16 @@ object MultiImagePicker { } fun showPicker( - fragmentManager: FragmentManager, - extensions: Array? = arrayOf(), - multiImagePickerModifier: BaseMultiPickerModifier.() -> Unit = {}, - imagesList: (list: List) -> Unit = {} + fragmentManager: FragmentManager, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + multiImagePickerModifier: BaseMultiPickerModifier.() -> Unit = {}, + imagesList: (list: List) -> Unit = {} ) { val modifier = setupModifier(multiImagePickerModifier) with(MultiImagePickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onImagesPicked = onImagesDSL(imagesList) show(fragmentManager, MULTI_PICKER_BOTTOM_SHEET) diff --git a/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/SingleImagePicker.kt b/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/SingleImagePicker.kt index 289fb1f..a2cc7e2 100644 --- a/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/SingleImagePicker.kt +++ b/imagepicker/src/main/java/com/crazylegend/imagepicker/pickers/SingleImagePicker.kt @@ -3,6 +3,7 @@ package com.crazylegend.imagepicker.pickers import android.content.Context import android.util.Log import androidx.fragment.app.FragmentManager +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier import com.crazylegend.core.setupModifier import com.crazylegend.extensions.setupManager @@ -36,15 +37,17 @@ object SingleImagePicker { } fun showPicker( - context: Context, - extensions: Array? = arrayOf(), - pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, - onPickedImage: (image: ImageModel) -> Unit = {} + context: Context, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, + onPickedImage: (image: ImageModel) -> Unit = {} ) { val modifier = setupModifier(pickerModifier) val manager = context.setupManager() with(SingleImagePickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onImagePicked = onImageDSL(onPickedImage) show(manager, SINGLE_PICKER_BOTTOM_SHEET) @@ -52,14 +55,16 @@ object SingleImagePicker { } fun showPicker( - fragmentManager: FragmentManager, - extensions: Array? = arrayOf(), - pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, - onPickedImage: (image: ImageModel) -> Unit = {} + fragmentManager: FragmentManager, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, + onPickedImage: (image: ImageModel) -> Unit = {} ) { val modifier = setupModifier(pickerModifier) with(SingleImagePickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onImagePicked = onImageDSL(onPickedImage) show(fragmentManager, SINGLE_PICKER_BOTTOM_SHEET) diff --git a/videopicker/README.md b/videopicker/README.md index 62c9670..11f6cc4 100644 --- a/videopicker/README.md +++ b/videopicker/README.md @@ -19,11 +19,13 @@ dependencies { ``` 3. How to use single picker and check out [how to customize single video picker](https://github.com/FunkyMuse/MediaPicker/wiki/Single--image-video-picker-customization) ```kotlin +import java.awt.Color + //simple usage without customization SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo) //customized - SingleVideoPicker.showPicker(this, extensions = arrayOf(),{ + SingleVideoPicker.showPicker(this, extensions = arrayOf(),config = Config(showFileSize = true),{ setupBaseModifier( loadingIndicatorColor = R.color.minusColor, titleTextModifications = { @@ -51,7 +53,7 @@ dependencies { MultiVideoPicker.showPicker(this) { loadVideos(it) } //customized - MultiVideoPicker.showPicker(this, extensions = arrayOf(),{ + MultiVideoPicker.showPicker(this, extensions = arrayOf(),config = Config(showFileSize = false),{ setupBaseMultiPicker( tintForLoadingProgressBar = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark), gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT, @@ -74,6 +76,15 @@ dependencies { }, viewHolderPlaceholderModifications = { resID = R.drawable.ic_close + }, + sizeTextModifications = { + textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START + textStyle = SizeTextModifier.TextStyle.NORMAL + margin = 22 // use dp or sp this is only for demonstration purposes + textColor = Color.BLACK + textPadding = 5 // use dp or sp this is only for demonstration purposes + textSize = 12f // use sp this is only for demonstration purposes + backgroundDrawable = R.drawable.rounded_bg_abstract_dialog } ) }, ::doSomethingWithVideoList) diff --git a/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/multi/MultiVideoPickerBottomSheetDialog.kt b/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/multi/MultiVideoPickerBottomSheetDialog.kt index b3ad907..aaf803e 100644 --- a/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/multi/MultiVideoPickerBottomSheetDialog.kt +++ b/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/multi/MultiVideoPickerBottomSheetDialog.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.observe import com.crazylegend.core.abstracts.AbstractBottomSheetDialogFragment import com.crazylegend.core.adapters.multi.MultiSelectAdapter import com.crazylegend.core.databinding.FragmentImagesGalleryLayoutMultiBinding +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.extensions.viewBinding import com.crazylegend.videopicker.contracts.MultiPickerContracts @@ -29,7 +30,7 @@ import com.google.android.material.button.MaterialButton * Created by crazy on 5/8/20 to long live and prosper ! */ internal class MultiVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFragment(), - MultiPickerContracts { + MultiPickerContracts { override val layout: Int @@ -40,19 +41,20 @@ internal class MultiVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFrag override val modifier: BaseMultiPickerModifier? get() = arguments?.getParcelable(modifierTag) override val multiSelectAdapter by lazy { - MultiSelectAdapter(modifier) + MultiSelectAdapter(modifier, pickerConfig.showFileSize) } var extensions: Array? = arrayOf() + var pickerConfig: PickerConfig = PickerConfig() override val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - videosVM.loadVideos(extensions = extensions) - } else { - Log.e(errorTag, "PERMISSION DENIED") - dismissAllowingStateLoss() + registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + videosVM.loadVideos(extensions = extensions) + } else { + Log.e(errorTag, "PERMISSION DENIED") + dismissAllowingStateLoss() + } } - } @Suppress("UNCHECKED_CAST") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -63,22 +65,22 @@ internal class MultiVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFrag askForStoragePermission.launch(Manifest.permission.READ_MEDIA_VIDEO) } setupUIForMultiPicker( - binding.gallery, - multiSelectAdapter, - binding.doneButton, - binding.title, - binding.loadingIndicator, - modifier?.loadingIndicatorTint, - ::applyDoneButtonModifications, - ::applyTitleModifications + binding.gallery, + multiSelectAdapter, + binding.doneButton, + binding.title, + binding.loadingIndicator, + modifier?.loadingIndicatorTint, + ::applyDoneButtonModifications, + ::applyTitleModifications ) videosVM.videos.observe(viewLifecycleOwner) { setupList( - multiSelectAdapter, - it, - binding.noContentText, - modifier?.noContentTextModifier + multiSelectAdapter, + it, + binding.noContentText, + modifier?.noContentTextModifier ) } handleUIIndicator(videosVM.loadingIndicator, binding.loadingIndicator) @@ -86,11 +88,11 @@ internal class MultiVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFrag binding.doneButton.setOnClickListener { val videoList = - multiSelectAdapter.currentList.filter { it.isSelected } as? List - ?: emptyList() + multiSelectAdapter.currentList.filter { it.isSelected } as? List + ?: emptyList() setFragmentResult( - MultiVideoPicker.MULTI_VIDEO_REQUEST_KEY, - bundleOf(MultiVideoPicker.ON_MULTI_VIDEO_PICK_KEY to videoList) + MultiVideoPicker.MULTI_VIDEO_REQUEST_KEY, + bundleOf(MultiVideoPicker.ON_MULTI_VIDEO_PICK_KEY to videoList) ) onVideosPicked?.onVideosPicked(videoList) dismissAllowingStateLoss() diff --git a/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/single/SingleVideoPickerBottomSheetDialog.kt b/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/single/SingleVideoPickerBottomSheetDialog.kt index c0e92e9..c263514 100644 --- a/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/single/SingleVideoPickerBottomSheetDialog.kt +++ b/videopicker/src/main/java/com/crazylegend/videopicker/dialogs/single/SingleVideoPickerBottomSheetDialog.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.observe import com.crazylegend.core.abstracts.AbstractBottomSheetDialogFragment import com.crazylegend.core.adapters.single.SingleAdapter import com.crazylegend.core.databinding.FragmentImagesGalleryLayoutBinding +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier import com.crazylegend.extensions.viewBinding import com.crazylegend.videopicker.contracts.SinglePickerContracts @@ -28,7 +29,7 @@ import com.crazylegend.videopicker.videos.VideosVM * Created by crazy on 5/8/20 to long live and prosper ! */ internal class SingleVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFragment(), - SinglePickerContracts { + SinglePickerContracts { override val layout: Int get() = super.layout @@ -36,14 +37,15 @@ internal class SingleVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFra override val binding by viewBinding(FragmentImagesGalleryLayoutBinding::bind) override val videosVM by viewModels() var extensions: Array? = arrayOf() + var pickerConfig: PickerConfig = PickerConfig() override val modifier: BaseSinglePickerModifier? get() = arguments?.getParcelable(modifierTag) override val singleAdapter by lazy { - SingleAdapter(modifier?.viewHolderPlaceholderModifier) { + SingleAdapter(pickerConfig.showFileSize, modifier?.viewHolderPlaceholderModifier, modifier?.sizeTextModifier) { setFragmentResult( - SingleVideoPicker.SINGLE_VIDEO_REQUEST_KEY, - bundleOf(SingleVideoPicker.ON_SINGLE_VIDEO_PICK_KEY to it as VideoModel) + SingleVideoPicker.SINGLE_VIDEO_REQUEST_KEY, + bundleOf(SingleVideoPicker.ON_SINGLE_VIDEO_PICK_KEY to it as VideoModel) ) onVideoPicked?.forVideo(it) dismissAllowingStateLoss() @@ -51,14 +53,14 @@ internal class SingleVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFra } override val askForStoragePermission = - registerForActivityResult(ActivityResultContracts.RequestPermission()) { - if (it) { - videosVM.loadVideos(extensions = extensions) - } else { - Log.e(errorTag, "PERMISSION DENIED") - dismissAllowingStateLoss() + registerForActivityResult(ActivityResultContracts.RequestPermission()) { + if (it) { + videosVM.loadVideos(extensions = extensions) + } else { + Log.e(errorTag, "PERMISSION DENIED") + dismissAllowingStateLoss() + } } - } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -69,12 +71,12 @@ internal class SingleVideoPickerBottomSheetDialog : AbstractBottomSheetDialogFra askForStoragePermission.launch(Manifest.permission.READ_MEDIA_VIDEO) } setupUIForSinglePicker( - binding.gallery, - singleAdapter, - binding.title, - binding.loadingIndicator, - modifier?.loadingIndicatorTint, - ::applyTitleModifications + binding.gallery, + singleAdapter, + binding.title, + binding.loadingIndicator, + modifier?.loadingIndicatorTint, + ::applyTitleModifications ) videosVM.videos.observe(viewLifecycleOwner) { setupList(singleAdapter, it, binding.noContentText, modifier?.noContentTextModifier) diff --git a/videopicker/src/main/java/com/crazylegend/videopicker/pickers/MultiVideoPicker.kt b/videopicker/src/main/java/com/crazylegend/videopicker/pickers/MultiVideoPicker.kt index 26df0f5..7f6d1db 100644 --- a/videopicker/src/main/java/com/crazylegend/videopicker/pickers/MultiVideoPicker.kt +++ b/videopicker/src/main/java/com/crazylegend/videopicker/pickers/MultiVideoPicker.kt @@ -3,6 +3,7 @@ package com.crazylegend.videopicker.pickers import android.content.Context import android.util.Log import androidx.fragment.app.FragmentManager +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier import com.crazylegend.core.setupModifier import com.crazylegend.extensions.setupManager @@ -25,7 +26,7 @@ object MultiVideoPicker { fun restoreListener(context: Context, videoList: (list: List) -> Unit = {}) { val manager = context.setupManager() when (val fragment = manager.findFragmentByTag(MULTI_PICKER_BOTTOM_SHEET) - ?: manager.findFragmentByTag(MULTI_PICKER_DIALOG)) { + ?: manager.findFragmentByTag(MULTI_PICKER_DIALOG)) { is MultiVideoPickerBottomSheetDialog -> { fragment.onVideosPicked = onVideosDSL(videoList) } @@ -37,15 +38,17 @@ object MultiVideoPicker { } fun showPicker( - context: Context, - extensions: Array? = arrayOf(), - modifier: BaseMultiPickerModifier.() -> Unit = {}, - videoList: (list: List) -> Unit = {}, + context: Context, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + modifier: BaseMultiPickerModifier.() -> Unit = {}, + videoList: (list: List) -> Unit = {}, ) { val manager = context.setupManager() val setupModifier = setupModifier(modifier) with(MultiVideoPickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(setupModifier) onVideosPicked = onVideosDSL(videoList) show(manager, MULTI_PICKER_BOTTOM_SHEET) @@ -53,14 +56,16 @@ object MultiVideoPicker { } fun showPicker( - fragmentManager: FragmentManager, - extensions: Array? = arrayOf(), - modifier: BaseMultiPickerModifier.() -> Unit = {}, - videoList: (list: List) -> Unit = {} + fragmentManager: FragmentManager, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + modifier: BaseMultiPickerModifier.() -> Unit = {}, + videoList: (list: List) -> Unit = {} ) { val setupModifier = setupModifier(modifier) with(MultiVideoPickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(setupModifier) onVideosPicked = onVideosDSL(videoList) show(fragmentManager, MULTI_PICKER_BOTTOM_SHEET) diff --git a/videopicker/src/main/java/com/crazylegend/videopicker/pickers/SingleVideoPicker.kt b/videopicker/src/main/java/com/crazylegend/videopicker/pickers/SingleVideoPicker.kt index f16dfdd..5e194dc 100644 --- a/videopicker/src/main/java/com/crazylegend/videopicker/pickers/SingleVideoPicker.kt +++ b/videopicker/src/main/java/com/crazylegend/videopicker/pickers/SingleVideoPicker.kt @@ -3,6 +3,7 @@ package com.crazylegend.videopicker.pickers import android.content.Context import android.util.Log import androidx.fragment.app.FragmentManager +import com.crazylegend.core.dto.PickerConfig import com.crazylegend.core.modifiers.base.BaseSinglePickerModifier import com.crazylegend.core.setupModifier import com.crazylegend.extensions.setupManager @@ -36,15 +37,17 @@ object SingleVideoPicker { } fun showPicker( - context: Context, - extensions: Array? = arrayOf(), - pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, - onPickedVideo: (video: VideoModel) -> Unit = {} + context: Context, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, + onPickedVideo: (video: VideoModel) -> Unit = {} ) { val modifier = setupModifier(pickerModifier) val manager = context.setupManager() with(SingleVideoPickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onVideoPicked = onVideoDSL(onPickedVideo) show(manager, SINGLE_PICKER_BOTTOM_SHEET) @@ -52,14 +55,16 @@ object SingleVideoPicker { } fun showPicker( - fragmentManager: FragmentManager, - extensions: Array? = arrayOf(), - pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, - onPickedVideo: (video: VideoModel) -> Unit = {} + fragmentManager: FragmentManager, + extensions: Array? = arrayOf(), + pickerConfig: PickerConfig = PickerConfig(), + pickerModifier: BaseSinglePickerModifier.() -> Unit = {}, + onPickedVideo: (video: VideoModel) -> Unit = {} ) { val modifier = setupModifier(pickerModifier) with(SingleVideoPickerBottomSheetDialog()) { this.extensions = extensions + this.pickerConfig = pickerConfig addModifier(modifier) onVideoPicked = onVideoDSL(onPickedVideo) show(fragmentManager, SINGLE_PICKER_BOTTOM_SHEET)