mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 21:47:11 +08:00
TaskSchedulerActivity类改用内嵌函数创建内容菜单。
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon May 18 19:22:43 HKT 2026
|
||||
#Mon May 18 12:05:16 GMT 2026
|
||||
stageCount=3
|
||||
libraryProject=
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.2
|
||||
buildCount=0
|
||||
buildCount=3
|
||||
baseBetaVersion=15.20.3
|
||||
|
||||
+18
-61
@@ -39,25 +39,6 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
ArrayList<TaskSchedulerBean> mTaskList;
|
||||
TaskSchedulerAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
menu.add(0, 1001, 0, "编辑任务内容");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == 1001) {
|
||||
View triggerView = item.getActionView();
|
||||
if (triggerView != null && triggerView.getTag() instanceof Integer) {
|
||||
int position = (Integer) triggerView.getTag();
|
||||
showEditTaskDialog(position);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
@@ -129,13 +110,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
* 初始化示例数据
|
||||
*/
|
||||
private void initSampleData() {
|
||||
// 创建今天的日期作为基础
|
||||
java.util.Calendar calendar = java.util.Calendar.getInstance();
|
||||
calendar.set(java.util.Calendar.MINUTE, 0);
|
||||
calendar.set(java.util.Calendar.SECOND, 0);
|
||||
calendar.set(java.util.Calendar.MILLISECOND, 0);
|
||||
|
||||
// 设置不同的小时
|
||||
calendar.set(java.util.Calendar.HOUR_OF_DAY, 9);
|
||||
long time9 = calendar.getTimeInMillis();
|
||||
|
||||
@@ -220,7 +199,6 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.dialog_task_edit);
|
||||
|
||||
// 初始化对话框控件
|
||||
final EditText etTaskName = dialog.findViewById(R.id.dialog_et_task_name);
|
||||
final EditText etCurrentScheduleTime = dialog.findViewById(R.id.dialog_et_start_time);
|
||||
final EditText etMonth = dialog.findViewById(R.id.dialog_et_month);
|
||||
@@ -230,12 +208,10 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
|
||||
Button btnSave = dialog.findViewById(R.id.dialog_btn_save);
|
||||
|
||||
// 填充现有数据 - 将分钟转换为月、天、小时
|
||||
etTaskName.setText(task.getTaskName());
|
||||
etCurrentScheduleTime.setText(formatTimestamp(task.getCurrentScheduleTime()));
|
||||
etRemark.setText(task.getRemark());
|
||||
|
||||
// 反向转换:将分钟转换为月、天、小时
|
||||
int totalMinutes = task.getDurationMinutes();
|
||||
int totalHours = totalMinutes / MINUTES_PER_HOUR;
|
||||
int totalDays = totalHours / HOURS_PER_DAY;
|
||||
@@ -253,7 +229,6 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
etHour.setText(Integer.toString(hour));
|
||||
}
|
||||
|
||||
// 取消按钮
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -261,11 +236,9 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
}
|
||||
});
|
||||
|
||||
// 保存按钮
|
||||
btnSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 获取输入的数据
|
||||
String taskName = etTaskName.getText().toString().trim();
|
||||
String currentScheduleTime = etCurrentScheduleTime.getText().toString().trim();
|
||||
String monthStr = etMonth.getText().toString().trim();
|
||||
@@ -273,7 +246,6 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
String hourStr = etHour.getText().toString().trim();
|
||||
String remark = etRemark.getText().toString().trim();
|
||||
|
||||
// 验证输入
|
||||
if (taskName.isEmpty()) {
|
||||
etTaskName.setError("请输入任务名称");
|
||||
return;
|
||||
@@ -283,50 +255,33 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析时间字符串为时间戳
|
||||
long timestamp = parseTimeString(currentScheduleTime);
|
||||
if (timestamp == 0) {
|
||||
etCurrentScheduleTime.setError("时间格式不正确,请使用 yyyy-MM-dd HH 格式");
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析排档幅度 - 月、天、小时
|
||||
int month = 0;
|
||||
int day = 0;
|
||||
int hour = 0;
|
||||
|
||||
int month = 0, day = 0, hour = 0;
|
||||
try {
|
||||
if (!monthStr.isEmpty()) {
|
||||
month = Integer.parseInt(monthStr);
|
||||
}
|
||||
if (!dayStr.isEmpty()) {
|
||||
day = Integer.parseInt(dayStr);
|
||||
}
|
||||
if (!hourStr.isEmpty()) {
|
||||
hour = Integer.parseInt(hourStr);
|
||||
}
|
||||
if (!monthStr.isEmpty()) month = Integer.parseInt(monthStr);
|
||||
if (!dayStr.isEmpty()) day = Integer.parseInt(dayStr);
|
||||
if (!hourStr.isEmpty()) hour = Integer.parseInt(hourStr);
|
||||
} catch (NumberFormatException e) {
|
||||
LogUtils.e(TAG, "showEditTaskDialog: 数字解析错误", e);
|
||||
return;
|
||||
}
|
||||
|
||||
// 转换为总分钟数
|
||||
int durationMinutes = convertToTotalMinutes(month, day, hour);
|
||||
|
||||
// 更新任务数据
|
||||
task.setTaskName(taskName);
|
||||
task.setCurrentScheduleTime(timestamp);
|
||||
task.setDurationMinutes(durationMinutes);
|
||||
task.setRemark(remark);
|
||||
|
||||
// 刷新列表
|
||||
mAdapter.notifyItemChanged(position);
|
||||
LogUtils.i(TAG, "showEditTaskDialog: 任务 [" + taskName + "] 数据已更新,排档幅度=" + durationMinutes + "分钟");
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@@ -338,16 +293,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
if (position < 0 || position >= mTaskList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TaskSchedulerBean currentTask = mTaskList.get(position);
|
||||
long currentTime = currentTask.getCurrentScheduleTime();
|
||||
int duration = currentTask.getDurationMinutes();
|
||||
|
||||
// 计算新的时间(时间戳加上分钟数)
|
||||
long newTime = currentTime + duration * 60 * 1000L;
|
||||
LogUtils.i(TAG, "performSchedule: 当前时间 " + formatTimestamp(currentTime) + " + " + duration + "分钟 = " + formatTimestamp(newTime));
|
||||
|
||||
// 更新下一个任务的时间(如果有)
|
||||
if (position + 1 < mTaskList.size()) {
|
||||
TaskSchedulerBean nextTask = mTaskList.get(position + 1);
|
||||
nextTask.setCurrentScheduleTime(newTime);
|
||||
@@ -379,22 +329,29 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
|
||||
viewHolder.mtvTaskName.setText(item.getTaskName());
|
||||
viewHolder.mtvCurrentScheduleTime.setText(formatTimestamp(item.getCurrentScheduleTime()));
|
||||
// 格式化显示排档幅度
|
||||
viewHolder.mtvDuration.setText(formatDurationToString(item.getDurationMinutes()));
|
||||
viewHolder.mtvRemark.setText(item.getRemark());
|
||||
|
||||
// mllMain长按存入当前条目独立位置Tag,互不干扰
|
||||
// 长按直接内置菜单,直接使用当前position
|
||||
viewHolder.mllMain.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
v.setTag(position);
|
||||
registerForContextMenu(v);
|
||||
openContextMenu(v);
|
||||
public boolean onLongClick(final View v) {
|
||||
// 动态创建上下文菜单
|
||||
ContextMenu menu = new android.view.ContextMenu(getApplicationContext());
|
||||
menu.add("编辑任务内容").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// 直接使用onBind里的position,无需取tag
|
||||
showEditTaskDialog(position);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// 弹出菜单
|
||||
viewHolder.mllMain.showContextMenu();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// 设置排档按钮点击事件
|
||||
viewHolder.mbtnSchedule.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Reference in New Issue
Block a user