Skip to content

Ui Module Wiki

Sieun Ju edited this page Dec 19, 2022 · 5 revisions

This library makes it easy to process your gallery with RecyclerView.

Avoid using 'GalleryRecyclerView' as much as possible because it is the screen that requires custom the most in the app service. Rather, copy the example code and use it according to the app service.🥰

스크린샷 2022-12-04 오후 8 47 58

Developer Guide

public class

GalleryRecyclerView

This is a UI class that expresses data imported through Cursor in RecyclerView

Attribute

Link

public methods


setLifecycle(lifecycle: Lifecycle) Required!

setLifecycle(fragmentActivity: FragmentActivity) Required!

setLifecycle(fragment: Fragment) Required!

A function that must be invoked as required because there is a logic that automatically updates when a picture is added.


setCursor(cursor: Cursor?)

A function that imports gallery data and exposes it to RecyclerView.
Automatically process updates when gallery images are added.


setCameraShow(isShow: Boolean)

First Index CameraViewHolder Visible Flag

setCameraResourceId(@DrawableRes id: Int)

First Index CameraViewHolder set Camera Resource Id


setSelectedMaxCount(count: Int)

A function that sets the maximum number of pictures to be selected.


setSelectedSize(size: Int)

A function that sets the width/height value of the numeric UI exposed to the selected item in the picture.

setSelectedDrawable(drawable: Drawable)

The ability to set the background of the numeric UI that is exposed to the selected item in the picture.

setSelectedTxtColor(@ColorInt color: Int)

The ability to set the color of the letter in the numeric UI that is exposed to the selected item in the picture.


setRequestManager(requestManager: RequestManager) Required!

'RequestManager' to be used in 'View Holder'.


requestViewHolderClick(pos: Int)

ViewHolder Auto Click Function


setListener(listener: GalleryListener)

set GalleryAdapter Click Listener


public interface

interface GalleryListener {

    fun onCameraOpen()

    /**
     * Photo Picker Callback
     * @param item Current GalleryItem
     * @param isAdd true Picker, false No Picker
     */
    fun onPhotoPicker(item: GalleryItem, isAdd: Boolean)

    /**
     * Picker Max Count Callback
     */
    fun onMaxPickerCount()

}

GalleryRecyclerView Example

<com.gallery.ui.GalleryRecyclerView
    android:id="@+id/rvGallery"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:scrollbars="vertical"
    app:cursor="@{vm.cursor}"
    app:galleryCameraVisible="true"
    app:gallerySelectedMaxCount="5"
    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    app:onGalleryCameraOpen="@{()->vm.onCameraOpen()}"
    app:onGalleryMaxPicker="@{()->vm.onMaxPhotoClick()}"
    app:onGalleryPhotoClick="@{(item,isAdd) -> vm.onPhotoClick(item,isAdd)}"
    app:spanCount="3"
    tools:listitem="@layout/vh_child_gallery" />

DataBinding Sample

internal object GalleryBindingAdapter {
    interface GalleryCameraOpenListener {
        fun callback()
    }

    interface GalleryPhotoClickListener {
        fun callback(item: GalleryItem, isAdd: Boolean)
    }

    interface GalleryMaxClickListener {
        fun callback()
    }

    /**
     * GalleryRecyclerView setListener
     * DataBinding Example
     *
     */
    @JvmStatic
    @BindingAdapter(
        "onGalleryCameraOpen",
        "onGalleryPhotoClick",
        "onGalleryMaxPicker", requireAll = false
    )
    fun GalleryRecyclerView.setGalleryRecyclerViewListener(
        cameraOpen: GalleryCameraOpenListener? = null,
        photoClick: GalleryPhotoClickListener? = null,
        maxClick: GalleryMaxClickListener? = null
    ) {
        setListener(object : GalleryListener {
            override fun onCameraOpen() {
                cameraOpen?.callback()
            }

            override fun onPhotoPicker(item: GalleryItem, isAdd: Boolean) {
                photoClick?.callback(item, isAdd)
            }

            override fun onMaxPickerCount() {
                maxClick?.callback()
            }
        })
    }

    /**
     * GalleryRecyclerView Set Cusor
     * DataBinding Example
     */
    @JvmStatic
    @BindingAdapter("cursor")
    fun setGalleryCursor(
        view: GalleryRecyclerView,
        cursor: Cursor?
    ) {
        view.setCursor(cursor)
    }
}