diff --git a/app/src/main/java/net/mikaelzero/app/PreviewActivity.kt b/app/src/main/java/net/mikaelzero/app/PreviewActivity.kt index 978f2e0..e19eaca 100644 --- a/app/src/main/java/net/mikaelzero/app/PreviewActivity.kt +++ b/app/src/main/java/net/mikaelzero/app/PreviewActivity.kt @@ -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 @@ -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 { @@ -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(R.id.srcImageView)?.visibility = View.GONE + } + + override fun onMojitoViewFinish(pagePosition: Int) { + for (x in 0 until recyclerView.childCount) { + recyclerView.getChildAt(x).findViewById(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(R.id.srcImageView)?.visibility = View.GONE + } else { + recyclerView.getChildAt(x).findViewById(R.id.srcImageView)?.visibility = View.VISIBLE + } + } + + } }) .setIndicator(NumIndicator()) .start() diff --git a/build.gradle b/build.gradle index 4db74db..2b930d1 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { ext { kotlin_version = '1.4.10' - mojito_version = '1.7.1' + mojito_version = '1.7.2' } repositories { diff --git a/mojito/src/main/java/net/mikaelzero/mojito/MojitoView.java b/mojito/src/main/java/net/mikaelzero/mojito/MojitoView.java index 9b951e6..90918dd 100644 --- a/mojito/src/main/java/net/mikaelzero/mojito/MojitoView.java +++ b/mojito/src/main/java/net/mikaelzero/mojito/MojitoView.java @@ -525,6 +525,9 @@ public boolean dispatchTouchEvent(MotionEvent event) { } break; case MotionEvent.ACTION_MOVE: + if (isMultiFinger && mMoveDownTranslateY != 0) { + return true; + } if (isAnimating || isMultiFinger) { break; } @@ -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 diff --git a/mojito/src/main/java/net/mikaelzero/mojito/impl/SimpleMojitoViewCallback.kt b/mojito/src/main/java/net/mikaelzero/mojito/impl/SimpleMojitoViewCallback.kt index 28f2ebf..6397a90 100644 --- a/mojito/src/main/java/net/mikaelzero/mojito/impl/SimpleMojitoViewCallback.kt +++ b/mojito/src/main/java/net/mikaelzero/mojito/impl/SimpleMojitoViewCallback.kt @@ -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 @@ -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) { } @@ -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) { @@ -31,4 +33,8 @@ import net.mikaelzero.mojito.interfaces.OnMojitoListener override fun onLongImageMove(ratio: Float) { } + override fun onViewPageSelected(position: Int) { + + } + } \ No newline at end of file diff --git a/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoListener.kt b/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoListener.kt index ea336ff..54a9b0a 100644 --- a/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoListener.kt +++ b/mojito/src/main/java/net/mikaelzero/mojito/interfaces/OnMojitoListener.kt @@ -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) } \ No newline at end of file diff --git a/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoActivity.kt b/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoActivity.kt index 4ca556c..4dffd16 100644 --- a/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoActivity.kt +++ b/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoActivity.kt @@ -130,6 +130,7 @@ class ImageMojitoActivity : AppCompatActivity(), IMojitoActivity { imageViewPagerAdapter.getItem(viewPager.currentItem) as IMojitoFragment, viewPagerBeans.size, position ) + onMojitoListener?.onViewPageSelected(position) } }) diff --git a/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoFragment.kt b/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoFragment.kt index 7e0eaed..b090c0b 100644 --- a/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoFragment.kt +++ b/mojito/src/main/java/net/mikaelzero/mojito/ui/ImageMojitoFragment.kt @@ -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 @@ -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) { @@ -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() @@ -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 { @@ -307,7 +309,7 @@ class ImageMojitoFragment : Fragment(), IMojitoFragment, OnMojitoViewCallback { mojitoView?.backToMin() } - override fun providerContext(): Fragment? { + override fun providerContext(): Fragment { return this } @@ -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() }