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

Commit

Permalink
fix bug #68 #74
Browse files Browse the repository at this point in the history
fix question #70
  • Loading branch information
MikaelZero committed Jun 12, 2021
1 parent 0106b6f commit 21a29a7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
24 changes: 23 additions & 1 deletion app/src/main/java/net/mikaelzero/app/PreviewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.bumptech.glide.Glide
import com.facebook.drawee.backends.pipeline.info.ForwardingImageOriginListener
import kotlinx.android.synthetic.main.activity_display.*
import net.mikaelzero.mojito.Mojito
import net.mikaelzero.mojito.impl.DefaultPercentProgress
Expand Down Expand Up @@ -46,7 +47,7 @@ class PreviewActivity : AppCompatActivity() {
adapter.setOnItemClickListener { _, view, position ->
Mojito.with(context)
.urls(SourceUtil.getNormalImages())
.position(position,headerSize = 1,footerSize = 1)
.position(position, headerSize = 1, footerSize = 1)
.views(recyclerView, R.id.srcImageView)
.autoLoadTarget(false)
.setProgressLoader(object : InstanceLoader<IProgress> {
Expand All @@ -62,6 +63,27 @@ class PreviewActivity : AppCompatActivity() {
override fun onClick(view: View, x: Float, y: Float, position: Int) {
Toast.makeText(context, "tap click", Toast.LENGTH_SHORT).show()
}

override fun onStartAnim(position: Int) {
recyclerView.getChildAt(position+1).findViewById<View?>(R.id.srcImageView)?.visibility = View.GONE
}

override fun onMojitoViewFinish(pagePosition: Int) {
for (x in 0 until recyclerView.childCount) {
recyclerView.getChildAt(x).findViewById<View?>(R.id.srcImageView)?.visibility = View.VISIBLE
}
}

override fun onViewPageSelected(position: Int) {
for (x in 0 until recyclerView.childCount) {
if ((position + 1) == x) {
recyclerView.getChildAt(x).findViewById<View?>(R.id.srcImageView)?.visibility = View.GONE
} else {
recyclerView.getChildAt(x).findViewById<View?>(R.id.srcImageView)?.visibility = View.VISIBLE
}
}

}
})
.setIndicator(NumIndicator())
.start()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
kotlin_version = '1.4.10'
mojito_version = '1.7.1'
mojito_version = '1.7.2'
}

repositories {
Expand Down
4 changes: 4 additions & 0 deletions mojito/src/main/java/net/mikaelzero/mojito/MojitoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ public boolean dispatchTouchEvent(MotionEvent event) {
}
break;
case MotionEvent.ACTION_MOVE:
if (isMultiFinger && mMoveDownTranslateY != 0) {
return true;
}
if (isAnimating || isMultiFinger) {
break;
}
Expand All @@ -542,6 +545,7 @@ public boolean dispatchTouchEvent(MotionEvent event) {
}
break;
}
Log.e("1", "dispatchTouchEvent: isMultiFinger" + isMultiFinger);
if (contentLoader.dispatchTouchEvent(isDrag, false, mMoveDownTranslateY < 0, Math.abs(mTranslateX) > Math.abs(mMoveDownTranslateY))) {
//if is long image,top or bottom or minScale, need handle event
//if image scale<1(origin scale) , need handle event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.mikaelzero.mojito.impl

import android.util.Log
import android.view.View
import androidx.fragment.app.FragmentActivity
import net.mikaelzero.mojito.MojitoView
Expand All @@ -12,6 +11,9 @@ import net.mikaelzero.mojito.interfaces.OnMojitoListener
* @Description:
*/
abstract class SimpleMojitoViewCallback : OnMojitoListener {
override fun onStartAnim(position: Int) {

}
override fun onClick(view: View, x: Float, y: Float, position: Int) {

}
Expand All @@ -22,7 +24,7 @@ import net.mikaelzero.mojito.interfaces.OnMojitoListener
override fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean) {
}

override fun onMojitoViewFinish() {
override fun onMojitoViewFinish(pagePosition:Int) {
}

override fun onDrag(view: MojitoView, moveX: Float, moveY: Float) {
Expand All @@ -31,4 +33,8 @@ import net.mikaelzero.mojito.interfaces.OnMojitoListener
override fun onLongImageMove(ratio: Float) {
}

override fun onViewPageSelected(position: Int) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import net.mikaelzero.mojito.MojitoView
* @Description:
*/
interface OnMojitoListener {
fun onStartAnim(position: Int)
fun onClick(view: View, x: Float, y: Float, position: Int)
fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int)
fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean)
fun onMojitoViewFinish()
fun onMojitoViewFinish(pagePosition: Int)
fun onDrag(view: MojitoView, moveX: Float, moveY: Float)
fun onLongImageMove(ratio: Float)
fun onViewPageSelected(position: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class ImageMojitoActivity : AppCompatActivity(), IMojitoActivity {
imageViewPagerAdapter.getItem(viewPager.currentItem) as IMojitoFragment,
viewPagerBeans.size, position
)
onMojitoListener?.onViewPageSelected(position)
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.io.File

class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {
lateinit var fragmentConfig: FragmentConfig
var showView: View? = null
private var showView: View? = null
private var mImageLoader: ImageLoader? = null
private var mViewLoadFactory: ImageViewLoadFactory? = null
private var contentLoader: ContentLoader? = null
Expand All @@ -47,7 +47,7 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {
return
}
if (arguments != null) {
fragmentConfig = arguments!!.getParcelable(MojitoConstant.KEY_FRAGMENT_PARAMS)!!
fragmentConfig = requireArguments().getParcelable(MojitoConstant.KEY_FRAGMENT_PARAMS)!!
}
mImageLoader = imageLoader()
mViewLoadFactory = if (ImageMojitoActivity.multiContentLoader != null) {
Expand All @@ -72,7 +72,6 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {
mojitoView?.setContentLoader(contentLoader, fragmentConfig.originUrl, fragmentConfig.targetUrl)
showView = contentLoader?.providerRealView()


contentLoader?.onTapCallback(object : OnTapCallback {
override fun onTap(view: View, x: Float, y: Float) {
mojitoView?.backToMin()
Expand Down Expand Up @@ -122,6 +121,9 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {


private fun startAnim(w: Int, h: Int, originLoadFail: Boolean = false, needLoadImageUrl: String = "") {
if (!fragmentConfig.showImmediately) {
ImageMojitoActivity.onMojitoListener?.onStartAnim(fragmentConfig.position)
}
if (fragmentConfig.viewParams == null) {
mojitoView?.showWithoutView(w, h, if (ImageMojitoActivity.hasShowedAnim) true else fragmentConfig.showImmediately)
} else {
Expand Down Expand Up @@ -307,7 +309,7 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {
mojitoView?.backToMin()
}

override fun providerContext(): Fragment? {
override fun providerContext(): Fragment {
return this
}

Expand Down Expand Up @@ -337,7 +339,7 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback {
}

override fun onMojitoViewFinish() {
ImageMojitoActivity.onMojitoListener?.onMojitoViewFinish()
ImageMojitoActivity.onMojitoListener?.onMojitoViewFinish(fragmentConfig.position)
if (context is ImageMojitoActivity) {
(context as ImageMojitoActivity).finishView()
}
Expand Down

0 comments on commit 21a29a7

Please sign in to comment.