This commit is contained in:
ZhanGSKen 2025-03-04 18:52:16 +08:00
parent 53eced104e
commit 859238a173
7 changed files with 336 additions and 29 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Tue Mar 04 01:25:27 HKT 2025
#Tue Mar 04 10:00:11 GMT 2025
stageCount=9
libraryProject=
baseVersion=1.0
publishVersion=1.0.8
buildCount=0
buildCount=60
baseBetaVersion=1.0.9

View File

@ -19,7 +19,12 @@ import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.contacts.R;
import cc.winboll.studio.contacts.beans.PhoneConnectRuleModel;
import cc.winboll.studio.contacts.dun.Rules;
import java.util.ArrayList;
import java.util.List;
import android.widget.LinearLayout;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;
import cc.winboll.studio.contacts.views.LeftScrollView;
public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -53,15 +58,75 @@ public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.V
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
final PhoneConnectRuleModel model = ruleList.get(position);
if (holder instanceof SimpleViewHolder) {
SimpleViewHolder simpleViewHolder = (SimpleViewHolder) holder;
simpleViewHolder.textView.setText(model.getRuleText());
simpleViewHolder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
model.setIsSimpleView(false);
notifyItemChanged(position);
}
});
final SimpleViewHolder simpleViewHolder = (SimpleViewHolder) holder;
simpleViewHolder.tvRuleText.setText(model.getRuleText());
// simpleViewHolder.setOnActionListener(new SimpleViewHolder.OnActionListener(){
//
// @Override
// public void onEdit(int position) {
// model.setIsSimpleView(false);
// notifyItemChanged(position);
// }
// @Override
// public void onDelete(int position) {
// model.setIsSimpleView(false);
// ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
// list.remove(position);
// Rules.getInstance(context).saveRules();
// notifyItemChanged(position);
// }
// });
// simpleViewHolder.editButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// model.setIsSimpleView(false);
// notifyItemChanged(position);
// }
// });
// simpleViewHolder.deleteButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// model.setIsSimpleView(false);
// ArrayList<PhoneConnectRuleModel> list = Rules.getInstance(context).getPhoneBlacRuleBeanList();
// list.remove(position);
// Rules.getInstance(context).saveRules();
// notifyItemChanged(position);
// }
// });
// // 触摸事件处理
// simpleViewHolder.contentLayout.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// switch (event.getAction()) {
// case MotionEvent.ACTION_DOWN:
// simpleViewHolder.startX = event.getX();
// simpleViewHolder.isSwiping = true;
// break;
// case MotionEvent.ACTION_MOVE:
// if (simpleViewHolder.isSwiping) {
// float deltaX = simpleViewHolder.startX - event.getX();
// if (deltaX > 0) { // 左滑
// float translationX = Math.max(-simpleViewHolder.actionLayout.getWidth(), -deltaX);
// simpleViewHolder.contentLayout.setTranslationX(translationX);
// simpleViewHolder.actionLayout.setVisibility(View.VISIBLE);
// }
// }
// break;
// case MotionEvent.ACTION_UP:
// simpleViewHolder.isSwiping = false;
// if (simpleViewHolder.contentLayout.getTranslationX() < -simpleViewHolder.actionLayout.getWidth() / 2) {
// // 保持按钮显示
// simpleViewHolder.contentLayout.setTranslationX(-actionLayout.getWidth());
// } else {
// // 恢复原状
// simpleViewHolder.contentLayout.animate().translationX(0).setDuration(200).start();
// simpleViewHolder.actionLayout.setVisibility(View.INVISIBLE);
// }
// break;
// }
// return true;
// }
// });
} else if (holder instanceof EditViewHolder) {
final EditViewHolder editViewHolder = (EditViewHolder) holder;
editViewHolder.editText.setText(model.getRuleText());
@ -95,13 +160,17 @@ public class PhoneConnectRuleAdapter extends RecyclerView.Adapter<RecyclerView.V
}
static class SimpleViewHolder extends RecyclerView.ViewHolder {
TextView textView;
Button button;
private final LeftScrollView scrollView;
private final TextView tvRuleText;
public SimpleViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.text_view);
button = itemView.findViewById(R.id.button);
scrollView = itemView.findViewById(R.id.scrollView);
//tvRuleText = itemView.findViewById(R.id.ruletext_tv);
tvRuleText = new TextView(itemView.getContext());
scrollView.addContentLayout(tvRuleText);
}
}

View File

