Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
TKaxv-7S committed Jul 6, 2024
2 parents e56fcbe + 6784015 commit 4becd6d
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public synchronized void stopTask() {
Log.printStackTrace(e);
}
}
childTaskExecutor.clearAllChildTask();
if (childTaskExecutor != null) {
childTaskExecutor.clearAllChildTask();
}
childTaskMap.clear();
MAIN_THREAD_POOL.remove(mainRunnable);
MAIN_TASK_MAP.remove(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public Boolean addChildTask(ModelTask.ChildModelTask childTask) {
long time = childTask.getExecTime();
if (time > 0) {
future = threadPoolExecutor.submit(() -> {
if (childTask.getIsCancel()) {
return;
}
//String modelTaskId = getName();
//Log.i("任务模块:" + modelTaskId + " 添加子任务:" + id);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,43 @@ public SystemChildTaskExecutor() {
@Override
public Boolean addChildTask(ModelTask.ChildModelTask childTask) {
ThreadPoolExecutor threadPoolExecutor = getChildGroupHandler(childTask.getGroup());
Runnable runnable = () -> {
//String modelTaskId = getName();
//Log.i("任务模块:" + modelTaskId + " 添加子任务:" + id);
long execTime = childTask.getExecTime();
if (execTime > 0) {
Runnable runnable = () -> {
if (childTask.getIsCancel()) {
return;
}
//String modelTaskId = getName();
//Log.i("任务模块:" + modelTaskId + " 添加子任务:" + id);
Future<?> future = threadPoolExecutor.submit(() -> {
try {
childTask.run();
} catch (Exception e) {
Log.printStackTrace(e);
//Log.record("任务模块:" + modelTaskId + " 异常子任务:" + id);
} finally {
childTask.getModelTask().removeChildTask(childTask.getId());
//Log.i("任务模块:" + modelTaskId + " 移除子任务:" + id);
}
});
childTask.setCancelTask(() -> future.cancel(true));
};
childTask.setCancelTask(() -> handler.removeCallbacks(runnable));
handler.postDelayed(runnable, execTime - System.currentTimeMillis());
} else {
Future<?> future = threadPoolExecutor.submit(() -> {
//Log.i("任务模块:" + modelTaskId + " 添加子任务:" + id);
try {
childTask.run();
} catch (Exception e) {
Log.printStackTrace(e);
//Log.record("任务模块:" + modelTaskId + " 异常子任务:" + id);
//Log.record("任务模块:" + getName() + " 异常子任务:" + childTask.getId());
} finally {
childTask.getModelTask().removeChildTask(childTask.getId());
//Log.i("任务模块:" + modelTaskId + " 移除子任务:" + id);
}
});
childTask.setCancelTask(() -> future.cancel(true));
};
childTask.setCancelTask(() -> handler.removeCallbacks(runnable));
long execTime = childTask.getExecTime();
if (execTime > 0) {
handler.postDelayed(runnable, execTime - System.currentTimeMillis());
} else {
handler.post(runnable);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tkaxv7s.xposed.sesame.model.base;

import tkaxv7s.xposed.sesame.model.normal.base.BaseModel;
import tkaxv7s.xposed.sesame.util.TimeUtil;

public class TaskCommon {
Expand All @@ -10,8 +11,7 @@ public class TaskCommon {

public static void update() {
long currentTimeMillis = System.currentTimeMillis();
IS_ENERGY_TIME = (TimeUtil.isAfterOrCompareTimeStr(currentTimeMillis, "00") && TimeUtil.isBeforeOrCompareTimeStr(currentTimeMillis, "0005"))
|| (TimeUtil.isAfterOrCompareTimeStr(currentTimeMillis, "0700") && TimeUtil.isBeforeOrCompareTimeStr(currentTimeMillis, "0730"));
IS_ENERGY_TIME = TimeUtil.checkInTimeRange(currentTimeMillis, BaseModel.getEnergyTime().getValue());
IS_AFTER_8AM = TimeUtil.isAfterOrCompareTimeStr(currentTimeMillis, "0800");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class BaseModel extends Model {
@Getter
private static final ListModelField.ListJoinCommaToStringModelField wakenAtTimeList = new ListModelField.ListJoinCommaToStringModelField("wakenAtTimeList", "定时唤醒(关闭:-1)", ListUtil.newArrayList("0650", "2350"));
@Getter
private static final ListModelField.ListJoinCommaToStringModelField energyTime = new ListModelField.ListJoinCommaToStringModelField("energyTime", "只收能量时间(范围)", ListUtil.newArrayList("0700-0731"));
@Getter
private static final ChoiceModelField timedTaskModel = new ChoiceModelField("timedTaskModel", "定时任务模式", TimedTaskModel.SYSTEM, TimedTaskModel.nickNames);
@Getter
private static final BooleanModelField timeoutRestart = new BooleanModelField("timeoutRestart", "超时重启", true);
Expand Down Expand Up @@ -66,6 +68,7 @@ public ModelFields getFields() {
modelFields.addField(checkInterval);
modelFields.addField(execAtTimeList);
modelFields.addField(wakenAtTimeList);
modelFields.addField(energyTime);
modelFields.addField(timedTaskModel);
modelFields.addField(timeoutRestart);
modelFields.addField(waitWhenException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ public ModelFields getFields() {
modelFields.addField(dontCollectList = new SelectModelField("dontCollectList", "不收取能量列表", new KVNode<>(new LinkedHashMap<>(), false), AlipayUser::getList));
modelFields.addField(doubleCard = new BooleanModelField("doubleCard", "双击卡 | 使用", false));
modelFields.addField(doubleCountLimit = new IntegerModelField("doubleCountLimit", "双击卡 | 使用次数", 6));
List<String> doubleCardTimeList = new ArrayList<>();
doubleCardTimeList.add("0700-0730");
modelFields.addField(doubleCardTime = new ListModelField.ListJoinCommaToStringModelField("doubleCardTime", "双击卡 | 使用时间(范围)", doubleCardTimeList));
modelFields.addField(doubleCardTime = new ListModelField.ListJoinCommaToStringModelField("doubleCardTime", "双击卡 | 使用时间(范围)", ListUtil.newArrayList("0700-0730")));
modelFields.addField(returnWater10 = new IntegerModelField("returnWater10", "返水 | 10克需收能量(关闭:0)", 0));
modelFields.addField(returnWater18 = new IntegerModelField("returnWater18", "返水 | 18克需收能量(关闭:0)", 0));
modelFields.addField(returnWater33 = new IntegerModelField("returnWater33", "返水 | 33克需收能量(关闭:0)", 0));
Expand Down Expand Up @@ -317,11 +315,11 @@ public void run() {
try {
synchronized (AntForestV2.this) {
int count = taskCount.get();
if (count > 10) {
if (count > 0) {
AntForestV2.this.wait(TimeUnit.MINUTES.toMillis(30));
count = taskCount.get();
}
if (count > 10) {
if (count > 0) {
Log.record("执行超时-蚂蚁森林");
} else if (count == 0) {
Log.record("执行结束-蚂蚁森林");
Expand Down Expand Up @@ -1690,12 +1688,7 @@ private void useDoubleCard() {

private boolean hasDoubleCardTime() {
long currentTimeMillis = System.currentTimeMillis();
for (String doubleTime : doubleCardTime.getValue()) {
if (TimeUtil.checkInTimeRange(currentTimeMillis, doubleTime)) {
return true;
}
}
return false;
return TimeUtil.checkInTimeRange(currentTimeMillis, doubleCardTime.getValue());
}

/* 赠送道具 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ protected void afterHookedMethod(MethodHookParam param) {
int originStep = (Integer) param.getResult();
int step = tmpStepCount();
if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 6 || originStep >= step) {
Log.other("当前步数🏃🏻‍♂️[" + originStep + "步],无需同步");
return;
}
param.setResult(step);

}
});
Log.i(TAG, "hook readDailyStep successfully");
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/tkaxv7s/xposed/sesame/util/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public static synchronized void save(Calendar nowCalendar) {
}

public static Boolean updateDay(Calendar nowCalendar) {
if (TimeUtil.isLessThanNowOfDays(nowCalendar.getTimeInMillis())) {
if (TimeUtil.isLessThanSecondOfDays(INSTANCE.saveTime, nowCalendar.getTimeInMillis())) {
Status.unload();
return true;
} else {
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/tkaxv7s/xposed/sesame/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
* @author Constanline
Expand All @@ -14,6 +15,15 @@ public static Boolean checkNowInTimeRange(String timeRange) {
return checkInTimeRange(System.currentTimeMillis(), timeRange);
}

public static Boolean checkInTimeRange(Long timeMillis, List<String> timeRangeList) {
for (String timeRange : timeRangeList) {
if (checkInTimeRange(timeMillis, timeRange)) {
return true;
}
}
return false;
}

public static Boolean checkInTimeRange(Long timeMillis, String timeRange) {
try {
String[] timeRangeArray = timeRange.split("-");
Expand Down Expand Up @@ -188,10 +198,7 @@ public static boolean isLessThanSecondOfDays(Long firstdTimestamp, Long secondTi
final long day = 24 * 60 * 60 * 1000;
firstdTimestamp = firstdTimestamp + gmt8;
secondTimestamp = secondTimestamp + gmt8;
if (firstdTimestamp / day < secondTimestamp / day) {
return true;
}
return false;
return firstdTimestamp / day < secondTimestamp / day;
}

/**
Expand Down

0 comments on commit 4becd6d

Please sign in to comment.