Skip to content

Multi audio picker customization

CraZyLegenD edited this page May 18, 2020 · 2 revisions

The multi audio picker customization modifier

You'd be calling a picker using

    //multi picker as simple as
    MultiVideoPicker.showPicker(context = this){ doSomethingWithTheImageList(it) }

Where the pickerModifier = {} is a lambda that builds MultiAudioPickerModifier that inherits all of the arguments from BaseMultiPickerModifier except it has an additional viewHolderTitleTextModifier

The BaseMultiPickerModifier has

    doneButtonModifier: DoneButtonModifier
    titleTextModifier: TitleTextModifier
    selectIconModifier: SelectIconModifier
    unSelectedIconModifier: SelectIconModifier
    indicatorsGravity: Gravity
    viewHolderPlaceholderModifier: ImageModifier
    noContentTextModifier: TitleTextModifier
    loadingIndicatorTint: Int?
    viewHolderTitleTextModifier: TitleTextModifier 

So you have two options on how to customize the picker, it is really user preference, whether you choose to do one approach or the other it's up to you, do note that if you're using

   titleTextModifier.apply {

   }

Use a lambda function

   setupBaseMultiPicker(
                    tintForLoadingProgressBar = ContextCompat.getColor(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 audios"
                    },
                    selectIconModifications = {
                        resID = R.drawable.ic_checked
                        tint = Color.BLACK
                    },
                    unSelectIconModifications = {
                        resID = R.drawable.ic_unchecked
                        tint = Color.BLACK
                    },
                    viewHolderPlaceholderModifications = {
                        resID = R.drawable.ic_close
                    }
            )

      setupViewHolderTitleText {
                
            }

Option 1

     MultiAudioPicker.showPicker(this, {

            viewHolderTitleTextModifier.apply {

            }
            loadingIndicatorTint = Color.RED // or use ContextCompat.getColor
            titleTextModifier.apply {

            }
            noContentTextModifier.apply {

            }

        },::doSomethingWithAudioList)

Option 2

MultiAudioPicker.showPicker(this, {
            setupViewHolderTitleText {
                textColor = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark)
                textStyle = TitleTextModifier.TextStyle.BOLD
                textPadding = 10 // use dp or sp this is only for demonstration purposes
            }
            setupBaseMultiPicker(
                    tintForLoadingProgressBar = ContextCompat.getColor(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
                    }
            )
        }, ::doSomethingWithAudioList)

titleTextModifier lambda receives the parameters of the TitleTextModifier and it serves to set the title of the dialog

viewHolderPlaceholderModifier lambda receives the parameters of the ImageModifier and it serves to a placeholder when loading the thumbnails for audios

noContentTextModifier lambda receives the parameters of the TitleTextModifier and it serves to show a text when there's no audios on the device

loadingIndicatorTint receives a color, Color.X color or ContextCompat.getColor

doneButtonModifier lambda receives the parameters of the DoneButtonModifier and it serves to customize the done button in the multi picker

selectIconModifier lambda receives the parameters of the SelectIconModifier and it serves to customize the icon/image when you select an audio

unSelectIconModifier lambda receives the parameters of the SelectIconModifier and it serves to customize the icon/image when you un-select an audio

indicatorsGravity receives a gravity one of TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT the default is BOTTOM_RIGHT and sets the gravity for selectIconModifier and unSelectIconModifier

viewHolderTitleTextModifier lambda receives the parameters of the TitleTextModifier and it serves to show a title of the audio file

It's really important to restore the listeners state, so in your onRestoreInstanceState, you need to call restore listener

 override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        //audios
        MultiAudioPicker.restoreListener(this, ::loadAudios)
    }