规则编辑列表的项滑动逻辑完成。
This commit is contained in:
		@@ -1,8 +1,8 @@
 | 
				
			|||||||
#Created by .winboll/winboll_app_build.gradle
 | 
					#Created by .winboll/winboll_app_build.gradle
 | 
				
			||||||
#Wed Mar 05 17:21:57 HKT 2025
 | 
					#Wed Mar 05 12:40:02 GMT 2025
 | 
				
			||||||
stageCount=10
 | 
					stageCount=10
 | 
				
			||||||
libraryProject=
 | 
					libraryProject=
 | 
				
			||||||
baseVersion=1.0
 | 
					baseVersion=1.0
 | 
				
			||||||
publishVersion=1.0.9
 | 
					publishVersion=1.0.9
 | 
				
			||||||
buildCount=0
 | 
					buildCount=35
 | 
				
			||||||
baseBetaVersion=1.0.10
 | 
					baseBetaVersion=1.0.10
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,7 @@ import android.widget.LinearLayout;
 | 
				
			|||||||
import android.view.MotionEvent;
 | 
					import android.view.MotionEvent;
 | 
				
			||||||
import android.widget.HorizontalScrollView;
 | 
					import android.widget.HorizontalScrollView;
 | 
				
			||||||
import cc.winboll.studio.contacts.views.LeftScrollView;
 | 
					import cc.winboll.studio.contacts.views.LeftScrollView;
 | 
				
			||||||
 | 
					import com.hjq.toast.ToastUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
 | 
					public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -62,6 +63,43 @@ public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.V
 | 
				
			|||||||
            String szView = model.getRuleText().trim().equals("")?"[NULL]":model.getRuleText();
 | 
					            String szView = model.getRuleText().trim().equals("")?"[NULL]":model.getRuleText();
 | 
				
			||||||
            simpleViewHolder.tvRuleText.setText(szView);
 | 
					            simpleViewHolder.tvRuleText.setText(szView);
 | 
				
			||||||
            simpleViewHolder.scrollView.setOnActionListener(new LeftScrollView.OnActionListener(){
 | 
					            simpleViewHolder.scrollView.setOnActionListener(new LeftScrollView.OnActionListener(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void onUp() {
 | 
				
			||||||
 | 
					                        ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
 | 
				
			||||||
 | 
					                        if(position > 0) {
 | 
				
			||||||
 | 
					                            ToastUtils.show("onUp");
 | 
				
			||||||
 | 
					                            simpleViewHolder.scrollView.smoothScrollTo(0, 0);
 | 
				
			||||||
 | 
					//                            PhoneConnectRuleModel newBean = new PhoneConnectRuleModel();
 | 
				
			||||||
 | 
					//                            newBean.setRuleText(list.get(position).getRuleText());
 | 
				
			||||||
 | 
					//                            newBean.setIsAllowConnection(list.get(position).isAllowConnection());
 | 
				
			||||||
 | 
					//                            newBean.setIsEnable(list.get(position).isEnable());
 | 
				
			||||||
 | 
					//                            newBean.setIsSimpleView(list.get(position).isSimpleView());
 | 
				
			||||||
 | 
					                            list.add(position - 1, list.get(position));
 | 
				
			||||||
 | 
					                            list.remove(position + 1);
 | 
				
			||||||
 | 
					                            Rules.getInstance(context).saveRules();
 | 
				
			||||||
 | 
					                            notifyDataSetChanged();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void onDown() {
 | 
				
			||||||
 | 
					                        ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
 | 
				
			||||||
 | 
					                        if(position < list.size() - 1) {
 | 
				
			||||||
 | 
					                            ToastUtils.show("onDown");
 | 
				
			||||||
 | 
					                            simpleViewHolder.scrollView.smoothScrollTo(0, 0);
 | 
				
			||||||
 | 
					//                            PhoneConnectRuleModel newBean = new PhoneConnectRuleModel();
 | 
				
			||||||
 | 
					//                            newBean.setRuleText(list.get(position).getRuleText());
 | 
				
			||||||
 | 
					//                            newBean.setIsAllowConnection(list.get(position).isAllowConnection());
 | 
				
			||||||
 | 
					//                            newBean.setIsEnable(list.get(position).isEnable());
 | 
				
			||||||
 | 
					//                            newBean.setIsSimpleView(list.get(position).isSimpleView());
 | 
				
			||||||
 | 
					                            list.add(position + 2, list.get(position));
 | 
				
			||||||
 | 
					                            list.remove(position);
 | 
				
			||||||
 | 
					                            Rules.getInstance(context).saveRules();
 | 
				
			||||||
 | 
					                            notifyDataSetChanged();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
                    public void onEdit() {
 | 
					                    public void onEdit() {
 | 
				
			||||||
                        simpleViewHolder.scrollView.smoothScrollTo(0, 0);
 | 
					                        simpleViewHolder.scrollView.smoothScrollTo(0, 0);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,6 @@ import android.widget.LinearLayout;
 | 
				
			|||||||
import android.widget.TextView;
 | 
					import android.widget.TextView;
 | 
				
			||||||
import cc.winboll.studio.contacts.R;
 | 
					import cc.winboll.studio.contacts.R;
 | 
				
			||||||
import cc.winboll.studio.libappbase.LogUtils;
 | 
					import cc.winboll.studio.libappbase.LogUtils;
 | 
				
			||||||
import android.util.TypedValue;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class LeftScrollView extends HorizontalScrollView {
 | 
					public class LeftScrollView extends HorizontalScrollView {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,8 +25,12 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
    private TextView textView;
 | 
					    private TextView textView;
 | 
				
			||||||
    private Button editButton;
 | 
					    private Button editButton;
 | 
				
			||||||
    private Button deleteButton;
 | 
					    private Button deleteButton;
 | 
				
			||||||
    private float mLastX;
 | 
					    private Button upButton;
 | 
				
			||||||
 | 
					    private Button downButton;
 | 
				
			||||||
 | 
					    private float mStartX;
 | 
				
			||||||
 | 
					    private float mEndX;
 | 
				
			||||||
    private boolean isScrolling = false;
 | 
					    private boolean isScrolling = false;
 | 
				
			||||||
 | 
					    private int nScrollAcceptSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public LeftScrollView(Context context) {
 | 
					    public LeftScrollView(Context context) {
 | 
				
			||||||
        super(context);
 | 
					        super(context);
 | 
				
			||||||
@@ -52,6 +55,7 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
 | 
					        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
 | 
				
			||||||
        layoutParams.width = contentWidth;
 | 
					        layoutParams.width = contentWidth;
 | 
				
			||||||
        contentLayout.setLayoutParams(layoutParams);
 | 
					        contentLayout.setLayoutParams(layoutParams);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void init() {
 | 
					    private void init() {
 | 
				
			||||||
@@ -69,6 +73,10 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
        editButton = viewMain.findViewById(R.id.edit_btn);
 | 
					        editButton = viewMain.findViewById(R.id.edit_btn);
 | 
				
			||||||
        // 创建删除按钮
 | 
					        // 创建删除按钮
 | 
				
			||||||
        deleteButton = viewMain.findViewById(R.id.delete_btn);
 | 
					        deleteButton = viewMain.findViewById(R.id.delete_btn);
 | 
				
			||||||
 | 
					        // 向上按钮
 | 
				
			||||||
 | 
					        upButton = viewMain.findViewById(R.id.up_btn);
 | 
				
			||||||
 | 
					        // 向下按钮
 | 
				
			||||||
 | 
					        downButton = viewMain.findViewById(R.id.down_btn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 编辑按钮点击事件
 | 
					        // 编辑按钮点击事件
 | 
				
			||||||
        editButton.setOnClickListener(new OnClickListener() {
 | 
					        editButton.setOnClickListener(new OnClickListener() {
 | 
				
			||||||
@@ -89,6 +97,25 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					        // 编辑按钮点击事件
 | 
				
			||||||
 | 
					        upButton.setOnClickListener(new OnClickListener() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public void onClick(View v) {
 | 
				
			||||||
 | 
					                    if (onActionListener != null) {
 | 
				
			||||||
 | 
					                        onActionListener.onUp();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 删除按钮点击事件
 | 
				
			||||||
 | 
					        downButton.setOnClickListener(new OnClickListener() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public void onClick(View v) {
 | 
				
			||||||
 | 
					                    if (onActionListener != null) {
 | 
				
			||||||
 | 
					                        onActionListener.onDown();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -96,53 +123,40 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
        switch (event.getAction()) {
 | 
					        switch (event.getAction()) {
 | 
				
			||||||
            case MotionEvent.ACTION_DOWN:
 | 
					            case MotionEvent.ACTION_DOWN:
 | 
				
			||||||
                LogUtils.d(TAG, "ACTION_DOWN");
 | 
					                LogUtils.d(TAG, "ACTION_DOWN");
 | 
				
			||||||
                mLastX = event.getX();
 | 
					                mStartX = event.getX();
 | 
				
			||||||
                isScrolling = false;
 | 
					//                isScrolling = false;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case MotionEvent.ACTION_MOVE:
 | 
					            case MotionEvent.ACTION_MOVE:
 | 
				
			||||||
                //LogUtils.d(TAG, "ACTION_MOVE");
 | 
					                //LogUtils.d(TAG, "ACTION_MOVE");
 | 
				
			||||||
                float currentX = event.getX();
 | 
					//                float currentX = event.getX();
 | 
				
			||||||
                float deltaX = mLastX - currentX;
 | 
					//                float deltaX = mStartX - currentX;
 | 
				
			||||||
                mLastX = currentX;
 | 
					//                //mLastX = currentX;
 | 
				
			||||||
                if (Math.abs(deltaX) > 0) {
 | 
					//                if (Math.abs(deltaX) > 0) {
 | 
				
			||||||
                    isScrolling = true;
 | 
					//                    isScrolling = true;
 | 
				
			||||||
                }
 | 
					//                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case MotionEvent.ACTION_UP:
 | 
					            case MotionEvent.ACTION_UP:
 | 
				
			||||||
            case MotionEvent.ACTION_CANCEL:
 | 
					            case MotionEvent.ACTION_CANCEL:
 | 
				
			||||||
                LogUtils.d(TAG, "ACTION_UP");
 | 
					                if (getScrollX() > 0) {
 | 
				
			||||||
                if (isScrolling) {
 | 
					                    LogUtils.d(TAG, "ACTION_UP");
 | 
				
			||||||
                    LogUtils.d(TAG, String.format("isScrolling \ngetScrollX() %d\neditButton.getWidth() %d", getScrollX(), editButton.getWidth()));
 | 
					                    mEndX = event.getX();
 | 
				
			||||||
                    int scrollX = getScrollX();
 | 
					                    LogUtils.d(TAG, String.format("mStartX %f, mEndX %f", mStartX, mEndX));
 | 
				
			||||||
                    if (scrollX > editButton.getWidth()) {
 | 
					                    if (mEndX < mStartX) {
 | 
				
			||||||
                        // 获取HorizontalScrollView的子视图
 | 
					                        LogUtils.d(TAG, String.format("mEndX >= mStartX \ngetScrollX() %d", getScrollX()));
 | 
				
			||||||
                        View childView = getChildAt(0);
 | 
					                        //if (getScrollX() > editButton.getWidth()) {
 | 
				
			||||||
                        if (childView != null) {
 | 
					                        if (Math.abs(mStartX - mEndX) > editButton.getWidth()) {
 | 
				
			||||||
                            // 计算需要滑动到最右边的距离
 | 
					                            smoothScrollToRight();
 | 
				
			||||||
                            int scrollToX = childView.getWidth() - getWidth();
 | 
					                        } else {
 | 
				
			||||||
                            // 确保滑动距离不小于0
 | 
					                            smoothScrollToLeft();
 | 
				
			||||||
                            final int scrollToX2 = Math.max(0, scrollToX);
 | 
					 | 
				
			||||||
                            // 平滑滑动到最右边
 | 
					 | 
				
			||||||
                            post(new Runnable() {
 | 
					 | 
				
			||||||
                                    @Override
 | 
					 | 
				
			||||||
                                    public void run() {
 | 
					 | 
				
			||||||
                                        smoothScrollTo(scrollToX2, 0);
 | 
					 | 
				
			||||||
                                        LogUtils.d(TAG, "smoothScrollTo(0, 0);");
 | 
					 | 
				
			||||||
                                    }
 | 
					 | 
				
			||||||
                                });
 | 
					 | 
				
			||||||
                            LogUtils.d(TAG, "smoothScrollTo(scrollToX, 0);");
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        // 恢复原状
 | 
					                        LogUtils.d(TAG, String.format("mEndX >= mStartX \ngetScrollX() %d", getScrollX()));
 | 
				
			||||||
                        // 在手指抬起时,使用 post 方法调用 smoothScrollTo(0, 0)
 | 
					                        //if (getScrollX() > deleteButton.getWidth()) {
 | 
				
			||||||
                        post(new Runnable() {
 | 
					                        if (Math.abs(mEndX - mStartX) > deleteButton.getWidth()) {
 | 
				
			||||||
                                @Override
 | 
					                            smoothScrollToLeft();
 | 
				
			||||||
                                public void run() {
 | 
					                        } else {
 | 
				
			||||||
                                    smoothScrollTo(0, 0);
 | 
					                            smoothScrollToRight();
 | 
				
			||||||
                                    LogUtils.d(TAG, "smoothScrollTo(0, 0);");
 | 
					                        }
 | 
				
			||||||
                                }
 | 
					 | 
				
			||||||
                            });
 | 
					 | 
				
			||||||
                        //toolLayout.setTranslationX(0);
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@@ -150,6 +164,40 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
        return super.onTouchEvent(event);
 | 
					        return super.onTouchEvent(event);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void smoothScrollToRight() {
 | 
				
			||||||
 | 
					        mEndX = 0;
 | 
				
			||||||
 | 
					        mStartX = 0;
 | 
				
			||||||
 | 
					        View childView = getChildAt(0);
 | 
				
			||||||
 | 
					        if (childView != null) {
 | 
				
			||||||
 | 
					            // 计算需要滑动到最右边的距离
 | 
				
			||||||
 | 
					            int scrollToX = childView.getWidth() - getWidth();
 | 
				
			||||||
 | 
					            // 确保滑动距离不小于0
 | 
				
			||||||
 | 
					            final int scrollToX2 = Math.max(0, scrollToX);
 | 
				
			||||||
 | 
					            // 平滑滑动到最右边
 | 
				
			||||||
 | 
					            post(new Runnable() {
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void run() {
 | 
				
			||||||
 | 
					                        smoothScrollTo(scrollToX2, 0);
 | 
				
			||||||
 | 
					                        LogUtils.d(TAG, "smoothScrollTo(0, 0);");
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "smoothScrollTo(scrollToX, 0);");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void smoothScrollToLeft() {
 | 
				
			||||||
 | 
					        mEndX = 0;
 | 
				
			||||||
 | 
					        mStartX = 0;
 | 
				
			||||||
 | 
					        // 在手指抬起时,使用 post 方法调用 smoothScrollTo(0, 0)
 | 
				
			||||||
 | 
					        post(new Runnable() {
 | 
				
			||||||
 | 
					                @Override
 | 
				
			||||||
 | 
					                public void run() {
 | 
				
			||||||
 | 
					                    smoothScrollTo(0, 0);
 | 
				
			||||||
 | 
					                    LogUtils.d(TAG, "smoothScrollTo(0, 0);");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 设置文本内容
 | 
					    // 设置文本内容
 | 
				
			||||||
    public void setText(CharSequence text) {
 | 
					    public void setText(CharSequence text) {
 | 
				
			||||||
        textView.setText(text);
 | 
					        textView.setText(text);
 | 
				
			||||||
@@ -159,6 +207,8 @@ public class LeftScrollView extends HorizontalScrollView {
 | 
				
			|||||||
    public interface OnActionListener {
 | 
					    public interface OnActionListener {
 | 
				
			||||||
        void onEdit();
 | 
					        void onEdit();
 | 
				
			||||||
        void onDelete();
 | 
					        void onDelete();
 | 
				
			||||||
 | 
					        void onUp();
 | 
				
			||||||
 | 
					        void onDown();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private OnActionListener onActionListener;
 | 
					    private OnActionListener onActionListener;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,18 @@
 | 
				
			|||||||
            android:layout_height="wrap_content"
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
            android:text="编辑"
 | 
					            android:text="编辑"
 | 
				
			||||||
            android:background="@color/blue" />
 | 
					            android:background="@color/blue" />
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					            android:id="@+id/up_btn"
 | 
				
			||||||
 | 
					            android:layout_width="40dp"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:text="△"
 | 
				
			||||||
 | 
					            android:background="@color/green" />
 | 
				
			||||||
 | 
					        <Button
 | 
				
			||||||
 | 
					            android:id="@+id/down_btn"
 | 
				
			||||||
 | 
					            android:layout_width="40dp"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:text="▽"
 | 
				
			||||||
 | 
					            android:background="@color/green" />
 | 
				
			||||||
        <Button
 | 
					        <Button
 | 
				
			||||||
            android:id="@+id/delete_btn"
 | 
					            android:id="@+id/delete_btn"
 | 
				
			||||||
            android:layout_width="80dp"
 | 
					            android:layout_width="80dp"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
    <color name="colorPrimaryDark">#FF002B57</color>
 | 
					    <color name="colorPrimaryDark">#FF002B57</color>
 | 
				
			||||||
    <color name="colorAccent">#FF80BFFF</color>
 | 
					    <color name="colorAccent">#FF80BFFF</color>
 | 
				
			||||||
    <color name="blue">#FF379AFF</color>
 | 
					    <color name="blue">#FF379AFF</color>
 | 
				
			||||||
 | 
					    <color name="green">#FF69E551</color>
 | 
				
			||||||
    <color name="red">#FFE55151</color>
 | 
					    <color name="red">#FFE55151</color>
 | 
				
			||||||
    <color name="white">#FFFFFFFF</color>
 | 
					    <color name="white">#FFFFFFFF</color>
 | 
				
			||||||
    <color name="lightgray">#FFE0E0E0</color>
 | 
					    <color name="lightgray">#FFE0E0E0</color>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user