Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Latest commit

 

History

History
175 lines (135 loc) · 4.85 KB

README_en.md

File metadata and controls

175 lines (135 loc) · 4.85 KB

mojito Language Language

Demo Download

Video Preview

SAMPLE VIDEO LINK

GIf Preview

Getting started


Add the dependencies

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

implementation "com.github.mikaelzero.mojito:mojito:$mojito_version"
//support long image and gif with Sketch
implementation "com.github.mikaelzero.mojito:SketchImageViewLoader:$mojito_version"

//load with coil
implementation "com.github.mikaelzero.mojito:coilimageloader:$mojito_version"
//load with glide
implementation "com.github.mikaelzero.mojito:GlideImageLoader:$mojito_version"
//load with fresco
implementation "com.github.mikaelzero.mojito:FrescoImageLoader:$mojito_version"

Initialize

// in your application
Mojito.initialize(
    GlideImageLoader.with(this),
    SketchImageLoadFactory()
)

//or

//YourMojitoConfig:IMojitoConfig
Mojito.initialize(
    GlideImageLoader.with(this),
    SketchImageLoadFactory(),
    YourMojitoConfig()
)

Start

Mojito.with(context)
    .urls(SourceUtil.getSingleImage())
    .views(singleIv)
    .start()

Usage

RecyclerView

binding.recyclerView.mojito(R.id.srcImageView) {
    urls(SourceUtil.getNormalImages())
    position(position)
    mojitoListener(
        onClick = { view, x, y, pos ->
            Toast.makeText(context, "tap click", Toast.LENGTH_SHORT).show()
        }
    )
    progressLoader {
        DefaultPercentProgress()
    }
    setIndicator(NumIndicator())
}

Single View

binding.longHorIv.mojito(SourceUtil.getLongHorImage())

No View

 Mojito.start(context) {
    urls(SourceUtil.getNormalImages())
}

Video View or Video/Image View

Mojito.start(context) {
    urls(SourceUtil.getVideoImages(), SourceUtil.getVideoTargetImages())
    setMultiTargetEnableLoader(object : MultiTargetEnableLoader {
        override fun providerEnable(position: Int): Boolean {
            return position != 1
        }
    })
    setMultiContentLoader(object : MultiContentLoader {
        override fun providerLoader(position: Int): ImageViewLoadFactory {
            return if (position == 1) {
                ArtLoadFactory()
            } else {
                SketchImageLoadFactory()
            }
        }
    })
    position(position)
    views(recyclerView, R.id.srcImageView)
}

Callback

 abstract class SimpleMojitoViewCallback : OnMojitoListener {
    // image click
    override fun onClick(view: View, x: Float, y: Float, position: Int) {

    }

    //image long press
    override fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int) {
    }

    //end of min image to max image 
    override fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean) {
    }

    //activity finish,backToMin,single click
    override fun onMojitoViewFinish() {
    }

    //when you drag your image 
    override fun onDrag(view: MojitoView, moveX: Float, moveY: Float) {
    }

    //the ratio of long image when you scroll
    override fun onLongImageMove(ratio: Float) {
    }
}

API

Name desc
url(src,target) set source urls and target urls
position position of click
views 1. recylclerView,imageViewId
2. single view
3. multi views
autoLoadTarget default true,if you set target urls,and set autoLoadTarget(false)
you should load target url by yourself
and using setFragmentCoverLoader() to custom click view
setProgressLoader only work when you set autoLoadTarget false
setIndicator you can choose NumIndicator or CircleIndexIndicator
setActivityCoverLoader custom cover layout
setMultiContentLoader if you need both of video and image ,provider different ImageViewLoadFactory

Thanks

sketch

BigImageViewer