Skip to content

Single audio picker customization

CraZyLegenD edited this page May 18, 2020 · 1 revision

The single audio picker customization modifier

You'd be calling a picker using

    //single picker as simple as
    SingleAudioPicker.showPicker(context = this){ doSomethingWithSelectedAudioFile(it) }

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

SingleAudioPickerModifier has

    val titleTextModifier: TitleTextModifier = TitleTextModifier(),
    val viewHolderPlaceholderModifier: ImageModifier = ImageModifier(),
    val noContentTextModifier: TitleTextModifier = TitleTextModifier(),
    var loadingIndicatorTint: Int? = null
    val viewHolderTitleTextModifier: TitleTextModifier = 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

   setupViewHolderTitleText {
                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
                    }
            )
        }, ::loadAudio)

Option 1

    SingleAudioPicker.showPicker(this, {
            setupViewHolderTitleText {
                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
                    }
            )
        }, ::loadAudio)

Option 2

SingleAudioPicker.showPicker(this, {
            viewHolderTitleTextModifier.apply {

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

            }
            noContentTextModifier.apply {

            }
        },::loadAudio)

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 audio/videos on the device

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

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
        SingleAudioPicker.restoreListener(this, ::loadAnAudioFile)
    }