Skip to content

Commit

Permalink
Show file size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vedraj360 committed Mar 13, 2024
1 parent 540819b commit 2ff9455
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 97 deletions.
10 changes: 5 additions & 5 deletions app/src/main/java/com/crazylegend/mediapicker/FragmentResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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.Config
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
Expand Down Expand Up @@ -147,7 +147,7 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe

@SuppressLint("MissingPermission")
private fun showVideoMultiBottomSheetPicker() {
MultiVideoPicker.showPicker(requireContext(), arrayOf(), config = Config(showFileSize = true), {
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
Expand All @@ -173,7 +173,7 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe
private fun showSingleVideoBottomSheetPicker() {
//SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo)

SingleVideoPicker.showPicker(requireContext(), extensions = arrayOf(), config = Config(showFileSize = false), {
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
Expand Down Expand Up @@ -203,7 +203,7 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe
//images
@SuppressLint("MissingPermission")
private fun showImageMultiBottomSheetPicker() {
MultiImagePicker.showPicker(requireContext(), extensions = arrayOf(), config = Config(showFileSize = false), {
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
Expand All @@ -226,7 +226,7 @@ class FragmentResult : DialogFragment(R.layout.activity_main), View.OnClickListe

@SuppressLint("MissingPermission")
private fun showSingleImageBottomSheetPicker() {
SingleImagePicker.showPicker(requireContext(), extensions = arrayOf(), config = Config(showFileSize = true), {
SingleImagePicker.showPicker(requireContext(), extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), {
loadingIndicatorTint = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)
titleTextModifier.apply {
textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START
Expand Down
52 changes: 44 additions & 8 deletions app/src/main/java/com/crazylegend/mediapicker/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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.Config
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
Expand Down Expand Up @@ -150,7 +151,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
//videos

private fun showVideoMultiBottomSheetPicker() {
MultiVideoPicker.showPicker(this, extensions = arrayOf(), config = Config(showFileSize = true), {
MultiVideoPicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), {
setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor(
this@MainActivity, R.color.colorPrimaryDark
),
Expand All @@ -174,15 +175,23 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
},
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)
}


private fun showSingleVideoBottomSheetPicker() {
//SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo)

SingleVideoPicker.showPicker(this, extensions = arrayOf(), config = Config(showFileSize = true), {
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
Expand All @@ -193,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)

}
Expand All @@ -212,7 +230,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
//images

private fun showImageMultiBottomSheetPicker() {
MultiImagePicker.showPicker(this, extensions = arrayOf(), config = Config(showFileSize = true), {
MultiImagePicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), {
setupBaseMultiPicker(tintForLoadingProgressBar = ContextCompat.getColor(
this@MainActivity, R.color.colorPrimaryDark
),
Expand All @@ -236,15 +254,24 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
},
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)
}
}


private fun showSingleImageBottomSheetPicker() {
SingleImagePicker.showPicker(this, extensions = arrayOf(), config = Config(showFileSize = true),{
SingleImagePicker.showPicker(this, extensions = arrayOf(), pickerConfig = PickerConfig(showFileSize = true), {
loadingIndicatorTint =
ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark)
titleTextModifier.apply {
Expand All @@ -267,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)
}

Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/com/crazylegend/core/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 !
Expand Down Expand Up @@ -143,7 +144,15 @@ internal var Float.dp: Float
}
set(_) {}

internal fun Int.bytesToMegabytesFormatted(): String {
val megabytes = this / (1024.0 * 1024.0)
return "%.2f MB".format(megabytes)
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.crazylegend.core.adapters.multi

import androidx.core.view.isVisible
import com.crazylegend.core.adapters.BaseViewHolder
import com.crazylegend.core.bytesToMegabytesFormatted
import com.crazylegend.core.bytesToFormattedString
import com.crazylegend.core.databinding.ItemviewImageBinding
import com.crazylegend.core.dto.BaseCursorModel
import com.crazylegend.core.modifiers.base.BaseMultiPickerModifier
Expand All @@ -29,10 +29,12 @@ class MultiSelectViewHolder(
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 = true
binding.size.text = size.bytesToMegabytesFormatted()
binding.size.isVisible = size > 0
binding.size.text = size.bytesToFormattedString()
}
}
if (cursorModel.isSelected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ 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


/**
* 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<BaseCursorModel, SingleViewHolder>(SingleDiffUtil()) {
var showFileSize: Boolean = false

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.crazylegend.core.adapters.single

import androidx.core.view.isVisible
import com.crazylegend.core.adapters.BaseViewHolder
import com.crazylegend.core.bytesToMegabytesFormatted
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


Expand All @@ -14,16 +15,18 @@ 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, 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 = true
binding.size.text = size.bytesToMegabytesFormatted()
binding.size.isVisible = size > 0
binding.size.text = size.bytesToFormattedString()
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/com/crazylegend/core/dto/Config.kt

This file was deleted.

3 changes: 3 additions & 0 deletions core/src/main/java/com/crazylegend/core/dto/PickerConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.crazylegend.core.dto

data class PickerConfig(val showFileSize: Boolean = false)
Loading

0 comments on commit 2ff9455

Please sign in to comment.