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

Commit

Permalink
优化 能量收取逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
TKaxv-7S committed Jun 17, 2024
1 parent 8894bb7 commit b41811b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdk 31
versionCode 71
versionName "1.2.5-test11-TK"
versionName "1.2.5-test12-TK"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@Getter
public enum ModelType {

DISABLE(0, "关闭"),
DISABLE(0, "已关闭"),

MODEL(1, "模块"),
MODEL(1, "已激活"),

PACKAGE(2, "内置"),
PACKAGE(2, "已加载"),

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class ViewAppInfo {

@Setter
@Getter
private static ModelType modelType = null;
private static ModelType modelType = ModelType.DISABLE;

public static void init(Context context) {
ViewAppInfo.context = context;
Expand Down Expand Up @@ -80,7 +80,11 @@ public static ModelType checkModleType() {
}

public static void setModelTypeByCode(Integer modelTypeCode) {
ViewAppInfo.modelType = ModelType.getByCode(modelTypeCode);
ModelType newModelType = ModelType.getByCode(modelTypeCode);
if (newModelType == null) {
newModelType = ModelType.DISABLE;
}
ViewAppInfo.modelType = newModelType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ public Runnable init() {

listFarmTool();

if (Config.INSTANCE.isRewardFriend())
if (Config.INSTANCE.isRewardFriend()) {
rewardFriend();
}

if (Config.INSTANCE.isSendBackAnimal())
if (Config.INSTANCE.isSendBackAnimal()) {
sendBackAnimal();
}

if (!AnimalInteractStatus.HOME.name().equals(ownerAnimal.animalInteractStatus)) {
if ("ORCHARD".equals(ownerAnimal.locationType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ public static RpcEntity getCollectEnergyRpcEntity(String bizType, String userId,
return new RpcEntity("alipay.antmember.forest.h5.collectEnergy", args1);
}

public static String collectEnergy(String bizType, String userId, long bubbleId) {
public static String collectEnergy(String bizType, String userId, Long bubbleId) {
return ApplicationHook.requestString(getCollectEnergyRpcEntity(bizType, userId, bubbleId));
}

public static RpcEntity getCollectBatchEnergyRpcEntity(String userId, List<String> bubbleId) {
return new RpcEntity("alipay.antmember.forest.h5.collectEnergy", "[{\"bizType\":\"\",\"bubbleIds\":[" + String.join(",", bubbleId)
public static RpcEntity getCollectBatchEnergyRpcEntity(String userId, List<Long> bubbleIdList) {
return new RpcEntity("alipay.antmember.forest.h5.collectEnergy", "[{\"bizType\":\"\",\"bubbleIds\":[" + StringUtil.collectionJoinString(",", bubbleIdList)
+ "],\"fromAct\":\"BATCH_ROB_ENERGY\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\",\"userId\":\"" + userId + "\",\"version\":\""
+ VERSION + "\"}]");
}

public static String collectBatchEnergy(String userId, List<String> bubbleId) {
public static String collectBatchEnergy(String userId, List<Long> bubbleId) {
return ApplicationHook.requestString(getCollectBatchEnergyRpcEntity(userId, bubbleId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -367,17 +368,13 @@ private void collectUserEnergy(String userId) {

String bizNo = userHomeObject.getString("bizNo");
JSONArray jaBubbles = userHomeObject.getJSONArray("bubbles");
List<String> batchIdList = new ArrayList<>();
List<Long> bubbleIdList = new ArrayList<>();
for (int i = 0; i < jaBubbles.length(); i++) {
JSONObject bubble = jaBubbles.getJSONObject(i);
long bubbleId = bubble.getLong("id");
switch (CollectStatus.valueOf(bubble.getString("collectStatus"))) {
case AVAILABLE:
if (batchRobEnergy.getValue() && jaBubbles.length() < 7) {
batchIdList.add(String.valueOf(bubbleId));
} else {
collectUserEnergy(userId, bubbleId, bizNo);
}
bubbleIdList.add(bubbleId);
break;
case WAITING:
long produceTime = bubble.getLong("produceTime");
Expand All @@ -394,8 +391,26 @@ private void collectUserEnergy(String userId) {
}
}
if (batchRobEnergy.getValue()) {
if (!batchIdList.isEmpty()) {
collectUserBatchEnergy(userId, batchIdList);
Iterator<Long> iterator = bubbleIdList.iterator();
List<Long> batchBubbleIdList = new ArrayList<>();
while (iterator.hasNext()) {
batchBubbleIdList.add(iterator.next());
if (batchBubbleIdList.size() >= 6) {
collectUserBatchEnergy(userId, batchBubbleIdList);
batchBubbleIdList = new ArrayList<>();
}
}
int size = batchBubbleIdList.size();
if (size > 0) {
if (size == 1) {
collectUserEnergy(userId, batchBubbleIdList.get(0), bizNo);
} else {
collectUserBatchEnergy(userId, batchBubbleIdList);
}
}
} else {
for (Long bubbleId : bubbleIdList) {
collectUserEnergy(userId, bubbleId, bizNo);
}
}

Expand Down Expand Up @@ -663,7 +678,7 @@ private void collectUserEnergy(String userId, long bubbleId, String bizNo) {
});
}

private void collectUserBatchEnergy(String userId, final List<String> bubbleId) {
private void collectUserBatchEnergy(String userId, final List<Long> bubbleIdList) {
collectEnergyThreadPoolExecutor.execute(() -> {
synchronized (collectEnergyLockObj) {
try {
Expand All @@ -672,9 +687,9 @@ private void collectUserBatchEnergy(String userId, final List<String> bubbleId)
useDoubleCard();
}
RpcEntity rpcEntity;
List<String> bubbleList = bubbleId;
List<Long> doBubbleIdList = bubbleIdList;
do {
rpcEntity = AntForestRpcCall.getCollectBatchEnergyRpcEntity(userId, bubbleList);
rpcEntity = AntForestRpcCall.getCollectBatchEnergyRpcEntity(userId, doBubbleIdList);
ApplicationHook.requestObject(rpcEntity);
if (rpcEntity.getHasError()) {
break;
Expand All @@ -687,11 +702,11 @@ private void collectUserBatchEnergy(String userId, final List<String> bubbleId)
return;
}
JSONArray jaBubbles = jo.getJSONArray("bubbles");
List<String> newBubbleId = new ArrayList<>();
List<Long> newBubbleIdList = new ArrayList<>();
for (int i = 0; i < jaBubbles.length(); i++) {
JSONObject bubble = jaBubbles.getJSONObject(i);
if (bubble.getBoolean("canBeRobbedAgain")) {
newBubbleId.add(String.valueOf(bubble.getLong("id")));
newBubbleIdList.add(bubble.getLong("id"));
}
collected += bubble.getInt("collectedEnergy");
}
Expand All @@ -703,10 +718,10 @@ private void collectUserBatchEnergy(String userId, final List<String> bubbleId)
totalCollected += collected;
Statistics.addData(Statistics.DataType.COLLECTED, collected);
} else {
Log.record("一键收取[" + UserIdMap.getNameById(userId) + "]的能量失败" + " " + ",UserID:" + userId + ",BubbleId:" + newBubbleId);
Log.record("一键收取[" + UserIdMap.getNameById(userId) + "]的能量失败" + " " + ",UserID:" + userId + ",BubbleId:" + newBubbleIdList);
}
if (!newBubbleId.isEmpty()) {
bubbleList = newBubbleId;
if (!newBubbleIdList.isEmpty()) {
doBubbleIdList = newBubbleIdList;
isDouble = true;
continue;
}
Expand Down Expand Up @@ -1785,7 +1800,6 @@ private static void queryAnimalAndPiece(boolean canConsumeProp) {
jo = animalProps.getJSONObject(i);
JSONObject animal = jo.getJSONObject("animal");
int id = animal.getInt("id");
String name = animal.getString("name");
if (canConsumeProp && Config.INSTANCE.isAnimalConsumeProp()) {
JSONObject main = jo.optJSONObject("main");
if (main != null && main.optInt("holdsNum", 0) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
tvStatistics = findViewById(R.id.tv_statistics);
ViewAppInfo.init(getApplicationContext());
ModelType modelType = ViewAppInfo.getModelType();
if (modelType == null) {
modelType = ModelType.DISABLE;
}
updateTitle(ViewAppInfo.getModelType());
viewHandler = new Handler();
titleRunner = () -> updateTitle(ModelType.DISABLE);
updateTitle(modelType);
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ModelType modelType = ViewAppInfo.getModelType();
if (modelType == null) {
if (ModelType.DISABLE == ViewAppInfo.getModelType()) {
updateTitle(ModelType.PACKAGE);
}
viewHandler.removeCallbacks(titleRunner);
Expand Down Expand Up @@ -123,8 +118,7 @@ public void run() {
@Override
protected void onResume() {
super.onResume();
ModelType modelType = ViewAppInfo.getModelType();
if (modelType == null || ModelType.DISABLE == modelType) {
if (ModelType.DISABLE == ViewAppInfo.getModelType()) {
viewHandler.postDelayed(titleRunner, 3000);
try {
sendBroadcast(new Intent("com.eg.android.AlipayGphone.xqe.status"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ public static Config defInit() {
c.totalCertCount = false;

c.enableFarm = true;
c.rewardFriend = true;
c.rewardFriend = false;
c.sendBackAnimal = true;
c.sendType = SendType.HIT;
c.sendType = SendType.NORMAL;
if (c.dontSendFriendList == null)
c.dontSendFriendList = new ArrayList<>();
c.recallAnimalType = RecallAnimalType.ALWAYS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
package pansong291.xposed.quickenergy.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;

public class StringUtil {
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
return str == null || str.isEmpty();
}

public static String collectionJoinString(CharSequence conjunction, Collection<?> collection) {
if (!collection.isEmpty()) {
StringBuilder b = new StringBuilder();
Iterator<?> iterator = collection.iterator();
b.append(toStringOrEmpty(iterator.next()));
while (iterator.hasNext()) {
b.append(conjunction).append(toStringOrEmpty(iterator.next()));
}
return b.toString();
}
return "";
}

public static String arrayJoinString(CharSequence conjunction, Object... array) {
int length = array.length;
if (length > 0) {
StringBuilder b = new StringBuilder();
b.append(toStringOrEmpty(array[0]));
for (int i = 1; i < length; i++) {
b.append(conjunction).append(toStringOrEmpty(array[i]));
}
return b.toString();
}
return "";
}

public static String arrayToString(Object... array) {
return arrayJoinString(",", array);
}

private static String toStringOrEmpty(Object obj) {
return Objects.toString(obj, "");
}

public static String padLeft(int str, int totalWidth, char padChar) {
Expand Down

0 comments on commit b41811b

Please sign in to comment.