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 4, 2024
2 parents 2b41cf8 + 4144406 commit cccfa0c
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 48 deletions.
24 changes: 12 additions & 12 deletions app/src/main/java/tkaxv7s/xposed/sesame/data/ConfigV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ public <T extends ModelField> T getModelFieldExt(String modelCode, String fieldC
return (T) getModelField(modelCode, fieldCode);
}*/

public void reset() {
for (ModelFields modelFields : modelFieldsMap.values()) {
for (ModelField modelField : modelFields.values()) {
if (modelField != null) {
modelField.reset();
}
}
}
}

public static Boolean isModify(String userId) {
String json = null;
File configV2File;
Expand Down Expand Up @@ -194,7 +184,7 @@ public static synchronized ConfigV2 load(String userId) {
Log.system(TAG, "复制新配置: " + userName);
FileUtil.write2File(json, configV2File);
} else {
INSTANCE.reset();
unload();
Log.i(TAG, "初始新配置: " + userName);
Log.system(TAG, "初始新配置: " + userName);
FileUtil.write2File(JsonUtil.toJsonString(INSTANCE), configV2File);
Expand All @@ -205,7 +195,7 @@ public static synchronized ConfigV2 load(String userId) {
Log.i(TAG, "重置配置: " + userName);
Log.system(TAG, "重置配置: " + userName);
try {
INSTANCE.reset();
unload();
if (configV2File != null) {
FileUtil.write2File(JsonUtil.toJsonString(INSTANCE), configV2File);
}
Expand All @@ -218,4 +208,14 @@ public static synchronized ConfigV2 load(String userId) {
return INSTANCE;
}

public static synchronized void unload() {
for (ModelFields modelFields : INSTANCE.modelFieldsMap.values()) {
for (ModelField modelField : modelFields.values()) {
if (modelField != null) {
modelField.reset();
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public synchronized Boolean startTask(Boolean force) {

public synchronized void stopTask() {
for (ThreadPoolExecutor childThreadPool : childGroupThreadPoolMap.values()) {
ThreadUtil.shutdownAndAwaitTermination(childThreadPool, 10, TimeUnit.SECONDS);
ThreadUtil.shutdownAndAwaitTermination(childThreadPool, 3, TimeUnit.SECONDS);
}
childGroupThreadPoolMap.clear();
childTaskMap.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,13 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
private static void destroyHandler(Boolean force) {
try {
if (force) {
ModelTask.destroyAllModel();
if (context != null) {
stopHandler();
BaseModel.destroyData();
Status.unload();
Statistics.unload();
ConfigV2.unload();
ModelTask.destroyAllModel();
}
if (rpcResponseUnhook != null) {
rpcResponseUnhook.unhook();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void run() {
return;
}
try {
UserIdMap.clear();
UserIdMap.unload();
String selfId = ApplicationHook.getUserId();
Class<?> clsUserIndependentCache = loader.loadClass("com.alipay.mobile.socialcommonsdk.bizdata.UserIndependentCache");
Class<?> clsAliAccountDaoOp = loader.loadClass("com.alipay.mobile.socialcommonsdk.bizdata.contact.data.AliAccountDaoOp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public String getName() {

private final BooleanModelField cooperateWater = new BooleanModelField("cooperateWater", "合种浇水", false);
private final SelectModelField cooperateWaterList = new SelectModelField("cooperateWaterList", "合种浇水列表", new KVNode<>(new LinkedHashMap<>(), true), CooperateUser::getList);

private final SelectModelField cooperateWaterTotalLimitList = new SelectModelField("cooperateWaterTotalLimitList", "浇水总量限制列表", new KVNode<>(new LinkedHashMap<>(), true), CooperateUser::getList);
@Override
public ModelFields getFields() {
ModelFields modelFields = new ModelFields();
modelFields.addField(cooperateWater);
modelFields.addField(cooperateWaterList);
modelFields.addField(cooperateWaterTotalLimitList);
return modelFields;
}

Expand Down Expand Up @@ -60,16 +61,24 @@ public void run() {
String name = jo.getString("name");
int waterDayLimit = jo.getInt("waterDayLimit");
CooperationIdMap.add(cooperationId, name);
if (!Status.canCooperateWaterToday(UserIdMap.getCurrentUid(), cooperationId))
if (!Status.canCooperateWaterToday(UserIdMap.getCurrentUid(), cooperationId)) {
continue;
}
Integer num = cooperateWaterList.getValue().getKey().get(cooperationId);
if (num != null) {
if (num > waterDayLimit)
Integer limitNum = cooperateWaterTotalLimitList.getValue().getKey().get(cooperationId);
if (limitNum != null) {
num = calculatedWaterNum(UserIdMap.getCurrentUid(), cooperationId, num, limitNum);
}
if (num > waterDayLimit) {
num = waterDayLimit;
if (num > userCurrentEnergy)
}
if (num > userCurrentEnergy) {
num = userCurrentEnergy;
if (num > 0)
}
if (num > 0) {
cooperateWater(UserIdMap.getCurrentUid(), cooperationId, num, name);
}
}
}
} else {
Expand All @@ -96,7 +105,35 @@ private static void cooperateWater(String uid, String coopId, int count, String
} catch (Throwable t) {
Log.i(TAG, "cooperateWater err:");
Log.printStackTrace(TAG, t);
} finally {
TimeUtil.sleep(500);
}
}

private static int calculatedWaterNum(String uid, String coopId, int num, int limitNum) {
try{
String s = AntCooperateRpcCall.queryCooperateRank("A", coopId);
JSONObject jo = new JSONObject(s);
if (jo.optBoolean("success", false)) {
JSONArray jaList = jo.getJSONArray("cooperateRankInfos");
for (int i = 0; i < jaList.length(); i++) {
JSONObject joItem = jaList.getJSONObject(i);
String userId = joItem.getString("userId");
if (userId.equals(uid)) {
int energySummation = joItem.optInt("energySummation", 0);
if (num > limitNum - energySummation) {
num = limitNum - energySummation;
break;
}
}
}
}
} catch (Throwable t) {
Log.i(TAG, "calculatedWaterNum err:");
Log.printStackTrace(TAG, t);
} finally {
return num;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ public static String cooperateWater(String uid, String coopId, int count) {
+ "\"}]");
}

/**
* 获取合种浇水量排行
* @param bizType 参数:D/A,“D”为查询当天,“A”为查询所有
* @param coopId 合种ID
* @return
*/
public static String queryCooperateRank(String bizType, String coopId) {
return ApplicationHook.requestString("alipay.antmember.forest.h5.queryCooperateRank",
"[{\"bizType\":\""+ bizType + "\",\"cooperationId\":\"" + coopId + "\",\"source\":\"chInfo_ch_url-https://render.alipay.com/p/yuyan/180020010001247580/home.html\"}]");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,8 @@ public void run() {
harvestProduce(ownerFarmId);
}

if (donation.getValue() && harvestBenevolenceScore >= 1) {
Integer donationCountValue = donationCount.getValue();
if (donationCountValue == DonationCount.ALL || Status.canDonationEgg(userId)) {
handleDonation(donationCountValue);
}
if (donation.getValue() && Status.canDonationEgg(userId) && harvestBenevolenceScore >= 1) {
handleDonation(donationCount.getValue());
}

if (answerQuestion.getValue() && Status.canAnswerQuestionToday(UserIdMap.getCurrentUid())) {
Expand Down Expand Up @@ -296,19 +293,21 @@ public void run() {
enterFarm();
}

try {
Long startEatTime = ownerAnimal.startEatTime;
double allFoodHaveEatten = 0d;
double allConsumeSpeed = 0d;
for (Animal animal : animals) {
allFoodHaveEatten += animal.foodHaveEatten;
allConsumeSpeed += animal.consumeSpeed;
if (feedAnimal.getValue()) {
try {
Long startEatTime = ownerAnimal.startEatTime;
double allFoodHaveEatten = 0d;
double allConsumeSpeed = 0d;
for (Animal animal : animals) {
allFoodHaveEatten += animal.foodHaveEatten;
allConsumeSpeed += animal.consumeSpeed;
}
long nextFeedTime = startEatTime + (long) ((180 - (allFoodHaveEatten)) / (allConsumeSpeed)) * 1000;
addChildTask(new ChildModelTask("FA|" + ownerFarmId, "FA", () -> feedAnimal(ownerFarmId), nextFeedTime));
Log.record("添加蹲点投喂🥣[" + UserIdMap.getCurrentMaskName() + "]在[" + DateFormat.getDateTimeInstance().format(nextFeedTime) + "]执行");
} catch (Exception e) {
Log.printStackTrace(e);
}
long nextFeedTime = startEatTime + (long) ((180 - (allFoodHaveEatten)) / (allConsumeSpeed)) * 1000;
addChildTask(new ChildModelTask("FA|" + ownerFarmId, "FA", () -> feedAnimal(ownerFarmId), nextFeedTime));
Log.record("添加蹲点投喂🥣[" + UserIdMap.getCurrentMaskName() + "]在[" + DateFormat.getDateTimeInstance().format(nextFeedTime) + "]执行");
} catch (Exception e) {
Log.printStackTrace(e);
}

if (unreceiveTaskAward > 0) {
Expand Down Expand Up @@ -637,19 +636,23 @@ private void handleDonation(int donationType) {
if ("SUCCESS".equals(memo)) {
JSONArray jaActivityInfos = jo.getJSONArray("activityInfos");
String activityId = null, activityName = null;
boolean isDonation = false;
for (int i = 0; i < jaActivityInfos.length(); i++) {
jo = jaActivityInfos.getJSONObject(i);
if (!jo.get("donationTotal").equals(jo.get("donationLimit"))) {
activityId = jo.getString("activityId");
activityName = jo.optString("projectName", activityId);
if (performDonation(activityId, activityName)) {
isDonation = true;
if (donationType == DonationCount.ONE) {
Status.donationEgg(userId);
break;
}
}
}
}
if (isDonation) {
Status.donationEgg(userId);
}
if (activityId == null) {
Log.record("今日已无可捐赠的活动");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ private void collectEnergy(CollectEnergyEntity collectEnergyEntity, Boolean join
Log.i(TAG, "collectUserBatchEnergy err:");
Log.printStackTrace(TAG, e);
} finally {
NotificationUtil.updateLastExecText("收:" + totalCollected + "帮:" + totalHelpCollected);
NotificationUtil.updateLastExecText("收:" + totalCollected + " 帮:" + totalHelpCollected);
notifyMain();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public static Map<String, String> getMap() {
return readOnlyIdMap;
}

public synchronized static void add(String key, String value) {
public static synchronized void add(String key, String value) {
idMap.put(key, value);
}

public synchronized static void remove(String key) {
public static synchronized void remove(String key) {
idMap.remove(key);
}

public synchronized static void load(String userId) {
public static synchronized void load(String userId) {
idMap.clear();
try {
String body = FileUtil.readFromFile(FileUtil.getCooperationIdMapFile(userId));
Expand All @@ -38,7 +38,7 @@ public synchronized static void load(String userId) {
}
}

public synchronized static boolean save(String userId) {
public static synchronized boolean save(String userId) {
return FileUtil.write2File(JsonUtil.toNoFormatJsonString(idMap), FileUtil.getCooperationIdMapFile(userId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void shutdownAndAwaitTermination(ExecutorService pool, long timeou
if (pool != null && !pool.isShutdown()) {
pool.shutdown();
try {
if (!pool.awaitTermination(3, TimeUnit.SECONDS)) {
if (!pool.awaitTermination(1, TimeUnit.SECONDS)) {
pool.shutdownNow();
if (!pool.awaitTermination(timeout, unit)) {
Log.i(TAG, "thread pool can't close");
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/tkaxv7s/xposed/sesame/util/UserIdMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public synchronized static void load(String userId) {
}
}

public synchronized static void unload() {
userMap.clear();
}

public synchronized static boolean save(String userId) {
return FileUtil.write2File(JsonUtil.toNoFormatJsonString(userMap), FileUtil.getFriendIdMapFile(userId));
}
Expand All @@ -119,8 +123,4 @@ public synchronized static boolean saveSelf(UserEntity userEntity) {
return FileUtil.write2File(JsonUtil.toNoFormatJsonString(userEntity), FileUtil.getSelfIdFile(userEntity.getUserId()));
}

public synchronized static void clear() {
userMap.clear();
}

}

0 comments on commit cccfa0c

Please sign in to comment.