Skip to content

Commit

Permalink
合并了来自cwj851的pr。增加了配置、统计变动的记录,修复了不开启“7点启动”依然会激活的bug,关闭了onGoing。
Browse files Browse the repository at this point in the history
  • Loading branch information
constanline committed Aug 15, 2023
1 parent 0145467 commit cb823af
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 214 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdk 21
//noinspection ExpiredTargetSdkVersion
targetSdk 29
versionCode 48
versionName "1.1.0"
versionCode 50
versionName "1.1.1"
}
buildTypes {
release {
Expand Down
83 changes: 77 additions & 6 deletions app/src/main/java/pansong291/xposed/quickenergy/AntForest.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ private static void updateDoubleTime(JSONObject joHomePage) throws JSONException

private static void canCollectSelfEnergy(int times) {
try {
boolean hasMore = false;
long start = System.currentTimeMillis();
String s = AntForestRpcCall.queryHomePage();
long end = System.currentTimeMillis();
Expand Down Expand Up @@ -390,6 +391,56 @@ private static void canCollectSelfEnergy(int times) {
}
Thread.sleep(1000L);
}
if (wateringBubbles.length() >= 20)
hasMore = true;
}
}
if (Config.collectProp()) {
JSONArray givenProps = joHomePage.has("givenProps")
? joHomePage.getJSONArray("givenProps")
: new JSONArray();
if (givenProps.length() > 0) {
for (int i = 0; i < givenProps.length(); i++) {
JSONObject jo = givenProps.getJSONObject(i);
String giveConfigId = jo.getString("giveConfigId");
String giveId = jo.getString("giveId");
String propName = jo.getJSONObject("propConfig").getString("propName");
jo = new JSONObject(AntForestRpcCall.collectProp(giveConfigId, giveId));
if ("SUCCESS".equals(jo.getString("resultCode"))) {
Log.forest("领取道具🎭[" + propName + "g]");
} else {
Log.recordLog("领取道具失败:" + jo.getString("resultDesc"), jo.toString());
}
Thread.sleep(1000L);
}
if (givenProps.length() >= 20)
hasMore = true;
}
}
if (hasMore)
canCollectSelfEnergy(times);
JSONArray usingUserProps = joHomePage.has("usingUserProps")
? joHomePage.getJSONArray("usingUserProps")
: new JSONArray();
if (usingUserProps.length() > 0) {
for (int i = 0; i < usingUserProps.length(); i++) {
JSONObject jo = usingUserProps.getJSONObject(i);
if (!"animal".equals(jo.getString("type")))
continue;
JSONObject extInfo = new JSONObject(jo.getString("extInfo"));
int energy = extInfo.optInt("energy", 0);
if (energy > 0 && !extInfo.optBoolean("isCollected")) {
String propId = jo.getString("propSeq");
String propType = jo.getString("propType");
String shortDay = extInfo.getString("shortDay");
jo = new JSONObject(AntForestRpcCall.collectAnimalRobEnergy(propId, propType, shortDay));
if ("SUCCESS".equals(jo.getString("resultCode"))) {
Log.forest("动物能量🦩[" + energy + "g]");
} else {
Log.recordLog("收取动物能量失败:" + jo.getString("resultDesc"), jo.toString());
}
break;
}
}
}
} else {
Expand Down Expand Up @@ -751,6 +802,26 @@ private static void receiveTaskAward() {
} else {
Log.recordLog("完成任务失败," + taskTitle);
}
} else if ("DAKA_GROUP".equals(taskType)) {
JSONArray childTaskTypeList = taskInfo.getJSONArray("childTaskTypeList");
taskInfo = childTaskTypeList.getJSONObject(0);
taskBaseInfo = taskInfo.getJSONObject("taskBaseInfo");
bizInfo = new JSONObject(taskBaseInfo.getString("bizInfo"));
taskType = taskBaseInfo.getString("taskType");
taskTitle = bizInfo.optString("taskTitle", taskType);
sceneCode = taskBaseInfo.getString("sceneCode");
taskStatus = taskBaseInfo.getString("taskStatus");
if (TaskStatus.TODO.name().equals(taskStatus)) {
if (bizInfo.optBoolean("autoCompleteTask")) {
JSONObject joFinishTask = new JSONObject(
AntForestRpcCall.finishTask(sceneCode, taskType));
if (joFinishTask.getBoolean("success")) {
Log.forest("完成打卡🧾️[" + taskTitle + "]");
} else {
Log.recordLog("完成打卡失败," + taskTitle);
}
}
}
}
}
}
Expand Down Expand Up @@ -942,12 +1013,12 @@ private static void giveProp(String targetUserId) {
if (forestPropVOList.length() > 0) {
jo = forestPropVOList.getJSONObject(0);
String giveConfigId = jo.getJSONObject("giveConfigVO").getString("giveConfigId");
int holdsNum = jo.optInt("holdsNum");
int holdsNum = jo.optInt("holdsNum", 0);
String propName = jo.getJSONObject("propConfigVO").getString("propName");
String propId = jo.getJSONArray("propIdList").getString(0);
jo = new JSONObject(AntForestRpcCall.giveProp(giveConfigId, propId, targetUserId));
if ("SUCCESS".equals(jo.getString("resultCode"))) {
Log.forest("赠送道具[" + FriendIdMap.getNameById(targetUserId) + "]#" + propName);
Log.forest("赠送道具🎭[" + FriendIdMap.getNameById(targetUserId) + "]#" + propName);
} else {
Log.recordLog(jo.getString("resultDesc"), jo.toString());
}
Expand Down Expand Up @@ -1116,7 +1187,7 @@ private static void queryUserPatrol() {
} else if (leftStep >= 2000 && usedStep < 10000) {
jo = new JSONObject(AntForestRpcCall.exchangePatrolChance(leftStep));
if ("SUCCESS".equals(jo.getString("resultCode"))) {
int addedChance = jo.optInt("addedChance");
int addedChance = jo.optInt("addedChance", 0);
Log.forest("步数兑换⚖️[巡护次数*" + addedChance + "]");
queryUserPatrol();
} else {
Expand Down Expand Up @@ -1186,15 +1257,15 @@ private static void queryAnimalAndPiece(boolean canConsumeProp) {
String name = animal.getString("name");
if (canConsumeProp && Config.animalConsumeProp()) {
JSONObject main = jo.optJSONObject("main");
if (main != null && main.optInt("holdsNum") > 0) {
if (main != null && main.optInt("holdsNum", 0) > 0) {
canConsumeProp = !AnimalConsumeProp(id);
}
}
JSONArray pieces = jo.getJSONArray("pieces");
boolean canCombine = true;
for (int j = 0; j < pieces.length(); j++) {
jo = pieces.optJSONObject(j);
if (jo == null || jo.optInt("holdsNum") <= 0) {
if (jo == null || jo.optInt("holdsNum", 0) <= 0) {
canCombine = false;
break;
}
Expand Down Expand Up @@ -1254,7 +1325,7 @@ private static void combineAnimalPiece(int animalId) {
JSONArray piecePropIds = new JSONArray();
for (int j = 0; j < pieces.length(); j++) {
jo = pieces.optJSONObject(j);
if (jo == null || jo.optInt("holdsNum") <= 0) {
if (jo == null || jo.optInt("holdsNum", 0) <= 0) {
canCombine = false;
break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private static void initNotification(Context context) {
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setContentTitle("芝麻粒")
.setAutoCancel(false)
.setOngoing(true)
.setContentIntent(pi)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void run() {
}
queryPointCert(1, 8);

anXinDou();
insBlueBean();
} catch (Throwable t) {
Log.i(TAG, "receivePoint.run err:");
Log.printStackTrace(TAG, t);
Expand Down Expand Up @@ -74,7 +74,7 @@ private static void queryPointCert(int page, int pageSize) {
}
}

private static void anXinDou() {
private static void insBlueBean() {
try {
String s = AntMemberRpcCall.pageRender();
JSONObject jo = new JSONObject(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static void checkReward(JSONArray rewards) {
boolean canCombine = true;
for (int j = 0; j < attachReward.length(); j++) {
JSONObject detail = attachReward.getJSONObject(j);
if (detail.optInt("count") == 0) {
if (detail.optInt("count", 0) == 0) {
canCombine = false;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/pansong291/xposed/quickenergy/Reserve.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ private static void exchangeTree(String projectId, String itemName, int count) {
Statistics.reserveToday(projectId, count);
break;
}
Thread.sleep(200);
Thread.sleep(300);
canApply = queryTreeForExchange(projectId);
if (!canApply) {
Statistics.reserveToday(projectId, count);
//Statistics.reserveToday(projectId, count);
break;
} else {
Thread.sleep(200);
Expand Down Expand Up @@ -272,10 +272,10 @@ private static void oceanExchangeTree(String cultivationCode, String projectCode
Statistics.beachToday(cultivationCode);
break;
}
Thread.sleep(200);
Thread.sleep(300);
canApply = queryCultivationDetail(cultivationCode, projectCode);
if (!canApply) {
Statistics.beachToday(cultivationCode);
//Statistics.beachToday(cultivationCode);
break;
} else {
Thread.sleep(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public static String giveProp(String giveConfigId, String propId, String targetU
+ "\",\"source\":\"self_corner\",\"targetUserId\":\"" + targetUserId + "\"}]");
}

public static String collectProp(String giveConfigId, String giveId) {
return RpcUtil.request("alipay.antforest.forest.h5.collectProp",
"[{\"giveConfigId\":\"" + giveConfigId + "\",\"giveId\":\"" + giveId
+ "\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\"}]");
}

public static String consumeProp(String propId, String propType) {
return RpcUtil.request("alipay.antforest.forest.h5.consumeProp",
"[{\"propId\":\"" + propId + "\",\"propType\":\"" + propType +
Expand Down Expand Up @@ -229,4 +235,10 @@ public static String AnimalConsumeProp(String propGroup, String propId, String p
+ "\",\"source\":\"ant_forest\",\"timezoneId\":\"Asia/Shanghai\"}]");
}

public static String collectAnimalRobEnergy(String propId, String propType, String shortDay) {
return RpcUtil.request("alipay.antforest.forest.h5.collectAnimalRobEnergy",
"[{\"propId\":\"" + propId + "\",\"propType\":\"" + propType + "\",\"shortDay\":\"" + shortDay
+ "\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\"}]");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import pansong291.xposed.quickenergy.ui.MainActivity;
import pansong291.xposed.quickenergy.util.*;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class XposedHook implements IXposedHookLoadPackage {
Expand Down Expand Up @@ -71,7 +73,9 @@ protected void beforeHookedMethod(MethodHookParam param) {
private static void initHandler() {
if (handler == null) {
handler = new Handler();
Config.setAlarm7(AntForestToast.context);
if (Config.startAt7()) {
Config.setAlarm7(AntForestToast.context);
}
}
if (runnable == null) {
FriendManager.fillUser(XposedHook.classLoader);
Expand Down Expand Up @@ -122,6 +126,7 @@ private void hookService(ClassLoader loader) {
"onResume", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
RpcUtil.isInterrupted = false;
String targetUid = RpcUtil.getUserId(loader);
if (targetUid == null || targetUid.equals(FriendIdMap.currentUid)) {
return;
Expand Down Expand Up @@ -166,8 +171,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, service.getClass().getName());
wakeLock.acquire();
}
if (Config.stayAwake()) {

if (Config.stayAwakeType() == StayAwakeType.BROADCAST) {
alarmBroadcast(AntForestToast.context, 30 * 60 * 1000, false);
} else if (Config.stayAwakeType() == StayAwakeType.ALARM) {
Expand Down Expand Up @@ -290,13 +294,14 @@ public void onReceive(Context context, Intent intent) {
restartHook(AntForestToast.context, force);
} else if ("com.eg.android.AlipayGphone.xqe.test".equals(action)) {
Log.recordLog("收到测试消息");
alarmHook(AntForestToast.context, 3000, true);
// alarmHook(AntForestToast.context, 3000, true);
} else if ("com.eg.android.AlipayGphone.xqe.cancelAlarm7".equals(action)) {
Config.cancelAlarm7(AntForestToast.context);
Config.cancelAlarm7(AntForestToast.context, false);
}
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
private void registerBroadcastReceiver(Context context) {
try {
IntentFilter intentFilter = new IntentFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.*;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import pansong291.xposed.quickenergy.AntForestToast;
import pansong291.xposed.quickenergy.R;
import pansong291.xposed.quickenergy.entity.FriendWatch;
import pansong291.xposed.quickenergy.entity.IdAndName;
import pansong291.xposed.quickenergy.util.Config;
import pansong291.xposed.quickenergy.util.FileUtils;
import pansong291.xposed.quickenergy.util.PermissionUtil;
import pansong291.xposed.quickenergy.util.Statistics;

import java.util.ArrayList;
import java.util.Comparator;

public class MainActivity extends Activity {
TextView tvStatistics;
Expand Down Expand Up @@ -89,8 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = " v" + packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (PackageManager.NameNotFoundException ignored) {
}
this.setTitle(this.getTitle() + version);

Expand All @@ -114,9 +111,9 @@ public void onClick(View v) {
if (v.getId() == R.id.btn_test) {
if (isApkInDebug(this)) {
Toast toast = Toast.makeText(this, "测试", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, Config.toastOffsetY());
toast.setGravity(toast.getGravity(), toast.getXOffset(), Config.toastOffsetY());
toast.show();
// sendBroadcast(new Intent("com.eg.android.AlipayGphone.xqe.test"));
sendBroadcast(new Intent("com.eg.android.AlipayGphone.xqe.test"));
}
return;
}
Expand Down
Loading

0 comments on commit cb823af

Please sign in to comment.