@ -0,0 +1,147 @@
package cc.winboll.studio.contacts.views;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/03/04 10:51:50
* @Describe CustomHorizontalScrollView
*/
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cc.winboll.studio.contacts.R;
public class LeftScrollView extends HorizontalScrollView {
public static final String TAG = "LeftScrollView";
private LinearLayout contentLayout;
private LinearLayout toolLayout;
private TextView textView;
private Button editButton;
private Button deleteButton;
private float startX;
private boolean isDragging = false;
public LeftScrollView(Context context) {
super(context);
init();
}
public LeftScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public LeftScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public void addContentLayout(TextView textView) {
contentLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
}
private void init() {
View viewMain = inflate(getContext(), R.layout.view_left_scroll, null);
// 创建内容布局
contentLayout = viewMain.findViewById(R.id.content_layout);
toolLayout = viewMain.findViewById(R.id.action_layout);
addView(viewMain);
// 动态设置content_layout的宽度为scrollView的宽度
// post(new Runnable() {
// @Override
// public void run() {
// int scrollViewWidth = getWidth();
// LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
// layoutParams.width = scrollViewWidth;
// contentLayout.setLayoutParams(layoutParams);
// }
// });
// 创建编辑按钮
editButton = viewMain.findViewById(R.id.edit_btn);
// 创建删除按钮
deleteButton = viewMain.findViewById(R.id.delete_btn);
// 设置触摸事件监听器
// setOnTouchListener(new OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// switch (event.getAction()) {
// case MotionEvent.ACTION_DOWN:
// startX = event.getX();
// isDragging = true;
// break;
// case MotionEvent.ACTION_MOVE:
// if (isDragging) {
// float deltaX = startX - event.getX();
// if (deltaX > 0) { // 左滑
// float translationX = Math.max(-(editButton.getWidth() + deleteButton.getWidth()), -deltaX);
// toolLayout.setTranslationX(translationX);
// scrollTo((int) translationX, 0);
// }
// }
// break;
// case MotionEvent.ACTION_UP:
// case MotionEvent.ACTION_CANCEL:
// isDragging = false;
// if (getScrollX() <= -(editButton.getWidth())) {
// // 编辑按钮完全显示保持按钮显示
// smoothScrollTo(-(editButton.getWidth() + deleteButton.getWidth()), 0);
// } else {
// // 恢复原状
// smoothScrollTo(0, 0);
// toolLayout.setTranslationX(0);
// }
// break;
// }
// return true;
// }
// });
// 编辑按钮点击事件
editButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onActionListener != null) {
onActionListener.onEdit();
}
}
});
// 删除按钮点击事件
deleteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onActionListener != null) {
onActionListener.onDelete();
}
}
});
}
// 设置文本内容
public void setText(CharSequence text) {
textView.setText(text);
}
// 定义回调接口
public interface OnActionListener {
void onEdit();
void onDelete();
}
private OnActionListener onActionListener;
public void setOnActionListener(OnActionListener listener) {
this.onActionListener = listener;
}
}

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- 内容区域 -->
<LinearLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/white">
<!-- 这里放置你的列表项内容 -->
</LinearLayout>
<!-- 操作按钮 -->
<LinearLayout
android:id="@+id/action_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/lightgray">
<Button
android:id="@+id/edit_btn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="编辑"
android:background="@color/blue" />
<Button
android:id="@+id/delete_btn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="删除"
android:background="@color/red" />
</LinearLayout>
</LinearLayout>

View File

@ -2,24 +2,14 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center_vertical">
android:orientation="horizontal">
<TextView
android:id="@+id/text_view"
android:layout_width="0dp"
<cc.winboll.studio.contacts.views.LeftScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="编辑"/>
android:id="@+id/scrollView"/>
</LinearLayout>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- 内容区域 -->
<LinearLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@color/white">
<!-- 这里放置你的列表项内容 -->
<TextView
android:id="@+id/text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"/>
</LinearLayout>
<!-- 操作按钮 -->
<LinearLayout
android:id="@+id/action_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/lightgray">
<Button
android:id="@+id/edit_btn"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="编辑"
android:background="@color/blue" />
<Button
android:id="@+id/delete_btn"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="删除"
android:background="@color/red" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>

View File

@ -4,4 +4,9 @@
<color name="colorPrimary">#FF196ABC</color>
<color name="colorPrimaryDark">#FF002B57</color>
<color name="colorAccent">#FF80BFFF</color>
<color name="blue">#FF379AFF</color>
<color name="red">#FFE55151</color>
<color name="white">#FFFFFFFF</color>
<color name="lightgray">#FFE0E0E0</color>
</resources>