修复搜索过滤后弹窗操作位置错乱问题;删除对话框改用独立布局

- 搜索过滤后适配器位置与完整列表位置不一致,所有弹窗方法改为
  从 Adapter 数据源取任务对象,避免取错
- 删除时用 mTaskList.remove(task) 按对象引用移除
- 删除对话框不再复用 dialog_task_edit,改用新增的
  dialog_delete_confirm 专用布局,标题正确显示确认删除
This commit is contained in:
aBuild
2026-05-22 20:26:13 +08:00
parent bf95c11f38
commit e324e3b245
3 changed files with 64 additions and 49 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Fri May 22 20:08:15 HKT 2026
#Fri May 22 20:23:47 HKT 2026
stageCount=8
libraryProject=
baseVersion=15.20
publishVersion=15.20.7
buildCount=0
buildCount=3
baseBetaVersion=15.20.8
@@ -350,11 +350,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
* @param position 要编辑的任务位置
*/
private void showEditTaskDialog(final int position) {
if (position < 0 || position >= mTaskList.size()) {
if (position < 0 || position >= mAdapter.mDataList.size()) {
return;
}
final TaskSchedulerBean task = mTaskList.get(position);
final TaskSchedulerBean task = mAdapter.mDataList.get(position);
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_task_edit);
@@ -551,52 +551,20 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
* @param position 要删除的任务位置
*/
private void showDeleteConfirmDialog(final int position) {
if (position < 0 || position >= mTaskList.size()) {
if (position < 0 || position >= mAdapter.mDataList.size()) {
return;
}
final TaskSchedulerBean task = mTaskList.get(position);
final TaskSchedulerBean task = mAdapter.mDataList.get(position);
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_task_edit);
// 修改对话框布局,只保留必要的按钮
// 隐藏不需要的视图
android.view.View etTaskName = dialog.findViewById(R.id.dialog_et_task_name);
android.view.View etCurrentScheduleTime = dialog.findViewById(R.id.dialog_et_start_time);
android.view.View etMonth = dialog.findViewById(R.id.dialog_et_month);
android.view.View etDay = dialog.findViewById(R.id.dialog_et_day);
android.view.View etHour = dialog.findViewById(R.id.dialog_et_hour);
android.view.View etRemark = dialog.findViewById(R.id.dialog_et_remark);
if (etTaskName != null) etTaskName.setVisibility(View.GONE);
if (etCurrentScheduleTime != null) etCurrentScheduleTime.setVisibility(View.GONE);
if (etMonth != null) etMonth.setVisibility(View.GONE);
if (etDay != null) etDay.setVisibility(View.GONE);
if (etHour != null) etHour.setVisibility(View.GONE);
if (etRemark != null) etRemark.setVisibility(View.GONE);
// 添加提示文本
android.widget.TextView tvMessage = new android.widget.TextView(this);
tvMessage.setText("确定要删除任务 \"" + task.getTaskName() + "\" 吗?");
tvMessage.setPadding(40, 40, 40, 20);
tvMessage.setTextSize(16);
android.view.ViewGroup rootView = dialog.findViewById(android.R.id.content);
if (rootView != null) {
android.view.ViewGroup.LayoutParams params = new android.view.ViewGroup.LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT
);
rootView.addView(tvMessage, 0, params);
}
dialog.setContentView(R.layout.dialog_delete_confirm);
TextView tvMessage = dialog.findViewById(R.id.dialog_delete_message);
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
Button btnSave = dialog.findViewById(R.id.dialog_btn_save);
if (btnSave != null) {
btnSave.setText("确定删除");
}
Button btnConfirm = dialog.findViewById(R.id.dialog_btn_confirm);
tvMessage.setText("确定要删除任务 \"" + task.getTaskName() + "\" 吗?");
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
@@ -605,11 +573,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String taskName = task.getTaskName();
mTaskList.remove(position);
mTaskList.remove(task);
applyChanges();
LogUtils.i(TAG, "showDeleteConfirmDialog: 任务 [" + taskName + "] 已删除");
dialog.dismiss();
@@ -623,11 +591,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
* @param position 要排档的任务位置
*/
private void showScheduleConfirmDialog(final int position) {
if (position < 0 || position >= mTaskList.size()) {
if (position < 0 || position >= mAdapter.mDataList.size()) {
return;
}
final TaskSchedulerBean task = mTaskList.get(position);
final TaskSchedulerBean task = mAdapter.mDataList.get(position);
long currentTime = task.getCurrentScheduleTime();
int duration = task.getDurationMinutes();
long newTime = currentTime + duration * 60 * 1000L;
@@ -673,10 +641,10 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
* @param position 点击排档按钮的任务位置
*/
private void performSchedule(int position) {
if (position < 0 || position >= mTaskList.size()) {
if (position < 0 || position >= mAdapter.mDataList.size()) {
return;
}
TaskSchedulerBean currentTask = mTaskList.get(position);
TaskSchedulerBean currentTask = mAdapter.mDataList.get(position);
long currentTime = currentTask.getCurrentScheduleTime();
int duration = currentTask.getDurationMinutes();
long newTime = currentTime + duration * 60 * 1000L;
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp"
android:background="?android:attr/windowBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确认删除"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
android:paddingBottom="15dp"/>
<TextView
android:id="@+id/dialog_delete_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:paddingBottom="20dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
<Button
android:id="@+id/dialog_btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="取消"
android:layout_marginEnd="10dp"/>
<Button
android:id="@+id/dialog_btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定删除"/>
</LinearLayout>
</LinearLayout>