Skip to content

Commit

Permalink
Merge pull request #58 from SMask/master
Browse files Browse the repository at this point in the history
图片预览PhotoView冲突;RecyclerView监听onScrollStateChanged回调调整
  • Loading branch information
HuanTanSheng authored Mar 27, 2019
2 parents 5d7c369 + 6cd64c1 commit 4837ed6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,29 @@ private void initRecyclerView() {
snapHelper.attachToRecyclerView(rvPhotos);
rvPhotos.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int leftViewPosition = snapHelper.findTargetSnapPosition(lm, 1, rvPhotos.getHeight() / 2);
int rightViewPosition = snapHelper.findTargetSnapPosition(lm, rvPhotos.getWidth() - 1, rvPhotos.getHeight() / 2);
if (leftViewPosition == rightViewPosition) {
if (lastPosition == leftViewPosition - 1) {
return;
}
previewFragment.setSelectedPosition(-1);
tvNumber.setText(getString(R.string.preview_current_number_easy_photos, leftViewPosition, photos.size()));
lastPosition = leftViewPosition - 1;
View view = snapHelper.findSnapView(lm);
toggleSelector();
if (null == view) {
return;
}
PreviewPhotosAdapter.PreviewPhotosViewHolder viewHolder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view);
if (viewHolder == null || viewHolder.ivPhoto == null) {
return;
}
if (viewHolder.ivPhoto.getScale() != 1f)
viewHolder.ivPhoto.setScale(1f, true);

View view = snapHelper.findSnapView(lm);
if (view == null) {
return;
}
int position = lm.getPosition(view);
if (lastPosition == position) {
return;
}
lastPosition = position;
previewFragment.setSelectedPosition(-1);
tvNumber.setText(getString(R.string.preview_current_number_easy_photos, lastPosition + 1, photos.size()));
toggleSelector();
PreviewPhotosAdapter.PreviewPhotosViewHolder holder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view);
if (holder == null || holder.ivPhoto == null) {
return;
}
if (holder.ivPhoto.getScale() != 1f) {
holder.ivPhoto.setScale(1f, true);


}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.huantansheng.easyphotos.ui.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
* 图片预览 RecyclerView
* Create By lishilin On 2019/3/25
*/
public class PreviewRecyclerView extends RecyclerView {

private boolean isLock;// 是否锁住 RecyclerView ,避免和 PhotoView 双指放大缩小操作冲突

public PreviewRecyclerView(@NonNull Context context) {
super(context);
}

public PreviewRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public PreviewRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:// 非第一个触点按下
isLock = true;
break;
case MotionEvent.ACTION_UP:// 最后一个触点抬起
isLock = false;
break;
}
if (isLock) {
return false;// 不拦截,交给子View处理
}
return super.onInterceptTouchEvent(event);
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:// 非第一个触点按下
isLock = true;
break;
case MotionEvent.ACTION_UP:// 最后一个触点抬起
isLock = false;
break;
}
return super.dispatchTouchEvent(event);
}

}
18 changes: 9 additions & 9 deletions easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:background="@color/easy_photos_bg_primary">

<android.support.v7.widget.RecyclerView
<com.huantansheng.easyphotos.ui.widget.PreviewRecyclerView
android:id="@+id/rv_photos"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Expand All @@ -18,9 +18,9 @@

<FrameLayout
android:id="@+id/m_top_bar_layout"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?metaButtonBarStyle"
android:background="@color/easy_photos_status_bar">

<RelativeLayout
Expand All @@ -37,8 +37,8 @@
android:id="@+id/iv_back"
android:layout_width="42dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:padding="10dp"
app:srcCompat="@drawable/ic_arrow_back_easy_photos" />

Expand Down Expand Up @@ -113,9 +113,9 @@
android:id="@+id/tv_edit"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/fl_fragment"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
Expand All @@ -141,8 +141,8 @@
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_below="@+id/fl_fragment"
android:layout_toLeftOf="@+id/iv_selector"
android:layout_toStartOf="@+id/iv_selector"
android:layout_toLeftOf="@+id/iv_selector"
android:gravity="center"
android:text="@string/selector_easy_photos"
android:textColor="@color/easy_photos_fg_primary"
Expand All @@ -152,13 +152,13 @@
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_below="@+id/fl_fragment"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/fl_fragment"
android:paddingEnd="16dp"
android:paddingStart="6dp"
android:paddingLeft="6dp"
android:paddingEnd="16dp"
android:paddingRight="16dp"
android:paddingStart="6dp"
app:srcCompat="@drawable/ic_selector_easy_photos" />

</RelativeLayout>
Expand Down

0 comments on commit 4837ed6

Please sign in to comment.