mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 13:37:11 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bf95c11f38 | |||
| 69d1f6197e | |||
| 85bf9f1e1c | |||
| 4a0fbf024d | |||
| e8e7887926 | |||
| 4acae6726c | |||
| e61c36dfed | |||
| 297d840bff | |||
| 43e783f5aa | |||
| a11bad310b | |||
| 0ad264c4aa | |||
| 81c2b781b6 | |||
| de63acc114 | |||
| 02c27c37f7 |
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon May 18 19:22:43 HKT 2026
|
||||
stageCount=3
|
||||
#Fri May 22 20:08:15 HKT 2026
|
||||
stageCount=8
|
||||
libraryProject=
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.2
|
||||
publishVersion=15.20.7
|
||||
buildCount=0
|
||||
baseBetaVersion=15.20.3
|
||||
baseBetaVersion=15.20.8
|
||||
|
||||
+435
-69
@@ -2,6 +2,8 @@ package cc.winboll.studio.stallhelper.activities;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -11,6 +13,7 @@ import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -21,6 +24,13 @@ import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.stallhelper.R;
|
||||
import cc.winboll.studio.stallhelper.beans.TaskSchedulerBean;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen
|
||||
@@ -38,25 +48,9 @@ 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);
|
||||
}
|
||||
EditText mSearchEditText;
|
||||
String mSearchQuery = "";
|
||||
HanyuPinyinOutputFormat mPinyinFormat;
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
@@ -75,13 +69,44 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
|
||||
// 初始化任务列表
|
||||
mTaskList = new ArrayList<TaskSchedulerBean>();
|
||||
initSampleData();
|
||||
loadTaskData();
|
||||
|
||||
// 设置搜索框
|
||||
mPinyinFormat = new HanyuPinyinOutputFormat();
|
||||
mPinyinFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
||||
mPinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||
|
||||
mSearchEditText = findViewById(R.id.et_search);
|
||||
mSearchEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
mSearchQuery = s.toString().trim().toLowerCase();
|
||||
filterTaskList();
|
||||
}
|
||||
});
|
||||
|
||||
// 设置 RecyclerView
|
||||
RecyclerView recyclerView = findViewById(R.id.task_scheduler_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));
|
||||
mAdapter = new TaskSchedulerAdapter(mTaskList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
// 设置悬浮按钮点击事件
|
||||
Button fabAddTask = findViewById(R.id.fab_add_task);
|
||||
fabAddTask.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showAddTaskDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,6 +117,52 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件加载任务数据
|
||||
*/
|
||||
private void loadTaskData() {
|
||||
boolean loadSuccess = TaskSchedulerBean.loadBeanList(this, mTaskList, TaskSchedulerBean.class);
|
||||
if (loadSuccess) {
|
||||
LogUtils.i(TAG, "loadTaskData: 成功加载 " + mTaskList.size() + " 条任务数据");
|
||||
} else {
|
||||
LogUtils.i(TAG, "loadTaskData: 未找到已保存的任务数据,使用空列表");
|
||||
}
|
||||
sortTaskList();
|
||||
}
|
||||
|
||||
private void applyChanges() {
|
||||
sortTaskList();
|
||||
filterTaskList();
|
||||
saveTaskData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存任务数据到文件
|
||||
*/
|
||||
private void saveTaskData() {
|
||||
boolean saveSuccess = TaskSchedulerBean.saveBeanList(this, mTaskList, TaskSchedulerBean.class);
|
||||
if (saveSuccess) {
|
||||
LogUtils.i(TAG, "saveTaskData: 成功保存 " + mTaskList.size() + " 条任务数据");
|
||||
} else {
|
||||
LogUtils.e(TAG, "saveTaskData: 任务数据保存失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按排档时间倒序排列列表
|
||||
*/
|
||||
private void sortTaskList() {
|
||||
Collections.sort(mTaskList, new Comparator<TaskSchedulerBean>() {
|
||||
@Override
|
||||
public int compare(TaskSchedulerBean a, TaskSchedulerBean b) {
|
||||
long diff = a.getCurrentScheduleTime() - b.getCurrentScheduleTime();
|
||||
if (diff > 0) return 1;
|
||||
if (diff < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间戳为年月日和小时
|
||||
* @param timestamp 时间戳
|
||||
@@ -129,13 +200,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();
|
||||
|
||||
@@ -165,6 +234,76 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
mTaskList.add(new TaskSchedulerBean("烹饪晚餐", "制作丰盛的晚餐", time17, 90));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将中文转换为拼音(不含声调,小写)
|
||||
*/
|
||||
private String toPinyin(String chinese) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < chinese.length(); i++) {
|
||||
char c = chinese.charAt(i);
|
||||
try {
|
||||
String[] pinyins = PinyinHelper.toHanyuPinyinStringArray(c, mPinyinFormat);
|
||||
if (pinyins != null && pinyins.length > 0) {
|
||||
sb.append(pinyins[0]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将中文转换为拼音首字母串(小写)
|
||||
*/
|
||||
private String toPinyinInitials(String chinese) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < chinese.length(); i++) {
|
||||
char c = chinese.charAt(i);
|
||||
try {
|
||||
String[] pinyins = PinyinHelper.toHanyuPinyinStringArray(c, mPinyinFormat);
|
||||
if (pinyins != null && pinyins.length > 0) {
|
||||
sb.append(pinyins[0].charAt(0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查任务名称是否匹配搜索关键词(支持中文/拼音/首字母)
|
||||
*/
|
||||
private boolean matchesSearch(TaskSchedulerBean task, String query) {
|
||||
if (query == null || query.isEmpty()) return true;
|
||||
String name = task.getTaskName();
|
||||
if (name == null) return false;
|
||||
if (name.toLowerCase().contains(query)) return true;
|
||||
String pinyin = toPinyin(name);
|
||||
if (pinyin.contains(query)) return true;
|
||||
String initials = toPinyinInitials(name);
|
||||
if (initials.contains(query)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据搜索关键词过滤任务列表并刷新界面
|
||||
*/
|
||||
private void filterTaskList() {
|
||||
if (mSearchQuery.isEmpty()) {
|
||||
mAdapter.setData(mTaskList);
|
||||
return;
|
||||
}
|
||||
ArrayList<TaskSchedulerBean> filteredList = new ArrayList<TaskSchedulerBean>();
|
||||
for (TaskSchedulerBean task : mTaskList) {
|
||||
if (matchesSearch(task, mSearchQuery)) {
|
||||
filteredList.add(task);
|
||||
}
|
||||
}
|
||||
mAdapter.setData(filteredList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将月、天、小时转换为总分钟数
|
||||
* @param month 月份
|
||||
@@ -220,7 +359,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);
|
||||
@@ -229,13 +367,12 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
final EditText etRemark = dialog.findViewById(R.id.dialog_et_remark);
|
||||
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
|
||||
Button btnSave = dialog.findViewById(R.id.dialog_btn_save);
|
||||
Button btnNow = dialog.findViewById(R.id.dialog_btn_now);
|
||||
|
||||
// 填充现有数据 - 将分钟转换为月、天、小时
|
||||
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 +390,17 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
etHour.setText(Integer.toString(hour));
|
||||
}
|
||||
|
||||
// 取消按钮
|
||||
btnNow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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);
|
||||
etCurrentScheduleTime.setText(formatTimestamp(calendar.getTimeInMillis()));
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -261,11 +408,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 +418,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,49 +427,243 @@ 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);
|
||||
applyChanges();
|
||||
LogUtils.i(TAG, "showEditTaskDialog: 任务 [" + taskName + "] 数据已更新,排档幅度=" + durationMinutes + "分钟");
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示添加任务对话框
|
||||
*/
|
||||
private void showAddTaskDialog() {
|
||||
final Dialog dialog = new Dialog(this);
|
||||
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);
|
||||
final EditText etDay = dialog.findViewById(R.id.dialog_et_day);
|
||||
final EditText etHour = dialog.findViewById(R.id.dialog_et_hour);
|
||||
final EditText etRemark = dialog.findViewById(R.id.dialog_et_remark);
|
||||
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
|
||||
Button btnSave = dialog.findViewById(R.id.dialog_btn_save);
|
||||
Button btnNow = dialog.findViewById(R.id.dialog_btn_now);
|
||||
|
||||
// 设置默认时间为当前时间
|
||||
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);
|
||||
etCurrentScheduleTime.setText(formatTimestamp(calendar.getTimeInMillis()));
|
||||
|
||||
btnNow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
java.util.Calendar cal = java.util.Calendar.getInstance();
|
||||
cal.set(java.util.Calendar.MINUTE, 0);
|
||||
cal.set(java.util.Calendar.SECOND, 0);
|
||||
cal.set(java.util.Calendar.MILLISECOND, 0);
|
||||
etCurrentScheduleTime.setText(formatTimestamp(cal.getTimeInMillis()));
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
String dayStr = etDay.getText().toString().trim();
|
||||
String hourStr = etHour.getText().toString().trim();
|
||||
String remark = etRemark.getText().toString().trim();
|
||||
|
||||
if (taskName.isEmpty()) {
|
||||
etTaskName.setError("请输入任务名称");
|
||||
return;
|
||||
}
|
||||
if (currentScheduleTime.isEmpty()) {
|
||||
etCurrentScheduleTime.setError("请输入当前排档时间");
|
||||
return;
|
||||
}
|
||||
|
||||
long timestamp = parseTimeString(currentScheduleTime);
|
||||
if (timestamp == 0) {
|
||||
etCurrentScheduleTime.setError("时间格式不正确,请使用 yyyy-MM-dd HH 格式");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
} catch (NumberFormatException e) {
|
||||
LogUtils.e(TAG, "showAddTaskDialog: 数字解析错误", e);
|
||||
return;
|
||||
}
|
||||
|
||||
int durationMinutes = convertToTotalMinutes(month, day, hour);
|
||||
TaskSchedulerBean newTask = new TaskSchedulerBean(taskName, remark, timestamp, durationMinutes);
|
||||
mTaskList.add(newTask);
|
||||
applyChanges();
|
||||
LogUtils.i(TAG, "showAddTaskDialog: 任务 [" + taskName + "] 已添加,排档幅度=" + durationMinutes + "分钟");
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示删除确认对话框
|
||||
* @param position 要删除的任务位置
|
||||
*/
|
||||
private void showDeleteConfirmDialog(final int position) {
|
||||
if (position < 0 || position >= mTaskList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TaskSchedulerBean task = mTaskList.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);
|
||||
}
|
||||
|
||||
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
|
||||
Button btnSave = dialog.findViewById(R.id.dialog_btn_save);
|
||||
|
||||
if (btnSave != null) {
|
||||
btnSave.setText("确定删除");
|
||||
}
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
btnSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String taskName = task.getTaskName();
|
||||
mTaskList.remove(position);
|
||||
applyChanges();
|
||||
LogUtils.i(TAG, "showDeleteConfirmDialog: 任务 [" + taskName + "] 已删除");
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示排档确认对话框
|
||||
* @param position 要排档的任务位置
|
||||
*/
|
||||
private void showScheduleConfirmDialog(final int position) {
|
||||
if (position < 0 || position >= mTaskList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TaskSchedulerBean task = mTaskList.get(position);
|
||||
long currentTime = task.getCurrentScheduleTime();
|
||||
int duration = task.getDurationMinutes();
|
||||
long newTime = currentTime + duration * 60 * 1000L;
|
||||
|
||||
final Dialog dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.dialog_schedule_confirm);
|
||||
|
||||
TextView tvTaskName = dialog.findViewById(R.id.dialog_schedule_task_name);
|
||||
TextView tvCurrentTime = dialog.findViewById(R.id.dialog_schedule_current_time);
|
||||
TextView tvDuration = dialog.findViewById(R.id.dialog_schedule_duration);
|
||||
TextView tvRemark = dialog.findViewById(R.id.dialog_schedule_remark);
|
||||
TextView tvNewTime = dialog.findViewById(R.id.dialog_schedule_new_time);
|
||||
Button btnCancel = dialog.findViewById(R.id.dialog_btn_cancel);
|
||||
Button btnConfirm = dialog.findViewById(R.id.dialog_btn_confirm);
|
||||
|
||||
tvTaskName.setText("任务:" + task.getTaskName());
|
||||
tvCurrentTime.setText("当前排档时间:" + formatTimestamp(currentTime));
|
||||
tvDuration.setText("排档幅度:" + formatDurationToString(duration));
|
||||
tvRemark.setText("备注:" + (task.getRemark() != null && !task.getRemark().isEmpty() ? task.getRemark() : "无"));
|
||||
tvNewTime.setText("排档后时间:" + formatTimestamp(newTime));
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
btnConfirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
performSchedule(position);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
@@ -338,22 +676,14 @@ 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);
|
||||
mAdapter.notifyItemChanged(position + 1);
|
||||
LogUtils.i(TAG, "performSchedule: 更新任务 [" + nextTask.getTaskName() + "] 时间更新为 " + formatTimestamp(newTime));
|
||||
}
|
||||
currentTask.setCurrentScheduleTime(newTime);
|
||||
applyChanges();
|
||||
LogUtils.i(TAG, "performSchedule: 更新任务 [" + currentTask.getTaskName() + "] 时间更新为 " + formatTimestamp(newTime));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,6 +697,11 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
mDataList = dataList;
|
||||
}
|
||||
|
||||
public void setData(ArrayList<TaskSchedulerBean> dataList) {
|
||||
mDataList = dataList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataList.size();
|
||||
@@ -379,26 +714,55 @@ 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,互不干扰
|
||||
long diffMs = item.getCurrentScheduleTime() - System.currentTimeMillis();
|
||||
int diffMinutes = (int) Math.abs(diffMs / 60000);
|
||||
if (diffMs >= 0) {
|
||||
viewHolder.mtvTimeDiff.setText("剩余" + formatDurationToString(diffMinutes));
|
||||
} else {
|
||||
viewHolder.mtvTimeDiff.setText("已过" + formatDurationToString(diffMinutes));
|
||||
}
|
||||
|
||||
if (item.getCurrentScheduleTime() <= System.currentTimeMillis()) {
|
||||
viewHolder.mllMain.setBackgroundResource(R.color.colorScheduleFutureBackground);
|
||||
} else {
|
||||
viewHolder.mllMain.setBackgroundResource(R.drawable.bg_frame);
|
||||
}
|
||||
|
||||
// 长按直接内置菜单,直接使用当前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) {
|
||||
// 使用PopupMenu替代ContextMenu
|
||||
PopupMenu popup = new PopupMenu(TaskSchedulerActivity.this, v);
|
||||
popup.getMenu().add("编辑任务内容");
|
||||
popup.getMenu().add("删除任务");
|
||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
String title = item.getTitle().toString();
|
||||
if ("编辑任务内容".equals(title)) {
|
||||
showEditTaskDialog(position);
|
||||
return true;
|
||||
} else if ("删除任务".equals(title)) {
|
||||
showDeleteConfirmDialog(position);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// 弹出菜单
|
||||
popup.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// 设置排档按钮点击事件
|
||||
viewHolder.mbtnSchedule.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
performSchedule(position);
|
||||
showScheduleConfirmDialog(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -412,6 +776,7 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
class TaskViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mtvTaskName;
|
||||
TextView mtvCurrentScheduleTime;
|
||||
TextView mtvTimeDiff;
|
||||
TextView mtvDuration;
|
||||
TextView mtvRemark;
|
||||
LinearLayout mllMain;
|
||||
@@ -421,6 +786,7 @@ public class TaskSchedulerActivity extends WinBoLLActivity {
|
||||
super(itemView);
|
||||
mtvTaskName = itemView.findViewById(R.id.item_task_name);
|
||||
mtvCurrentScheduleTime = itemView.findViewById(R.id.item_start_time);
|
||||
mtvTimeDiff = itemView.findViewById(R.id.item_time_diff);
|
||||
mtvDuration = itemView.findViewById(R.id.item_duration);
|
||||
mtvRemark = itemView.findViewById(R.id.item_remark);
|
||||
mllMain = itemView.findViewById(R.id.itemtaskscheduler_llmain);
|
||||
|
||||
@@ -1,22 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/task_scheduler_recycler_view"/>
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
</LinearLayout>
|
||||
<EditText
|
||||
android:id="@+id/et_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="搜索任务名称(支持中文/拼音)"
|
||||
android:padding="10dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:layout_margin="10dp"
|
||||
android:inputType="text"
|
||||
android:singleLine="true"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/task_scheduler_recycler_view"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/fab_add_task"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:background="@color/colorPrimaryDark"
|
||||
android:text="+"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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_schedule_task_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingBottom="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:paddingBottom="5dp"
|
||||
android:id="@+id/dialog_schedule_current_time"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:paddingBottom="5dp"
|
||||
android:id="@+id/dialog_schedule_duration"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:paddingBottom="5dp"
|
||||
android:id="@+id/dialog_schedule_remark"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:paddingTop="10dp"
|
||||
android:textStyle="bold"
|
||||
android:id="@+id/dialog_schedule_new_time"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="20dp"
|
||||
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>
|
||||
@@ -40,14 +40,30 @@
|
||||
android:paddingTop="15dp"
|
||||
android:paddingBottom="5dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dialog_et_start_time"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="例如:09:00"
|
||||
android:inputType="time"
|
||||
android:padding="10dp"
|
||||
android:background="@android:drawable/edit_text"/>
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dialog_et_start_time"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="例如:09:00"
|
||||
android:inputType="time"
|
||||
android:padding="10dp"
|
||||
android:background="@android:drawable/edit_text"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_btn_now"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="现在"
|
||||
android:layout_marginStart="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -44,36 +44,65 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginTop="5dp">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="排档时间:"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_start_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="排档幅度:"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/item_time_diff"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="排档时间:"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_start_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=" 排档幅度:"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_marginLeft="0dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||
android:textColor="#FF1976D2"
|
||||
android:layout_marginStart="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -20,4 +20,6 @@
|
||||
<!-- 基础颜色 -->
|
||||
<color name="white">#FFFFFF</color>
|
||||
<color name="black">#000000</color>
|
||||
<!-- 排档时间超过当前时间的列表项背景色 -->
|
||||
<color name="colorScheduleFutureBackground">#FFC8E6C9</color>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user