From f3865d29aaa6f46eac3331f255427d87e173bb32 Mon Sep 17 00:00:00 2001 From: Magical Yang Date: Mon, 31 Jul 2023 20:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=9D=A5=E8=87=AAcwj851?= =?UTF-8?q?=E7=9A=84PR=E3=80=82=E6=84=9F=E8=B0=A2cwj851=E4=B8=BA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=81=9A=E5=87=BA=E7=9A=84=E8=B4=A1=E7=8C=AE=E3=80=82?= =?UTF-8?q?=E5=85=91=E6=8D=A2=E9=99=90=E6=97=B6=E5=8F=8C=E5=87=BB=E5=8D=A1?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E6=8A=A4=E5=9C=B0=EF=BC=8C=E7=BB=BF=E8=89=B2?= =?UTF-8?q?=E6=89=93=E5=8D=A1=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD(=E8=BF=90=E5=8A=A8=E5=AE=9D=E7=AE=B1?= =?UTF-8?q?=E3=80=81=E6=8D=90=E6=AD=A5=E3=80=81=E6=8D=90=E8=BF=90=E5=8A=A8?= =?UTF-8?q?=E5=B8=81)=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=94=B6=E9=9B=86=E8=BF=90=E5=8A=A8=E5=B8=81=E5=8A=9F=E8=83=BD?= =?UTF-8?q?.=E5=A2=9E=E5=8A=A0=E7=A5=9E=E5=A5=87=E7=89=A9=E7=A7=8D?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=BA=84=E5=9B=AD?= =?UTF-8?q?=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../xposed/quickenergy/AntFarm.java | 34 +- .../xposed/quickenergy/AntForest.java | 187 +++++++- .../xposed/quickenergy/AntSports.java | 314 +++++++------- .../xposed/quickenergy/Reserve.java | 155 +++++++ .../quickenergy/hook/AncientTreeRpcCall.java | 11 +- .../quickenergy/hook/AntFarmRpcCall.java | 11 +- .../quickenergy/hook/AntForestRpcCall.java | 37 ++ .../quickenergy/hook/AntSportsRpcCall.java | 153 ++++--- .../quickenergy/hook/EcoLifeRpcCall.java | 41 ++ .../quickenergy/hook/ReserveRpcCall.java | 25 ++ .../xposed/quickenergy/hook/RpcUtil.java | 2 + .../xposed/quickenergy/hook/XposedHook.java | 6 +- .../xposed/quickenergy/ui/AlipayReserve.java | 38 ++ .../xposed/quickenergy/ui/EditDialog.java | 12 +- .../xposed/quickenergy/ui/ListDialog.java | 8 +- .../xposed/quickenergy/ui/MainActivity.java | 4 +- .../xposed/quickenergy/ui/OptionsAdapter.java | 6 +- .../quickenergy/ui/SettingsActivity.java | 84 +++- .../xposed/quickenergy/util/Config.java | 240 +++++++++-- .../xposed/quickenergy/util/FileUtils.java | 86 +++- .../xposed/quickenergy/util/Log.java | 6 + .../xposed/quickenergy/util/RandomUtils.java | 8 + .../xposed/quickenergy/util/ReserveIdMap.java | 75 ++++ .../xposed/quickenergy/util/Statistics.java | 404 ++++++++++++------ app/src/main/res/layout/include_settings.xml | 82 ++++ app/src/main/res/values-zh-rCN/strings.xml | 17 +- app/src/main/res/values/strings.xml | 14 +- 28 files changed, 1612 insertions(+), 452 deletions(-) create mode 100644 app/src/main/java/pansong291/xposed/quickenergy/Reserve.java create mode 100644 app/src/main/java/pansong291/xposed/quickenergy/hook/EcoLifeRpcCall.java create mode 100644 app/src/main/java/pansong291/xposed/quickenergy/hook/ReserveRpcCall.java create mode 100644 app/src/main/java/pansong291/xposed/quickenergy/ui/AlipayReserve.java create mode 100644 app/src/main/java/pansong291/xposed/quickenergy/util/ReserveIdMap.java diff --git a/app/build.gradle b/app/build.gradle index a40f6c513..34338ed39 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { minSdkVersion 23 //noinspection ExpiredTargetSdkVersion targetSdkVersion 29 - versionCode 26 - versionName "1.0.9" + versionCode 27 + versionName "1.0.10" } buildTypes { release { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java index 8b734bcc4..81bf46f81 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntFarm.java @@ -566,7 +566,9 @@ private static void receiveFarmTaskAward() { String s = AntFarmRpcCall.listFarmTask(); JSONObject jo = new JSONObject(s); String memo = jo.getString("memo"); - if(memo.equals("SUCCESS")) { + if (memo.equals("SUCCESS")) { + JSONObject signList = jo.getJSONObject("signList"); + sign(signList); JSONArray jaFarmTaskList = jo.getJSONArray("farmTaskList"); for(int i = 0; i < jaFarmTaskList.length(); i++) { jo = jaFarmTaskList.getJSONObject(i); @@ -609,6 +611,36 @@ private static void receiveFarmTaskAward() { } } + private static boolean sign(JSONObject signList) { + try { + JSONArray jaFarmsignList = signList.getJSONArray("signList"); + boolean signed = true; + int awardCount = 0; + for (int i = 0; i < jaFarmsignList.length(); i++) { + JSONObject jo = jaFarmsignList.getJSONObject(i); + if (Log.getFormatDate().equals(jo.getString("signKey"))) { + signed = jo.getBoolean("signed"); + awardCount = jo.getInt("awardCount"); + break; + } + } + if (!signed) { + JSONObject joSign = new JSONObject(AntFarmRpcCall.sign()); + if (joSign.getString("memo").equals("SUCCESS")) { + Log.farm("庄园签到获得饲料[" + awardCount + "g]"); + } else { + Log.i(TAG, joSign.toString()); + } + } else { + Log.recordLog("庄园今日已签到", ""); + } + } catch (Throwable t) { + Log.i(TAG, "Farmsign err:"); + Log.printStackTrace(TAG, t); + } + return false; + } + private static void feedAnimal(String farmId) { try { if (foodStock < 180) { diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java b/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java index 79323e741..3ee9c70bc 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntForest.java @@ -6,6 +6,7 @@ import org.json.JSONObject; import pansong291.xposed.quickenergy.AntFarm.TaskStatus; import pansong291.xposed.quickenergy.hook.AntForestRpcCall; +import pansong291.xposed.quickenergy.hook.EcoLifeRpcCall; import pansong291.xposed.quickenergy.util.*; import java.util.*; @@ -117,17 +118,31 @@ public void run() { if (Config.energyRain()) { energyRain(); } + if (Config.ExchangeEnergyDoubleClick() && Statistics.canExchangeDoubleCardToday()) { + int exchangeCount = Config.getExchangeEnergyDoubleClickCount(); + int exchangeTimes = exchangeEnergyDoubleClick(exchangeCount); + } + if (Config.ecoLifeTick()) { + ecoLifeTick(); + } + if (Config.antdodoCollect()) { + antdodoCollect(); + } for (int i = 0; i < Config.getWaterFriendList().size(); i++) { String uid = Config.getWaterFriendList().get(i); - if (selfId.equals(uid)) continue; + if (selfId.equals(uid)) + continue; int waterCount = Config.getWaterCountList().get(i); - if (waterCount <= 0) continue; - if (waterCount > 3) waterCount = 3; + if (waterCount <= 0) + continue; + if (waterCount > 3) + waterCount = 3; if (Statistics.canWaterFriendToday(uid, waterCount)) { waterFriendEnergy(uid, waterCount); } } - if (Statistics.canSyncStepToday() && TimeUtil.getTimeStr().compareTo("0800") >= 0) { + if (Statistics.canSyncStepToday(FriendIdMap.currentUid) + && TimeUtil.getTimeStr().compareTo("0600") >= 0) { new StepTask(loader).start(); } } @@ -606,6 +621,37 @@ private static int returnFriendWater(String userId, String userName, String bizN return wateredTimes; } + private static int exchangeEnergyDoubleClick(int count) { + int exchangedTimes = 0; + try { + String s; + JSONObject jo; + for (int exchangeCount = 1; exchangeCount <= count; exchangeCount++) { + if (Statistics.canExchangeDoubleCardToday()) { + s = AntForestRpcCall.exchangeBenefit("CR20230516000362", "CR20230516000363"); + jo = new JSONObject(s); + if ("SUCCESS".equals(jo.getString("resultCode"))) { + exchangedTimes = Statistics.getExchangeTimes() + 1; + Log.forest("活力值兑换[限时双击卡]成功![第" + exchangedTimes + "次]"); + Statistics.exchangeDoubleCardToday(true); + } else { + Log.recordLog(jo.getString("resultDesc"), jo.toString()); + Statistics.exchangeDoubleCardToday(false); + break; + } + Thread.sleep(1000); + } else { + break; + } + + } + } catch (Throwable t) { + Log.i(TAG, "exchangeEnergyDoubleClick err:"); + Log.printStackTrace(TAG, t); + } + return exchangedTimes; + } + private static void receiveTaskAward() { try { String s = AntForestRpcCall.queryTaskList(); @@ -770,6 +816,7 @@ private static void useDoubleCard() { JSONArray forestPropVOList = jo.getJSONArray("forestPropVOList"); String propId = null; String propType = null; + String propName = null; for (int i = 0; i < forestPropVOList.length(); i++) { JSONObject forestPropVO = forestPropVOList.getJSONObject(i); String tmpPropType = forestPropVO.getString("propType"); @@ -777,22 +824,22 @@ private static void useDoubleCard() { JSONArray propIdList = forestPropVO.getJSONArray("propIdList"); propId = propIdList.getString(0); propType = tmpPropType; - Log.forest("检测到【限时双击卡】" + propId); + propName = "限时双击卡"; break; } if ("ENERGY_DOUBLE_CLICK".equals(tmpPropType)) { JSONArray propIdList = forestPropVO.getJSONArray("propIdList"); propId = propIdList.getString(0); propType = tmpPropType; - Log.forest("检测到【双击卡】" + propId); + propName = "双击卡"; } } if (!StringUtil.isEmpty(propId)) { - Log.forest("尝试使用【双击卡】【" + propType + "】" + propId); + // Log.forest("尝试使用[双击卡][" + propType + "]" + propId); jo = new JSONObject(AntForestRpcCall.consumeProp(propId, propType)); if ("SUCCESS".equals(jo.getString("resultCode"))) { doubleEndTime = System.currentTimeMillis() + 1000 * 60 * 5; - Log.forest("使用【双击卡】成功"); + Log.forest("使用[" + propName + "]成功"); } else { Log.recordLog(jo.getString("resultDesc"), jo.toString()); updateDoubleTime(); @@ -805,6 +852,124 @@ private static void useDoubleCard() { } } + private static void ecoLifeTick() { + try { + JSONObject jo = new JSONObject(EcoLifeRpcCall.queryHomePage()); + if ("SUCCESS".equals(jo.getString("resultCode"))) { + JSONObject data = jo.getJSONObject("data"); + String dayPoint = data.getString("dayPoint"); + JSONArray actionListVO = data.getJSONArray("actionListVO"); + for (int i = 0; i < actionListVO.length(); i++) { + JSONObject actionVO = actionListVO.getJSONObject(i); + JSONArray actionItemList = actionVO.getJSONArray("actionItemList"); + for (int j = 0; j < actionItemList.length(); j++) { + JSONObject actionItem = actionItemList.getJSONObject(j); + if (!actionItem.has("actionId")) + continue; + if (actionItem.getBoolean("actionStatus")) + continue; + String actionId = actionItem.getString("actionId"); + String actionName = actionItem.getString("actionName"); + boolean isGuangpan = false; + if ("photoguangpan".equals(actionId))continue; + jo = new JSONObject(EcoLifeRpcCall.tick(actionId, "ALIPAY", dayPoint, isGuangpan)); + if ("SUCCESS".equals(jo.getString("resultCode"))) { + Log.forest("绿色打卡[" + actionName + "]成功"); + } else { + Log.recordLog(jo.getString("resultDesc"), jo.toString()); + } + Thread.sleep(500); + } + } + } + } catch (Throwable th) { + Log.i(TAG, "ecoLifeTick err:"); + Log.printStackTrace(TAG, th); + } + } + + private static void antdodoCollect() { + try { + String s = AntForestRpcCall.queryAnimalStatus(); + JSONObject jo = new JSONObject(s); + if (jo.getString("resultCode").equals("SUCCESS")) { + JSONObject data = jo.getJSONObject("data"); + // s = data.getString("homeState"); + // if (s.equals("DODO_NOT_OPEN")) { + // collectAnimalCard(); + // } else if (s.equals("DODO_NEW_BOOK")) { + // //taskEntrance(); + // collectAnimalCard(); + // } else if (s.equals("DODO_BOOK")) {//DODO_TAKE_LOOK + if (data.getBoolean("collect")) { + Log.recordLog("神奇物种卡片今日收集完成!", ""); + } else { + collectAnimalCard(); + } + // } + } else { + Log.i(TAG, jo.getString("resultDesc")); + } + } catch (Throwable t) { + Log.i(TAG, "antdodoCollect err:"); + Log.printStackTrace(TAG, t); + } + } + + private static void collectAnimalCard() { + try { + JSONObject jo = new JSONObject(AntForestRpcCall.antdodoHomePage()); + if (jo.getString("resultCode").equals("SUCCESS")) { + JSONObject data = jo.getJSONObject("data"); + JSONArray ja = data.getJSONArray("limit"); + int index = -1; + for (int i = 0; i < ja.length(); i++) { + jo = ja.getJSONObject(i); + if (jo.getString("actionCode").equals("DAILY_COLLECT")) { + index = i; + break; + } + } + if (index >= 0) { + int leftFreeQuota = jo.getInt("leftFreeQuota"); + for (int j = 0; j < leftFreeQuota; j++) { + jo = new JSONObject(AntForestRpcCall.antdodoCollect()); + if (jo.getString("resultCode").equals("SUCCESS")) { + data = jo.getJSONObject("data"); + JSONObject animal = data.getJSONObject("animal"); + String ecosystem = animal.getString("ecosystem"); + String name = animal.getString("name"); + Log.forest("神奇物种获得[" + ecosystem + "-" + name + "]卡片"); + } else { + Log.i(TAG, jo.getString("resultDesc")); + } + } + } + } else { + Log.i(TAG, jo.getString("resultDesc")); + } + } catch (Throwable t) { + Log.i(TAG, "collect err:"); + Log.printStackTrace(TAG, t); + } + } + + private static void taskEntrance() { + try { + String s = AntForestRpcCall.taskEntrance(); + JSONObject jo = new JSONObject(s); + if (jo.getString("resultCode").equals("SUCCESS")) { + Log.recordLog("神奇物种卡片开启新图鉴!", ""); + antdodoCollect(); + } else { + Log.i(TAG, jo.getString("resultDesc")); + } + } catch (Throwable t) { + Log.i(TAG, "taskEntrance err:"); + Log.printStackTrace(TAG, t); + } + } + /** * Execute. * @@ -883,11 +1048,11 @@ public void run() { loader.loadClass("com.alibaba.health.pedometer.intergation.rpc.RpcManager"), "a"), "a", new Object[]{ step, Boolean.FALSE, "system" }); if (booleanValue) { - Log.recordLog("记录运动步数成功:" + step, ""); + Log.recordLog("同步运动步数成功:" + step, ""); } else { - Log.recordLog("修改运动步数失败:" + step, ""); + Log.recordLog("同步运动步数失败:" + step, ""); } - Statistics.SyncStepToday(); + Statistics.SyncStepToday(FriendIdMap.currentUid); } catch (Throwable t) { Log.i(TAG, "StepTask.run err:"); Log.printStackTrace(TAG, t); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java b/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java index 9bb80d277..2254752b5 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/AntSports.java @@ -8,37 +8,37 @@ import pansong291.xposed.quickenergy.util.Log; import pansong291.xposed.quickenergy.util.Statistics; -public class AntSports -{ +public class AntSports { private static final String TAG = AntSports.class.getCanonicalName(); - public static void start(ClassLoader loader, int times) - { - new Thread() - { + public static void start(ClassLoader loader, int times) { + new Thread() { ClassLoader loader; int times; - public Thread setData(ClassLoader cl, int i) - { + public Thread setData(ClassLoader cl, int i) { loader = cl; times = i; return this; } @Override - public void run() - { - try - { - if(Config.openTreasureBox()) + public void run() { + try { + while(FriendIdMap.currentUid == null || FriendIdMap.currentUid.isEmpty()) + Thread.sleep(100); + if (Config.openTreasureBox()) queryMyHomePage(loader); - if(Config.donateCharityCoin()) + + if (Config.receiveCoinAsset()) + receiveCoinAsset(); + + if (Config.donateCharityCoin()) queryProjectList(loader); - if(Config.minExchangeCount() > 0 && Statistics.canExchangeToday() && times == 0) + + if (Config.minExchangeCount() > 0 && Statistics.canExchangeToday(FriendIdMap.currentUid) && times == 0) queryWalkStep(loader); - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "start.run err:"); Log.printStackTrace(TAG, t); } @@ -46,22 +46,46 @@ public void run() }.setData(loader, times).start(); } - private static void queryMyHomePage(ClassLoader loader) - { - try - { + private static void receiveCoinAsset() { + try { + String s = AntSportsRpcCall.queryCoinBubbleModule(); + JSONObject jo = new JSONObject(s); + if (jo.getBoolean("success")) { + JSONObject data = jo.getJSONObject("data"); + if (!data.has("receiveCoinBubbleList")) + return; + JSONArray ja = data.getJSONArray("receiveCoinBubbleList"); + for (int i = 0; i < ja.length(); i++) { + jo = ja.getJSONObject(i); + String assetId = jo.getString("assetId"); + int coinAmount = jo.getInt("coinAmount"); + jo = new JSONObject(AntSportsRpcCall.receiveCoinAsset(assetId, coinAmount)); + if (jo.getBoolean("success")) { + Log.other("首页收集金币成功[" + coinAmount + "个]"); + } else { + Log.recordLog("首页收集金币", jo.toString()); + } + } + } else { + Log.i(TAG, s); + } + } catch (Throwable t) { + Log.i(TAG, "receiveCoinAsset err:"); + Log.printStackTrace(TAG, t); + } + } + + private static void queryMyHomePage(ClassLoader loader) { + try { String s = AntSportsRpcCall.queryMyHomePage(); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { + if (jo.getString("resultCode").equals("SUCCESS")) { s = jo.getString("pathJoinStatus"); - if(s.equals("GOING")) - { + if (s.equals("GOING")) { FriendIdMap.currentUid = jo.getJSONObject("myPositionModel").getString("userId"); String rankCacheKey = jo.getString("rankCacheKey"); JSONArray ja = jo.getJSONArray("treasureBoxModelList"); - for(int i = 0; i < ja.length(); i++) - { + for (int i = 0; i < ja.length(); i++) { parseTreasureBoxModel(loader, ja.getJSONObject(i), rankCacheKey); } JSONObject joPathRender = jo.getJSONObject("pathRenderModel"); @@ -72,114 +96,96 @@ private static void queryMyHomePage(ClassLoader loader) int produceQuantity = jo.getInt("produceQuantity"); String day = jo.getString("day"); int canMoveStepCount = produceQuantity - consumeQuantity; - if(canMoveStepCount >= minGoStepCount) - { + if (canMoveStepCount >= minGoStepCount) { go(loader, day, rankCacheKey, canMoveStepCount, title); } - }else if(s.equals("NOT_JOIN")) - { + } else if (s.equals("NOT_JOIN")) { + String firstJoinPathTitle = jo.getString("firstJoinPathTitle"); JSONArray ja = jo.getJSONArray("allPathBaseInfoList"); - for(int i = ja.length() - 1; i >= 0; i--) - { + for (int i = ja.length() - 1; i >= 0; i--) { jo = ja.getJSONObject(i); - if(jo.getBoolean("unlocked")) + if (jo.getBoolean("unlocked")) break; } String title = jo.getString("title"); String pathId = jo.getString("pathId"); - join(loader, pathId, title); + join(loader, pathId, title, firstJoinPathTitle); } - }else - { + } else { Log.i(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "queryMyHomePage err:"); Log.printStackTrace(TAG, t); } } - private static void join(ClassLoader loader, String pathId, String title) - { - try - { - String s = AntSportsRpcCall.join(pathId); + private static void join(ClassLoader loader, String pathId, String title, String firstJoinPathTitle) { + try { + String s; + if (title.equals(firstJoinPathTitle)) { + s = AntSportsRpcCall.openAndJoinFirst(); + } else { + s = AntSportsRpcCall.join(pathId); + } JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { - Log.other("成功加入〈" + title + "〉路线"); + if (jo.getString("resultCode").equals("SUCCESS")) { + Log.other("成功加入[" + title + "]路线"); queryMyHomePage(loader); - }else - { + } else { Log.i(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "join err:"); Log.printStackTrace(TAG, t); } } - private static void go(ClassLoader loader, String day, String rankCacheKey, int stepCount, String title) - { - try - { + private static void go(ClassLoader loader, String day, String rankCacheKey, int stepCount, String title) { + try { String s = AntSportsRpcCall.go(day, rankCacheKey, stepCount); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { - Log.other("〈" + title + "〉路线前进了〈" + jo.getInt("goStepCount") + "步〉"); + if (jo.getString("resultCode").equals("SUCCESS")) { + Log.other("[" + title + "]路线前进了[" + jo.getInt("goStepCount") + "步]"); boolean completed = jo.getString("completeStatus").equals("COMPLETED"); JSONArray ja = jo.getJSONArray("allTreasureBoxModelList"); - for(int i = 0; i < ja.length(); i++) - { + for (int i = 0; i < ja.length(); i++) { parseTreasureBoxModel(loader, ja.getJSONObject(i), rankCacheKey); } - if(completed) - { - Log.other("〈" + title + "〉路线已完成"); + if (completed) { + Log.other("[" + title + "]路线已完成"); queryMyHomePage(loader); } - }else - { + } else { Log.i(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "go err:"); Log.printStackTrace(TAG, t); } } - private static void parseTreasureBoxModel(ClassLoader loader, JSONObject jo, String rankCacheKey) - { - try - { + private static void parseTreasureBoxModel(ClassLoader loader, JSONObject jo, String rankCacheKey) { + try { String canOpenTime = jo.getString("canOpenTime"); String issueTime = jo.getString("issueTime"); String boxNo = jo.getString("boxNo"); String userId = jo.getString("userId"); - if(canOpenTime.equals(issueTime)) - { + if (canOpenTime.equals(issueTime)) { openTreasureBox(loader, boxNo, userId); - }else - { + } else { long cot = Long.parseLong(canOpenTime); long now = Long.parseLong(rankCacheKey); long delay = cot - now; Log.recordLog("还有 " + delay + "ms 才能开宝箱", ""); - if(delay < Config.checkInterval()) - { - new Thread() - { + if (delay < Config.checkInterval()) { + new Thread() { long delay; ClassLoader loader; String boxNo; String userId; - public Thread setData(long l, ClassLoader cl, String bN, String uid) - { + public Thread setData(long l, ClassLoader cl, String bN, String uid) { delay = l - 1000; loader = cl; boxNo = bN; @@ -188,21 +194,18 @@ public Thread setData(long l, ClassLoader cl, String bN, String uid) } @Override - public void run() - { - try - { - if(delay > 0) sleep(delay); + public void run() { + try { + if (delay > 0) + sleep(delay); Log.recordLog("蹲点开箱开始", ""); long startTime = System.currentTimeMillis(); - while(System.currentTimeMillis() - startTime < 5_000) - { - if(openTreasureBox(loader, boxNo, userId) > 0) + while (System.currentTimeMillis() - startTime < 5_000) { + if (openTreasureBox(loader, boxNo, userId) > 0) break; sleep(200); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "parseTreasureBoxModel.run err:"); Log.printStackTrace(TAG, t); } @@ -211,137 +214,120 @@ public void run() }.setData(delay, loader, boxNo, userId).start(); } } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "parseTreasureBoxModel err:"); Log.printStackTrace(TAG, t); } } - private static int openTreasureBox(ClassLoader loader, String boxNo, String userId) - { - try - { + private static int openTreasureBox(ClassLoader loader, String boxNo, String userId) { + try { String s = AntSportsRpcCall.openTreasureBox(boxNo, userId); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { + if (jo.getString("resultCode").equals("SUCCESS")) { JSONArray ja = jo.getJSONArray("treasureBoxAwards"); int num = 0; - for(int i = 0; i < ja.length(); i++) - { + for (int i = 0; i < ja.length(); i++) { jo = ja.getJSONObject(i); num += jo.getInt("num"); - Log.other("开宝箱获得〈" + num + jo.getString("name") + "〉"); + Log.other("开宝箱获得[" + num + jo.getString("name") + "]"); } return num; - }else - { + } else { Log.recordLog(jo.getString("resultDesc"), ""); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "openTreasureBox err:"); Log.printStackTrace(TAG, t); } return 0; } - private static void queryProjectList(ClassLoader loader) - { - try - { + private static void queryProjectList(ClassLoader loader) { + try { String s = AntSportsRpcCall.queryProjectList(0); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { + if (jo.getString("resultCode").equals("SUCCESS")) { int charityCoinCount = jo.getInt("charityCoinCount"); - if(charityCoinCount < 10) return; + if (charityCoinCount < 10) + return; jo = jo.getJSONObject("projectPage"); JSONArray ja = jo.getJSONArray("data"); - for(int i = 0; i < ja.length(); i++) - { + for (int i = 0; i < ja.length(); i++) { jo = ja.getJSONObject(i).getJSONObject("basicModel"); - if(jo.getString("footballFieldStatus").equals("OPENING_DONATE")) - { + if (jo.getString("footballFieldStatus").equals("OPENING_DONATE")) { donate(loader, charityCoinCount / 10 * 10, jo.getString("projectId"), jo.getString("title")); break; } } - }else - { + } else { Log.recordLog(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "queryProjectList err:"); Log.printStackTrace(TAG, t); } } - private static void donate(ClassLoader loader, int donateCharityCoin, String projectId, String title) - { - try - { + private static void donate(ClassLoader loader, int donateCharityCoin, String projectId, String title) { + try { String s = AntSportsRpcCall.donate(donateCharityCoin, projectId); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { - Log.other("捐赠〈" + title + "〉〈" + donateCharityCoin + "运动币〉"); - }else - { + if (jo.getString("resultCode").equals("SUCCESS")) { + Log.other("捐赠[" + title + "][" + donateCharityCoin + "运动币]"); + } else { Log.i(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "donate err:"); Log.printStackTrace(TAG, t); } } - private static void queryWalkStep(ClassLoader loader) - { - try - { + private static void queryWalkStep(ClassLoader loader) { + try { String s = AntSportsRpcCall.queryWalkStep(); JSONObject jo = new JSONObject(s); - if(jo.getString("resultCode").equals("SUCCESS")) - { + if (jo.getString("resultCode").equals("SUCCESS")) { jo = jo.getJSONObject("dailyStepModel"); int produceQuantity = jo.getInt("produceQuantity"); int hour = Integer.parseInt(Log.getFormatTime().split(":")[0]); - if(produceQuantity >= Config.minExchangeCount() || hour >= Config.latestExchangeTime()) - { - s = AntSportsRpcCall.exchange(produceQuantity, 3); + if (produceQuantity >= Config.minExchangeCount() || hour >= Config.latestExchangeTime()) { + s = AntSportsRpcCall.walkDonateSignInfo(produceQuantity); + s = AntSportsRpcCall.donateWalkHome(produceQuantity); jo = new JSONObject(s); - if(jo.getBoolean("isSuccess")) - { - s = AntSportsRpcCall.exchangeSuccess(jo.getString("exchangeId")); - jo = new JSONObject(s); - if(jo.getBoolean("isSuccess")) - { - int userCount = jo.getInt("userCount"); - double amount = jo.getJSONObject("userAmount").getDouble("amount"); - Log.other("捐出〈" + userCount + "步〉,兑换〈" + amount + "元〉公益金"); - Statistics.exchangeToday(); - }else - { - Log.i(TAG, jo.getString("resultDesc")); - } - }else if(s.contains("已捐步")) - { - Statistics.exchangeToday(); - }else - { + if (!jo.getBoolean("isSuccess")) + return; + JSONObject walkDonateHomeModel = jo.getJSONObject("walkDonateHomeModel"); + JSONObject walkUserInfoModel = walkDonateHomeModel.getJSONObject("walkUserInfoModel"); + if (!walkUserInfoModel.has("exchangeFlag")) { + Statistics.exchangeToday(FriendIdMap.currentUid); + return; + } + + String donateToken = walkDonateHomeModel.getString("donateToken"); + JSONObject walkCharityActivityModel = walkDonateHomeModel.getJSONObject("walkCharityActivityModel"); + String activityId = walkCharityActivityModel.getString("activityId"); + + s = AntSportsRpcCall.exchange(activityId, produceQuantity, donateToken); + jo = new JSONObject(s); + if (jo.getBoolean("isSuccess")) { + JSONObject donateExchangeResultModel = jo.getJSONObject("donateExchangeResultModel"); + int userCount = donateExchangeResultModel.getInt("userCount"); + double amount = donateExchangeResultModel.getJSONObject("userAmount").getDouble("amount"); + Log.other("捐出[" + userCount + "步],兑换[" + amount + "元]公益金"); + Statistics.exchangeToday(FriendIdMap.currentUid); + + } else if (s.contains("已捐步")) { + Statistics.exchangeToday(FriendIdMap.currentUid); + } else { Log.i(TAG, jo.getString("resultDesc")); } } - }else - { + } else { Log.i(TAG, jo.getString("resultDesc")); } - }catch(Throwable t) - { + } catch (Throwable t) { Log.i(TAG, "queryWalkStep err:"); Log.printStackTrace(TAG, t); } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java b/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java new file mode 100644 index 000000000..aaa6efda2 --- /dev/null +++ b/app/src/main/java/pansong291/xposed/quickenergy/Reserve.java @@ -0,0 +1,155 @@ +package pansong291.xposed.quickenergy; + +import org.json.JSONArray; +import org.json.JSONObject; +import pansong291.xposed.quickenergy.hook.ReserveRpcCall; +import pansong291.xposed.quickenergy.util.Config; +import pansong291.xposed.quickenergy.util.ReserveIdMap; +import pansong291.xposed.quickenergy.util.FriendIdMap; +import pansong291.xposed.quickenergy.util.Log; +import pansong291.xposed.quickenergy.util.RandomUtils; +import pansong291.xposed.quickenergy.util.Statistics; + +public class Reserve { + private static final String TAG = Reserve.class.getCanonicalName(); + + private static boolean firstTime = true; + + public static void start() { + if (!Config.reserve() || !firstTime) + return; + Log.recordLog("开始检测保护地", ""); + new Thread() { + + @Override + public void run() { + try { + while(FriendIdMap.currentUid == null || FriendIdMap.currentUid.isEmpty()) + Thread.sleep(100); + String s = ReserveRpcCall.queryTreeItemsForExchange(); + if (s == null) { + Thread.sleep(RandomUtils.delay()); + s = ReserveRpcCall.queryTreeItemsForExchange(); + } + JSONObject jo = new JSONObject(s); + if (jo.getString("resultCode").equals("SUCCESS")) { + JSONObject userBaseInfo = jo.getJSONObject("userBaseInfo"); + JSONArray ja = jo.getJSONArray("treeItems"); + for (int i = 0; i < ja.length(); i++) { + jo = ja.getJSONObject(i); + /* + * if (!jo.has("itemId")) { + * s = ReserveRpcCall.queryTreeItemsForExchange(); + * jo = new JSONObject(s).getJSONObject("treeItems"); + * } + */ + if (!jo.has("projectType")) + continue; + if (!jo.getString("projectType").equals("RESERVE")) + continue; + if (!jo.getString("applyAction").equals("AVAILABLE")) + continue; + String projectId = jo.getString("itemId"); + String itemName = jo.getString("itemName"); + int energy = jo.getInt("energy"); + ReserveIdMap.putIdMap(projectId, itemName + "(" + energy + "g)"); + int index = -1; + for (int j = 0; j < Config.getReserveList().size(); j++) { + if (Config.getReserveList().get(j).equals(projectId)) { + index = j; + break; + } + } + if (index < 0) + continue; + int reserveCount = Config.getReserveCountList().get(index); + if (reserveCount <= 0) + continue; + if (!Statistics.canReserveToday(projectId, reserveCount)) + continue; + exchangeTree(projectId, itemName, reserveCount); + } + } else { + Log.i(TAG, jo.getString("resultDesc")); + } + } catch (Throwable t) { + Log.i(TAG, "start.run err:"); + Log.printStackTrace(TAG, t); + } + ReserveIdMap.saveIdMap(); + firstTime = false; + } + }.start(); + } + + private static boolean queryTreeForExchange(String projectId) { + try { + String s = ReserveRpcCall.queryTreeForExchange(projectId); + JSONObject jo = new JSONObject(s); + if ("SUCCESS".equals(jo.getString("resultCode"))) { + String applyAction = jo.getString("applyAction"); + int currentEnergy = jo.getInt("currentEnergy"); + jo = jo.getJSONObject("exchangeableTree"); + if ("AVAILABLE".equals(applyAction)) { + if (currentEnergy >= jo.getInt("energy")) { + return true; + } else { + Log.forest("能量不够申请保护地[" + jo.getString("projectName") + "],停止申请!"); + return false; + } + } else { + Log.forest("保护地[" + jo.getString("projectName") + "]似乎没有了!"); + return false; + } + } else { + Log.recordLog(jo.getString("resultDesc"), s); + } + } catch (Throwable t) { + Log.i(TAG, "queryTreeForExchange err:"); + Log.printStackTrace(TAG, t); + } + return false; + } + + private static void exchangeTree(String projectId, String itemName, int count) { + int appliedTimes = 0; + try { + String s; + JSONObject jo; + boolean canApply = queryTreeForExchange(projectId); + if (!canApply) + return; + for (int applyCount = 1; applyCount <= count; applyCount++) { + if (!Statistics.canReserveToday(projectId, count)) + continue; + s = ReserveRpcCall.exchangeTree(projectId); + jo = new JSONObject(s); + if ("SUCCESS".equals(jo.getString("resultCode"))) { + int vitalityAmount = jo.getInt("vitalityAmount"); + appliedTimes = Statistics.getReserveTimes(projectId) + 1; + String str = "申请保护地[" + itemName + "]成功![第" + appliedTimes + "次]" + + (vitalityAmount > 0 ? "获得活力值[" + vitalityAmount + "]" : ""); + Log.forest(str); + Statistics.reserveToday(projectId, 1); + } else { + Log.recordLog(jo.getString("resultDesc"), jo.toString()); + Log.forest("申请保护地发生未知错误,停止申请!"); + Statistics.reserveToday(projectId, count); + break; + } + Thread.sleep(500); + canApply = queryTreeForExchange(projectId); + if (!canApply) { + Statistics.reserveToday(projectId, count); + break; + } else { + Thread.sleep(500); + } + } + } catch (Throwable t) { + Log.i(TAG, "exchangeTree err:"); + Log.printStackTrace(TAG, t); + } + } + +} diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AncientTreeRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AncientTreeRpcCall.java index 6555505b5..dd8c4bba8 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AncientTreeRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AncientTreeRpcCall.java @@ -1,13 +1,20 @@ package pansong291.xposed.quickenergy.hook; -public class AncientTreeRpcCall -{ +public class AncientTreeRpcCall { + private static final String VERSION = "20230522"; public static String homePage(String cityCode) { return RpcUtil.request("alipay.greenmatrix.rpc.h5.ancienttree.homePage", "[{\"cityCode\":\"" + cityCode + "\",\"source\":\"antforesthome\"}]"); } + public static String queryTreeItemsForExchange(String cityCode) { + return RpcUtil.request("alipay.antforest.forest.h5.queryTreeItemsForExchange", + "[{\"cityCode\":\"" + cityCode + + "\",\"itemTypes\":\"\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\",\"version\":\"" + + VERSION + "\"}]"); + } + public static String protect(String activityId, String projectId, String cityCode) { return RpcUtil.request("alipay.greenmatrix.rpc.h5.ancienttree.protect", "[{\"ancientTreeActivityId\":\"" + activityId + "\",\"ancientTreeProjectId\":\"" + diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java index 6f0ca10a4..03abb417c 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntFarmRpcCall.java @@ -166,8 +166,15 @@ public static String farmId2UserId(String farmId) { } public static String collectManurePot(String manurePotNO) { - return RpcUtil.request("com.alipay.antfarm.collectManurePot","[{\"manurePotNOs\":\"" + manurePotNO + - "\",\"requestType\":\"NORMAL\",\"sceneCode\":\"ANTFARM\",\"source\":\"H5\",\"version\":\"" + VERSION + "\"}]"); + return RpcUtil.request("com.alipay.antfarm.collectManurePot", "[{\"manurePotNOs\":\"" + manurePotNO + + "\",\"requestType\":\"NORMAL\",\"sceneCode\":\"ANTFARM\",\"source\":\"H5\",\"version\":\"" + VERSION + + "\"}]"); + } + + public static String sign() { + return RpcUtil.request("com.alipay.antfarm.sign", + "[{\"requestType\":\"NORMAL\",\"sceneCode\":\"ANTFARM\",\"source\":\"H5\",\"version\":\"" + VERSION + + "\"}]"); } } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntForestRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntForestRpcCall.java index b00b2e5e2..654bd9924 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntForestRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntForestRpcCall.java @@ -2,6 +2,8 @@ import pansong291.xposed.quickenergy.util.StringUtil; +import pansong291.xposed.quickenergy.util.RandomUtils; + import java.util.UUID; public class AntForestRpcCall { @@ -78,6 +80,7 @@ public static String grantEnergyRainChance(String targetUserId) { public static String startEnergyRain() { return RpcUtil.request("alipay.antforest.forest.h5.startEnergyRain", "[{}]"); } + public static String energyRainSettlement(int saveEnergy, String token) { return RpcUtil.request("alipay.antforest.forest.h5.energyRainSettlement", "[{\"activityPropNums\":0,\"saveEnergy\":" + saveEnergy + ",\"token\":\"" + token + "\"}]"); @@ -114,4 +117,38 @@ public static String consumeProp(String propId, String propType) { VERSION + "\"}]"); } + public static String exchangeBenefit(String spuId, String skuId) { + return RpcUtil.request("com.alipay.antcommonweal.exchange.h5.exchangeBenefit", + "[{\"sceneCode\":\"ANTFOREST_VITALITY\",\"requestId\":\"" + System.currentTimeMillis() + + "_" + RandomUtils.getRandom(17) + "\",\"spuId\":\"" + + spuId + "\",\"skuId\":\"" + skuId + "\",\"source\":\"GOOD_DETAIL\"}]"); + } + + + public static String testH5Rpc(String operationTpye, String requestDate) { + return RpcUtil.request(operationTpye,requestDate); + } + + /* 神奇物种 */ + + public static String queryAnimalStatus() { + return RpcUtil.request("alipay.antdodo.rpc.h5.queryAnimalStatus", + "[{\"source\":\"chInfo_ch_appcenter__chsub_9patch\"}]"); + } + + public static String antdodoHomePage() { + return RpcUtil.request("alipay.antdodo.rpc.h5.homePage", + "[{}]"); + } + + public static String taskEntrance() { + return RpcUtil.request("alipay.antdodo.rpc.h5.taskEntrance", + "[{\"statusList\":[\"TODO\",\"FINISHED\"]}]"); + } + + public static String antdodoCollect() { + return RpcUtil.request("alipay.antdodo.rpc.h5.collect", + "[{}]"); + } + } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntSportsRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntSportsRpcCall.java index fbbb10023..fc5dff5a2 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/AntSportsRpcCall.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/AntSportsRpcCall.java @@ -1,61 +1,98 @@ package pansong291.xposed.quickenergy.hook; -public class AntSportsRpcCall -{ - private static final String chInfo = "antsports-account", - timeZone = "Asia\\/Shanghai", version = "3.0.1.2"; - - public static String queryMyHomePage() { - String args1 = "[{\"chInfo\":\"" + chInfo - + "\",\"pathListUsePage\":true,\"timeZone\":\"" + timeZone + "\"}]"; - return RpcUtil.request("alipay.antsports.walk.map.queryMyHomePage", args1); - } - - public static String join(String pathId) { - String args1 = "[{\"chInfo\":\"" + chInfo + "\",\"pathId\":\"" + pathId + "\"}]"; - return RpcUtil.request("alipay.antsports.walk.map.join", args1); - } - - public static String go(String day, String rankCacheKey, int stepCount) { - String args1 = "[{\"chInfo\":\"" + chInfo + "\",\"day\":\"" + day - + "\",\"needAllBox\":true,\"rankCacheKey\":\"" + rankCacheKey - + "\",\"timeZone\":\"" + timeZone + "\",\"useStepCount\":" + stepCount + "}]"; - return RpcUtil.request("alipay.antsports.walk.map.go", args1); - } - - public static String openTreasureBox(String boxNo, String userId) { - String args1 = "[{\"boxNo\":\"" + boxNo + "\",\"chInfo\":\"" - + chInfo + "\",\"userId\":\"" + userId + "\"}]"; - return RpcUtil.request("alipay.antsports.walk.treasureBox.openTreasureBox", args1); - } - - public static String queryProjectList(int index) { - String args1 = "[{\"chInfo\":\"" + chInfo + "\",\"index\":" - + index + ",\"projectListUseVertical\":true}]"; - return RpcUtil.request("alipay.antsports.walk.charity.queryProjectList", args1); - } - - public static String donate(int donateCharityCoin, String projectId) { - String args1 = "[{\"chInfo\":\"" + chInfo + "\",\"donateCharityCoin\":" - + donateCharityCoin + ",\"projectId\":\"" + projectId + "\"}]"; - return RpcUtil.request("alipay.antsports.walk.charity.donate", args1); - } - - public static String queryWalkStep() { - String args1 = "[{\"timeZone\":\"" + timeZone + "\"}]"; - return RpcUtil.request("alipay.antsports.walk.user.queryWalkStep", args1); - } - - public static String exchange(int count, int ver) { - String args1 = "[{\"actId\":\"\",\"count\":" + count - + ",\"timezone\":\"" + timeZone + "\",\"ver\":" - + ver + ",\"version\":\"" + version + "\"}]"; - return RpcUtil.request("alipay.charity.mobile.donate.exchange", args1); - } - - public static String exchangeSuccess(String exchangeId) { - String args1 = "[{\"exchangeId\":\"" + exchangeId - + "\",\"timezone\":\"GMT+08:00\",\"version\":\"" + version + "\"}]"; - return RpcUtil.request("alipay.charity.mobile.donate.exchange.success", args1); - } +public class AntSportsRpcCall { + private static final String chInfo = "ch_appcenter__chsub_9patch", + timeZone = "Asia\\/Shanghai", version = "3.0.1.2", alipayAppVersion = "0.0.852"; + + public static String queryCoinBubbleModule() { + return RpcUtil.request("com.alipay.sportshealth.biz.rpc.sportsHealthHomeRpc.queryCoinBubbleModule", + "[{\"bubbleId\":\"\",\"canAddHome\":false,\"chInfo\":\"" + chInfo + + "\",\"clientAuthStatus\":\"not_support\",\"clientOS\":\"android\",\"distributionChannel\":\"\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_AI\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"]}]"); + } + + public static String receiveCoinAsset(String assetId, int coinAmount) { + return RpcUtil.request("com.alipay.sportshealth.biz.rpc.SportsHealthCoinCenterRpc.receiveCoinAsset", + "[{\"assetId\":\"" + assetId + + "\",\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"coinAmount\":" + + coinAmount + + ",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"tracertPos\":\"首页金币收集\"}]"); + } + + public static String queryMyHomePage() { + return RpcUtil.request("alipay.antsports.walk.map.queryMyHomePage", "[{\"alipayAppVersion\":\"" + + alipayAppVersion + "\",\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"pathListUsePage\":true,\"timeZone\":\"" + + timeZone + "\"}]"); + } + + public static String join(String pathId) { + return RpcUtil.request("alipay.antsports.walk.map.join", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"pathId\":\"" + + pathId + "\"}]"); + } + + public static String openAndJoinFirst() { + return RpcUtil.request("alipay.antsports.walk.user.openAndJoinFirst", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"]}]"); + } + + public static String go(String day, String rankCacheKey, int stepCount) { + return RpcUtil.request("alipay.antsports.walk.map.go", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"day\":\"" + day + + "\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"needAllBox\":true,\"rankCacheKey\":\"" + + chInfo + "\",\"timeZone\":\"" + timeZone + "\",\"useStepCount\":" + stepCount + "}]"); + } + + public static String openTreasureBox(String boxNo, String userId) { + return RpcUtil.request("alipay.antsports.walk.treasureBox.openTreasureBox", "[{\"boxNo\":\"" + boxNo + + "\",\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"userId\":\"" + + userId + "\"}]"); + } + + public static String queryProjectList(int index) { + return RpcUtil.request("alipay.antsports.walk.charity.queryProjectList", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"index\":" + + index + ",\"projectListUseVertical\":true}]"); + } + + public static String donate(int donateCharityCoin, String projectId) { + return RpcUtil.request("alipay.antsports.walk.charity.donate", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"donateCharityCoin\":" + donateCharityCoin + + ",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"projectId\":\"" + + projectId + "\"}]"); + } + + public static String queryWalkStep() { + return RpcUtil.request("alipay.antsports.walk.user.queryWalkStep", "[{\"chInfo\":\"" + chInfo + + "\",\"clientOS\":\"android\",\"features\":[\"DAILY_STEPS_RANK_V2\",\"STEP_BATTLE\",\"CLUB_HOME_CARD\",\"NEW_HOME_PAGE_STATIC\",\"CLOUD_SDK_AUTH\",\"STAY_ON_COMPLETE\",\"EXTRA_TREASURE_BOX\",\"NEW_HOME_PAGE_STATIC\",\"SUPPORT_TAB3\",\"SUPPORT_FLYRABBIT\",\"PROP\",\"PROPV2\",\"ASIAN_GAMES\"],\"timeZone\":\"" + + timeZone + "\"}]"); + } + + public static String walkDonateSignInfo(int count) { + return RpcUtil.request("alipay.charity.mobile.donate.walk.walkDonateSignInfo", + "[{\"needDonateAction\":false,\"source\":\"walkDonateHome\",\"steps\":" + count + + ",\"timezoneId\":\"" + + timeZone + "\"}]"); + } + + public static String donateWalkHome(int count) { + return RpcUtil.request("alipay.charity.mobile.donate.walk.home", + "[{\"module\":\"3\",\"steps\":" + count + ",\"timezoneId\":\"" + timeZone + "\"}]"); + } + + public static String exchange(String actId, int count, String donateToken) { + return RpcUtil.request("alipay.charity.mobile.donate.walk.exchange", + "[{\"actId\":\"" + actId + "\",\"count\":" + + count + ",\"donateToken\":\"" + donateToken + "\",\"timezoneId\":\"" + + timeZone + "\",\"ver\":0}]"); + } + + /* 这个好像没用 */ + public static String exchangeSuccess(String exchangeId) { + String args1 = "[{\"exchangeId\":\"" + exchangeId + + "\",\"timezone\":\"GMT+08:00\",\"version\":\"" + version + "\"}]"; + return RpcUtil.request("alipay.charity.mobile.donate.exchange.success", args1); + } } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/EcoLifeRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/EcoLifeRpcCall.java new file mode 100644 index 000000000..149c3fe0c --- /dev/null +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/EcoLifeRpcCall.java @@ -0,0 +1,41 @@ +package pansong291.xposed.quickenergy.hook; + +public class EcoLifeRpcCall { + + public static String queryHomePage() { + return RpcUtil.request("alipay.ecolife.rpc.h5.queryHomePage", + "[{\"channel\":\"ALIPAY\",\"source\":\"search_brandbox\"}]"); + } + + public static String tick(String actionId, String channel, String dayPoint, boolean photoguangpan) { + String args1 = null; + if (photoguangpan) { + args1 = "[{\"actionId\":\"photoguangpan\",\"channel\":\"" + channel + "\",\"dayPoint\":\"" + dayPoint + + "\",\"source\":\"search_brandbox\"}]"; + } else { + args1 = "[{\"actionId\":\"" + actionId + "\",\"channel\":\"" + + channel + "\",\"dayPoint\":\"" + dayPoint + + "\",\"generateEnergy\":false,\"source\":\"search_brandbox\"}]"; + } + return RpcUtil.request("alipay.ecolife.rpc.h5.tick", args1); + } + + public static String uploadDishImageBeforeMeals(String channel, String dayPoint) { + return RpcUtil.request("alipay.ecolife.rpc.h5.uploadDishImage", + "[{\"channel\":\"" + channel + "\",\"dayPoint\":\"" + dayPoint + + "\",\"source\":\"photo-comparison\",\"uploadParamMap\":{\"AIResult\":[{\"conf\":0.016113121,\"kvPair\":false,\"label\":\"other\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"},{\"conf\":0.00046864362,\"kvPair\":false,\"label\":\"guangpan\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"},{\"conf\":0.9834183,\"kvPair\":false,\"label\":\"feiguangpan\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"}],\"existAIResult\":true,\"imageId\":\"A*khE0QbDOJTsAAAAAAAAAAAAAAQAAAQ\",\"imageUrl\":\"https://mdn.alipayobjects.com/afts/img/A*khE0QbDOJTsAAAAAAAAAAAAAAQAAAQ/original?bz=APM_20000067\",\"operateType\":\"BEFORE_MEALS\"}}]"); + } + + public static String uploadDishImageAfterMeals(String channel, String dayPoint) { + return RpcUtil.request("alipay.ecolife.rpc.h5.uploadDishImage", + "[{\"channel\":\"" + channel + "\",\"dayPoint\":\"" + dayPoint + + "\",\"source\":\"photo-comparison\",\"uploadParamMap\":{\"AIResult\":[{\"conf\":0.00018646188,\"kvPair\":false,\"label\":\"other\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"},{\"conf\":0.9997553,\"kvPair\":false,\"label\":\"guangpan\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"},{\"conf\":0.00005811434,\"kvPair\":false,\"label\":\"feiguangpan\",\"pos\":[1,0.2213781,0.0012539185,0.7786219],\"value\":\"\"}],\"existAIResult\":true,\"imageId\":\"A*-r7VRbaQS_kAAAAAAAAAAAAAAQAAAQ\",\"imageUrl\":\"https://mdn.alipayobjects.com/afts/img/A*-r7VRbaQS_kAAAAAAAAAAAAAAQAAAQ/original?bz=APM_20000067\",\"operateType\":\"AFTER_MEALS\"}}]"); + } + + public static String queryDish(String channel, String dayPoint) { + return RpcUtil.request("alipay.ecolife.rpc.h5.queryDish", + "[{\"channel\":\"" + channel + "\",\"dayPoint\":\"" + dayPoint + + "\",\"source\":\"photo-comparison\"}]"); + } + +} diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/ReserveRpcCall.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/ReserveRpcCall.java new file mode 100644 index 000000000..d40233897 --- /dev/null +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/ReserveRpcCall.java @@ -0,0 +1,25 @@ +package pansong291.xposed.quickenergy.hook; + +public class ReserveRpcCall { + private static final String VERSION = "20230501"; + private static final String VERSION2 = "20230522"; + + public static String queryTreeItemsForExchange() { + return RpcUtil.request("alipay.antforest.forest.h5.queryTreeItemsForExchange", + "[{\"cityCode\":\"370100\",\"itemTypes\":\"\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\",\"version\":\"" + + VERSION2 + "\"}]"); + } + + public static String queryTreeForExchange(String projectId) { + return RpcUtil.request("alipay.antforest.forest.h5.queryTreeForExchange", "[{\"projectId\":\"" + projectId + + "\",\"version\":\"" + VERSION + "\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\"}]"); + } + + public static String exchangeTree(String projectId) { + int projectId_num = Integer.parseInt(projectId); + return RpcUtil.request("alipay.antmember.forest.h5.exchangeTree", + "[{\"projectId\":" + projectId_num + ",\"sToken\":\"" + System.currentTimeMillis() + "\",\"version\":\"" + + VERSION + "\",\"source\":\"chInfo_ch_appcenter__chsub_9patch\"}]"); + } + +} diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java index 9629bad2c..90188bb56 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/RpcUtil.java @@ -59,6 +59,7 @@ public static String request(String args0, String args1) { if (jo.optString("memo", "").contains("系统繁忙")) { isInterruptted = true; AntForestNotification.setContentText("系统繁忙,可能需要滑动验证"); + Log.recordLog("系统繁忙,可能需要滑动验证"); return str; } } catch (Throwable ignored) { } @@ -82,6 +83,7 @@ public static String request(String args0, String args1) { long waitTime = System.currentTimeMillis() + Config.waitWhenException(); Config.setForestPauseTime(waitTime); AntForestNotification.setContentText("请求不合法,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); + Log.recordLog("触发异常,等待至" + DateFormat.getDateTimeInstance().format(waitTime)); } } else if (msg.contains("MMTPException")) { return "{\"resultCode\":\"FAIL\",\"memo\":\"MMTPException\",\"resultDesc\":\"MMTPException\"}"; diff --git a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java index 91854debf..c94f8257b 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/hook/XposedHook.java @@ -93,8 +93,12 @@ public void run() { } else { AntCooperate.start(); AntFarm.start(); + Reserve.start(); + if (TimeUtil.getTimeStr().compareTo("0800") >= 0) { + AncientTree.start(); + } + AntSports.start(XposedHook.classLoader, times-1); AntMember.receivePoint(); - AncientTree.start(); handler.postDelayed(this, Config.checkInterval()); } } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/AlipayReserve.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/AlipayReserve.java new file mode 100644 index 000000000..da2353e64 --- /dev/null +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/AlipayReserve.java @@ -0,0 +1,38 @@ +package pansong291.xposed.quickenergy.ui; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import pansong291.xposed.quickenergy.util.ReserveIdMap; + +public class AlipayReserve extends IdAndName { + private static List list; + + public AlipayReserve(String i, String n) { + id = i; + name = n; + } + + public static List getList() { + if (list == null || ReserveIdMap.shouldReload) { + list = new ArrayList<>(); + Set> idSet = ReserveIdMap.getIdMap().entrySet(); + for (Map.Entry entry: idSet) { + list.add(new AlipayReserve(entry.getKey(), entry.getValue())); + } + } + return list; + } + + public static void remove(String id) { + getList(); + for (int i = 0; i < list.size(); i++) { + if(list.get(i).id.equals(id)) { + list.remove(i); + break; + } + } + } + +} diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/EditDialog.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/EditDialog.java index b6865985b..5943eb3de 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/ui/EditDialog.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/EditDialog.java @@ -12,7 +12,7 @@ public class EditDialog { public enum EditMode { CHECK_INTERVAL, THREAD_COUNT, ADVANCE_TIME, COLLECT_INTERVAL, LIMIT_COUNT, DOUBLE_CARD_TIME, COLLECT_TIMEOUT, RETURN_WATER_30, RETURN_WATER_20, RETURN_WATER_10, ANIMAL_SLEEP_TIME, - MIN_EXCHANGE_COUNT, LATEST_EXCHANGE_TIME, SYNC_STEP_COUNT, WAIT_WHEN_EXCEPTION } + MIN_EXCHANGE_COUNT, LATEST_EXCHANGE_TIME, SYNC_STEP_COUNT, WAIT_WHEN_EXCEPTION ,EXCHANGE_ENERGY_DOUBLE_CLICK_COUNT } private static EditMode mode; public static void showEditDialog(Context c, CharSequence title, EditMode em) { @@ -114,6 +114,12 @@ public void onClick(DialogInterface p1, int p2) { Config.setWaitWhenException(i * 60 * 1000); break; + case EXCHANGE_ENERGY_DOUBLE_CLICK_COUNT: + if (i > 0) { + Config.setExchangeEnergyDoubleClickCount(i); + } + break; + } } catch(Throwable ignored) { } } @@ -176,6 +182,10 @@ public void onClick(DialogInterface p1, int p2) { case WAIT_WHEN_EXCEPTION: str = String.valueOf(Config.waitWhenException() / 60 / 1000); break; + + case EXCHANGE_ENERGY_DOUBLE_CLICK_COUNT: + str = String.valueOf(Config.getExchangeEnergyDoubleClickCount()); + break; } edt.setText(str); return editDialog; diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/ListDialog.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/ListDialog.java index 1a365ef6c..1e0e0f1f8 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/ui/ListDialog.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/ListDialog.java @@ -131,9 +131,9 @@ private static void showEdtDialog(Context c) { } edtDialog.setTitle(curIdAndName.name); if(curIdAndName instanceof CooperateUser) - edt_count.setHint("grams"); + edt_count.setHint("浇水克数"); else - edt_count.setHint("count"); + edt_count.setHint("次数"); int i = selectedList.indexOf(curIdAndName.id); if(i >= 0) edt_count.setText(String.valueOf(countList.get(i))); @@ -259,7 +259,7 @@ private static void showDeleteDialog(Context c) deleteDialog = null; getDeleteDialog(c).show(); } - deleteDialog.setTitle("Delete " + curIdAndName.name); + deleteDialog.setTitle("删除 " + curIdAndName.name); } private static AlertDialog getDeleteDialog(Context c) @@ -324,7 +324,7 @@ public void onClick(View p1) } if(index < 0) { - Toast.makeText(p1.getContext(), "Not found", Toast.LENGTH_SHORT).show(); + Toast.makeText(p1.getContext(), "未找到", Toast.LENGTH_SHORT).show(); }else { lv_list.setSelection(index); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/MainActivity.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/MainActivity.java index f5bb09fd5..5b7ce98fb 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/ui/MainActivity.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/MainActivity.java @@ -156,13 +156,13 @@ public boolean onOptionsItemSelected(MenuItem item) { case 2: if (FileUtils.copyTo(FileUtils.getStatisticsFile(), FileUtils.getExportedStatisticsFile())) - Toast.makeText(this, "Export success", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "导出成功!", Toast.LENGTH_SHORT).show(); break; case 3: if (FileUtils.copyTo(FileUtils.getExportedStatisticsFile(), FileUtils.getStatisticsFile())) { tvStatistics.setText(Statistics.getText()); - Toast.makeText(this, "Import success", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "导入成功!", Toast.LENGTH_SHORT).show(); } break; diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/OptionsAdapter.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/OptionsAdapter.java index 0c62b3a7e..fdcc78193 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/ui/OptionsAdapter.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/OptionsAdapter.java @@ -28,9 +28,9 @@ private OptionsAdapter(Context c) { context = c; list = new ArrayList<>(); - list.add("View the forest"); - list.add("View the farm"); - list.add("Delete"); + list.add("查看森林"); + list.add("查看庄园"); + list.add("删除"); } @Override diff --git a/app/src/main/java/pansong291/xposed/quickenergy/ui/SettingsActivity.java b/app/src/main/java/pansong291/xposed/quickenergy/ui/SettingsActivity.java index 7c23d96ba..667b72210 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/ui/SettingsActivity.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/ui/SettingsActivity.java @@ -14,9 +14,9 @@ import pansong291.xposed.quickenergy.util.Config; import pansong291.xposed.quickenergy.util.CooperationIdMap; import pansong291.xposed.quickenergy.util.FriendIdMap; +import pansong291.xposed.quickenergy.util.ReserveIdMap; -public class SettingsActivity extends Activity -{ +public class SettingsActivity extends Activity { CheckBox cb_immediateEffect, cb_recordLog, cb_showToast, cb_stayAwake, cb_timeoutRestart, cb_collectWateringBubble, cb_collectEnergy, cb_helpFriendCollect, cb_receiveForestTaskAward, @@ -26,17 +26,18 @@ public class SettingsActivity extends Activity cb_donation, cb_answerQuestion, cb_receiveFarmTaskAward, cb_feedAnimal, cb_useAccelerateTool, cb_notifyFriend, cb_receivePoint, cb_openTreasureBox, cb_donateCharityCoin, - cb_kbSignIn, cb_limitCollect, cb_doubleCard; + cb_kbSignIn, cb_limitCollect, cb_doubleCard, cb_ExchangeEnergyDoubleClick, cb_reserve, cb_ecoLifeTick, + cb_ancientTree, cb_ancientTreeOnlyWeek, cb_receiveCoinAsset, cb_antdodoCollect; @Override - protected void onCreate(Bundle savedInstanceState) - { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Config.shouldReload = true; FriendIdMap.shouldReload = true; CooperationIdMap.shouldReload = true; + ReserveIdMap.shouldReload = true; cb_immediateEffect = findViewById(R.id.cb_immediateEffect); cb_recordLog = findViewById(R.id.cb_recordLog); @@ -48,7 +49,9 @@ protected void onCreate(Bundle savedInstanceState) cb_helpFriendCollect = findViewById(R.id.cb_helpFriendCollect); cb_receiveForestTaskAward = findViewById(R.id.cb_receiveForestTaskAward); cb_cooperateWater = findViewById(R.id.cb_cooperateWater); + cb_ancientTree = findViewById(R.id.cb_ancientTree); cb_energyRain = findViewById(R.id.cb_energyRain); + cb_reserve = findViewById(R.id.cb_reserve); cb_enableFarm = findViewById(R.id.cb_enableFarm); cb_rewardFriend = findViewById(R.id.cb_rewardFriend); cb_sendBackAnimal = findViewById(R.id.cb_sendBackAnimal); @@ -63,15 +66,19 @@ protected void onCreate(Bundle savedInstanceState) cb_notifyFriend = findViewById(R.id.cb_notifyFriend); cb_receivePoint = findViewById(R.id.cb_receivePoint); cb_openTreasureBox = findViewById(R.id.cb_openTreasureBox); + cb_receiveCoinAsset = findViewById(R.id.cb_receiveCoinAsset); cb_donateCharityCoin = findViewById(R.id.cb_donateCharityCoin); cb_kbSignIn = findViewById(R.id.cb_kbSignIn); cb_limitCollect = findViewById(R.id.cb_limitCollect); cb_doubleCard = findViewById(R.id.cb_doubleCard); + cb_ExchangeEnergyDoubleClick = findViewById(R.id.cb_ExchangeEnergyDoubleClick); + cb_ecoLifeTick = findViewById(R.id.cb_ecoLifeTick); + cb_ancientTreeOnlyWeek = findViewById(R.id.cb_ancientTreeOnlyWeek); + cb_antdodoCollect = findViewById(R.id.cb_antdodoCollect); } @Override - protected void onResume() - { + protected void onResume() { super.onResume(); cb_immediateEffect.setChecked(Config.immediateEffect()); cb_recordLog.setChecked(Config.recordLog()); @@ -83,7 +90,9 @@ protected void onResume() cb_helpFriendCollect.setChecked(Config.helpFriendCollect()); cb_receiveForestTaskAward.setChecked(Config.receiveForestTaskAward()); cb_cooperateWater.setChecked(Config.cooperateWater()); + cb_ancientTree.setChecked(Config.ancientTree()); cb_energyRain.setChecked(Config.energyRain()); + cb_reserve.setChecked(Config.reserve()); cb_enableFarm.setChecked(Config.enableFarm()); cb_rewardFriend.setChecked(Config.rewardFriend()); cb_sendBackAnimal.setChecked(Config.sendBackAnimal()); @@ -98,19 +107,22 @@ protected void onResume() cb_notifyFriend.setChecked(Config.notifyFriend()); cb_receivePoint.setChecked(Config.receivePoint()); cb_openTreasureBox.setChecked(Config.openTreasureBox()); + cb_receiveCoinAsset.setChecked(Config.receiveCoinAsset()); cb_donateCharityCoin.setChecked(Config.donateCharityCoin()); cb_kbSignIn.setChecked(Config.kbSginIn()); cb_limitCollect.setChecked(Config.isLimitCollect()); cb_doubleCard.setChecked(Config.doubleCard()); + cb_ExchangeEnergyDoubleClick.setChecked(Config.ExchangeEnergyDoubleClick()); + cb_ecoLifeTick.setChecked(Config.ecoLifeTick()); + cb_ancientTreeOnlyWeek.setChecked(Config.ancientTreeOnlyWeek()); + cb_antdodoCollect.setChecked(Config.antdodoCollect()); } @SuppressLint("NonConstantResourceId") - public void onClick(View v) - { + public void onClick(View v) { if (v instanceof CheckBox) { - CheckBox cb = (CheckBox)v; - switch(v.getId()) - { + CheckBox cb = (CheckBox) v; + switch (v.getId()) { case R.id.cb_immediateEffect: Config.setImmediateEffect(cb.isChecked()); break; @@ -159,10 +171,22 @@ public void onClick(View v) Config.setCooperateWater(cb.isChecked()); break; + case R.id.cb_ancientTree: + Config.setAncientTree(cb.isChecked()); + break; + case R.id.cb_energyRain: Config.setEnergyRain(cb.isChecked()); break; + case R.id.cb_ExchangeEnergyDoubleClick: + Config.setExchangeEnergyDoubleClick(cb.isChecked()); + break; + + case R.id.cb_reserve: + Config.setReserve(cb.isChecked()); + break; + case R.id.cb_enableFarm: Config.setEnableFarm(cb.isChecked()); break; @@ -219,6 +243,10 @@ public void onClick(View v) Config.setOpenTreasureBox(cb.isChecked()); break; + case R.id.cb_receiveCoinAsset: + Config.setReceiveCoinAsset(cb.isChecked()); + break; + case R.id.cb_donateCharityCoin: Config.setDonateCharityCoin(cb.isChecked()); break; @@ -226,6 +254,18 @@ public void onClick(View v) case R.id.cb_kbSignIn: Config.setKbSginIn(cb.isChecked()); break; + + case R.id.cb_ecoLifeTick: + Config.setEcoLifeTick(cb.isChecked()); + break; + + case R.id.cb_ancientTreeOnlyWeek: + Config.setAncientTreeOnlyWeek(cb.isChecked()); + break; + + case R.id.cb_antdodoCollect: + Config.setAntdodoCollect(cb.isChecked()); + break; } } else if (v instanceof Button) { Button btn = (Button)v; @@ -287,15 +327,21 @@ public void onClick(View v) break; case R.id.btn_cooperateWaterList: - ListDialog.show(this, btn.getText(), CooperateUser.getList(), Config.getCooperateWaterList(), Config.getcooperateWaterNumList()); + ListDialog.show(this, btn.getText(), CooperateUser.getList(), Config.getCooperateWaterList(), + Config.getcooperateWaterNumList()); + break; + + case R.id.btn_ancientTreeAreaCodeList: + ListDialog.show(this, btn.getText(), AreaCode.getList(), Config.getAncientTreeAreaCodeList(), null); break; case R.id.btn_giveEnergyRainList: ListDialog.show(this, btn.getText(), AlipayUser.getList(), Config.getGiveEnergyRainList(), null); break; - case R.id.btn_ancientTreeAreaCodeList: - ListDialog.show(this, btn.getText(), AreaCode.getList(), Config.getAncientTreeAreaCodeList(), null); + case R.id.btn_reserveList: + ListDialog.show(this, btn.getText(), AlipayReserve.getList(), Config.getReserveList(), + Config.getReserveCountList()); break; case R.id.btn_sendType: @@ -349,6 +395,11 @@ public void onClick(View v) case R.id.btn_waitWhenException: EditDialog.showEditDialog(this, btn.getText(), EditDialog.EditMode.WAIT_WHEN_EXCEPTION); break; + + case R.id.btn_ExchangeEnergyDoubleClickCount: + EditDialog.showEditDialog(this, btn.getText(), + EditDialog.EditMode.EXCHANGE_ENERGY_DOUBLE_CLICK_COUNT); + break; } } } @@ -358,10 +409,11 @@ protected void onPause() { super.onPause(); if(Config.hasChanged) { Config.hasChanged = !Config.saveConfigFile(); - Toast.makeText(this, "Configuration saved", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "保存成功!", Toast.LENGTH_SHORT).show(); } FriendIdMap.saveIdMap(); CooperationIdMap.saveIdMap(); + ReserveIdMap.saveIdMap(); } } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/Config.java b/app/src/main/java/pansong291/xposed/quickenergy/util/Config.java index e70ee870b..377d29259 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/Config.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/Config.java @@ -43,7 +43,6 @@ public CharSequence nickName() public static final String jn_ReturnWater18 = "returnWater20"; public static final String jn_ReturnWater10 = "returnWater10"; public static final String jn_helpFriendCollect = "helpFriendCollect"; - public static final String jn_ancientTreeAreaCodeList = "ancientTreeAreaCodeList"; public static final String jn_dontCollectList = "dontCollectList"; public static final String jn_dontHelpCollectList = "dontHelpCollectList"; public static final String jn_checkInterval = "checkInterval"; @@ -56,9 +55,14 @@ public CharSequence nickName() public static final String jn_waterFriendList = "waterFriendList"; public static final String jn_cooperateWater = "cooperateWater"; public static final String jn_cooperateWaterList = "cooperateWaterList"; + public static final String jn_ancientTree = "ancientTree"; + public static final String jn_ancientTreeAreaCodeList = "ancientTreeAreaCodeList"; + public static final String jn_reserve = "reserve"; + public static final String jn_reserveList = "reserveList"; public static final String jn_energyRain = "energyRain"; public static final String jn_giveEnergyRainList = "giveEnergyRainList"; public static final String jn_waitWhenException = "waitWhenException"; + public static final String jn_ancientTreeOnlyWeek = "ancientTreeOnlyWeek"; /* farm */ public static final String jn_enableFarm = "enableFarm"; public static final String jn_rewardFriend = "rewardFriend"; @@ -78,14 +82,18 @@ public CharSequence nickName() public static final String jn_animalSleepTime = "animalSleepTime"; public static final String jn_notifyFriend = "notifyFriend"; public static final String jn_dontNotifyFriendList = "dontNotifyFriendList"; + public static final String jn_antdodoCollect = "antdodoCollect"; + /* other */ public static final String jn_receivePoint = "receivePoint"; public static final String jn_openTreasureBox = "openTreasureBox"; + public static final String jn_receiveCoinAsset = "receiveCoinAsset"; public static final String jn_donateCharityCoin = "donateCharityCoin"; public static final String jn_minExchangeCount = "minExchangeCount"; public static final String jn_latestExchangeTime = "latestExchangeTime"; public static final String jn_syncStepCount = "syncStepCount"; public static final String jn_kbSignIn = "kbSignIn"; + public static final String jn_ecoLifeTick = "ecoLifeTick"; public static boolean shouldReload; public static boolean hasChanged; @@ -124,14 +132,23 @@ public CharSequence nickName() private List waterCountList; private boolean cooperateWater; private List cooperateWaterList; + private List syncStepList; private List cooperateWaterNumList; + private boolean ancientTree; + private List ancientTreeAreaCodeList; private boolean energyRain; + private boolean reserve; + private List reserveList; + private List reserveCountList; + private boolean ancientTreeOnlyWeek; private List giveEnergyRainList; private int waitWhenException; - private List ancientTreeAreaCodeList; + private boolean exchangeEnergyDoubleClick; + private int exchangeEnergyDoubleClickCount; + private boolean antdodoCollect; /* farm */ private boolean enableFarm; @@ -158,11 +175,13 @@ public CharSequence nickName() /* other */ private boolean receivePoint; private boolean openTreasureBox; + private boolean receiveCoinAsset; private boolean donateCharityCoin; private int minExchangeCount; private int latestExchangeTime; private int syncStepCount; private boolean kbSignIn; + private boolean ecoLifeTick; /* base */ private static Config config; @@ -297,11 +316,6 @@ public static int waitWhenException() return getConfig().waitWhenException; } - public static List getAncientTreeAreaCodeList() - { - return getConfig().ancientTreeAreaCodeList; - } - public static boolean isLimitCollect() { return getConfig().limitCollect; } @@ -474,6 +488,43 @@ public static List getcooperateWaterNumList() return getConfig().cooperateWaterNumList; } + public static void setAncientTree(boolean b) + { + getConfig().ancientTree = b; + hasChanged = true; + } + + public static boolean ancientTree() + { + return getConfig().ancientTree; + } + + public static List getAncientTreeAreaCodeList() + { + return getConfig().ancientTreeAreaCodeList; + } + + public static void setReserve(boolean b) + { + getConfig().reserve = b; + hasChanged = true; + } + + public static boolean reserve() + { + return getConfig().reserve; + } + + public static List getReserveList() + { + return getConfig().reserveList; + } + + public static List getReserveCountList() + { + return getConfig().reserveCountList; + } + public static void setEnergyRain(boolean b) { getConfig().energyRain = b; @@ -490,6 +541,46 @@ public static boolean energyRain() return getConfig().energyRain; } + public static boolean ExchangeEnergyDoubleClick() { + return getConfig().exchangeEnergyDoubleClick; + } + + public static void setExchangeEnergyDoubleClick(boolean exchangeEnergyDoubleClick) { + getConfig().exchangeEnergyDoubleClick = exchangeEnergyDoubleClick; + hasChanged = true; + } + + public static int getExchangeEnergyDoubleClickCount() { + return getConfig().exchangeEnergyDoubleClickCount; + } + + public static void setExchangeEnergyDoubleClickCount(int exchangeEnergyDoubleClickCount) { + getConfig().exchangeEnergyDoubleClickCount = exchangeEnergyDoubleClickCount; + hasChanged = true; + } + + public static void setAncientTreeOnlyWeek(boolean b) + { + getConfig().ancientTreeOnlyWeek = b; + hasChanged = true; + } + + public static boolean ancientTreeOnlyWeek() + { + return getConfig().ancientTreeOnlyWeek; + } + + public static void setAntdodoCollect(boolean b) + { + getConfig().antdodoCollect = b; + hasChanged = true; + } + + public static boolean antdodoCollect() + { + return getConfig().antdodoCollect; + } + /* farm */ public static void setEnableFarm(boolean b) { @@ -717,6 +808,17 @@ public static boolean openTreasureBox() return getConfig().openTreasureBox; } + public static void setReceiveCoinAsset(boolean b) + { + getConfig().receiveCoinAsset = b; + hasChanged = true; + } + + public static boolean receiveCoinAsset() + { + return getConfig().receiveCoinAsset; + } + public static void setDonateCharityCoin(boolean b) { getConfig().donateCharityCoin = b; @@ -767,16 +869,21 @@ public static void setKbSginIn(boolean b) hasChanged = true; } - public static boolean kbSginIn() - { + public static boolean kbSginIn() { return getConfig().kbSignIn; } + public static void setEcoLifeTick(boolean b) { + getConfig().ecoLifeTick = b; + hasChanged = true; + } + + public static boolean ecoLifeTick() { + return getConfig().ecoLifeTick; + } /* base */ - private static Config getConfig() - { - if(config == null || shouldReload && config.immediateEffect) - { + private static Config getConfig() { + if(config == null || shouldReload && config.immediateEffect) { shouldReload = false; String confJson = null; if(FileUtils.getConfigFile().exists()) @@ -803,7 +910,6 @@ public static Config defInit() c.collectWateringBubble = true; c.checkInterval = 720_000; c.waitWhenException = 60 * 60 * 1000; - c.ancientTreeAreaCodeList = new ArrayList<>(); c.limitCollect = true; c.limitCount = 50; c.doubleCard = false; @@ -823,9 +929,19 @@ public static Config defInit() if(c.waterCountList == null) c.waterCountList = new ArrayList<>(); c.cooperateWater = true; if(c.cooperateWaterList == null) c.cooperateWaterList = new ArrayList<>(); + if(c.syncStepList == null) c.syncStepList = new ArrayList<>(); if(c.cooperateWaterNumList == null) c.cooperateWaterNumList = new ArrayList<>(); + c.ancientTree = true; + c.ancientTreeAreaCodeList = new ArrayList<>(); + c.reserve = true; + if(c.reserveList == null) c.reserveList = new ArrayList<>(); + if(c.reserveCountList == null) c.reserveCountList = new ArrayList<>(); c.energyRain = true; if(c.giveEnergyRainList == null) c.giveEnergyRainList = new ArrayList<>(); + c.exchangeEnergyDoubleClick = false; + c.exchangeEnergyDoubleClickCount = 6; + c.ancientTreeOnlyWeek = true; + c.antdodoCollect = true; c.enableFarm = true; c.rewardFriend = true; @@ -851,9 +967,11 @@ public static Config defInit() c.receivePoint = true; c.openTreasureBox = true; - c.donateCharityCoin = true; + c.receiveCoinAsset = true; + c.donateCharityCoin = false; c.kbSignIn = true; c.syncStepCount = 22000; + c.ecoLifeTick = true; return c; } @@ -895,14 +1013,6 @@ public static Config json2Config(String json) config.waitWhenException = jo.optInt(jn_waitWhenException, 60 * 60 * 1000); - config.ancientTreeAreaCodeList = new ArrayList<>(); - if (jo.has(jn_ancientTreeAreaCodeList)) { - ja = jo.getJSONArray(jn_ancientTreeAreaCodeList); - for(int i = 0; i < ja.length(); i++) { - config.ancientTreeAreaCodeList.add(ja.getString(i)); - } - } - config.limitCollect = jo.optBoolean("limitCollect", true); config.limitCount = jo.optInt("limitCount", 50); @@ -971,6 +1081,17 @@ public static Config json2Config(String json) config.cooperateWaterNumList.add(jaa.getInt(1)); } } + + config.ancientTree = jo.optBoolean(jn_ancientTree, true); + + config.ancientTreeAreaCodeList = new ArrayList<>(); + if (jo.has(jn_ancientTreeAreaCodeList)) { + ja = jo.getJSONArray(jn_ancientTreeAreaCodeList); + for(int i = 0; i < ja.length(); i++) { + config.ancientTreeAreaCodeList.add(ja.getString(i)); + } + } + config.energyRain = jo.optBoolean(jn_energyRain, true); config.giveEnergyRainList = new ArrayList<>(); if(jo.has(jn_giveEnergyRainList)) { @@ -981,6 +1102,31 @@ public static Config json2Config(String json) } } + config.reserve = jo.optBoolean(jn_reserve, true); + config.reserveList = new ArrayList<>(); + config.reserveCountList = new ArrayList<>(); + if(jo.has(jn_reserveList)) { + ja = jo.getJSONArray(jn_reserveList); + for(int i = 0; i < ja.length(); i++) { + if(ja.get(i) instanceof JSONArray) { + jaa = ja.getJSONArray(i); + config.reserveList.add(jaa.getString(0)); + config.reserveCountList.add(jaa.getInt(1)); + } else { + config.reserveList.add(ja.getString(i)); + config.reserveCountList.add(2); + } + } + } + + config.exchangeEnergyDoubleClick = jo.optBoolean("exchangeEnergyDoubleClick", false); + + config.exchangeEnergyDoubleClickCount = jo.optInt("exchangeEnergyDoubleClickCount", 6); + + config.ancientTreeOnlyWeek = jo.optBoolean(jn_ancientTreeOnlyWeek, true); + + config.antdodoCollect = jo.optBoolean(jn_antdodoCollect, true); + /* farm */ config.enableFarm = jo.optBoolean(jn_enableFarm, true); @@ -1049,7 +1195,9 @@ public static Config json2Config(String json) config.openTreasureBox = jo.optBoolean(jn_openTreasureBox, true); - config.donateCharityCoin = jo.optBoolean(jn_donateCharityCoin, true); + config.receiveCoinAsset = jo.optBoolean(jn_receiveCoinAsset, true); + + config.donateCharityCoin = jo.optBoolean(jn_donateCharityCoin, false); config.minExchangeCount = jo.optInt(jn_minExchangeCount); @@ -1059,6 +1207,8 @@ public static Config json2Config(String json) config.kbSignIn = jo.optBoolean(jn_kbSignIn, true); + config.ecoLifeTick = jo.optBoolean(jn_ecoLifeTick, true); + } catch(Throwable t) { Log.printStackTrace(TAG, t); if(json != null) { @@ -1107,12 +1257,6 @@ public static String config2Json(Config config) { jo.put(jn_waitWhenException, config.waitWhenException); - ja = new JSONArray(); - for (String s : config.ancientTreeAreaCodeList) { - ja.put(s); - } - jo.put(jn_ancientTreeAreaCodeList, ja); - jo.put("limitCollect", config.limitCollect); jo.put("limitCount", config.limitCount); @@ -1172,6 +1316,27 @@ public static String config2Json(Config config) { } jo.put(jn_cooperateWaterList, ja); + jo.put(jn_ancientTree, config.ancientTree); + + + ja = new JSONArray(); + for (String s : config.ancientTreeAreaCodeList) { + ja.put(s); + } + jo.put(jn_ancientTreeAreaCodeList, ja); + + jo.put(jn_reserve, config.reserve); + + ja = new JSONArray(); + for(int i = 0; i < config.reserveList.size(); i++) + { + jaa = new JSONArray(); + jaa.put(config.reserveList.get(i)); + jaa.put(config.reserveCountList.get(i)); + ja.put(jaa); + } + jo.put(jn_reserveList, ja); + jo.put(jn_energyRain, config.energyRain); ja = new JSONArray(); for(int i = 0; i < config.giveEnergyRainList.size(); i++) @@ -1182,6 +1347,14 @@ public static String config2Json(Config config) { } jo.put(jn_giveEnergyRainList, ja); + jo.put("exchangeEnergyDoubleClick", config.exchangeEnergyDoubleClick); + + jo.put("exchangeEnergyDoubleClickCount", config.exchangeEnergyDoubleClickCount); + + jo.put(jn_ancientTreeOnlyWeek, config.ancientTreeOnlyWeek); + + jo.put(jn_antdodoCollect, config.antdodoCollect); + /* farm */ jo.put(jn_enableFarm, config.enableFarm); @@ -1242,6 +1415,8 @@ public static String config2Json(Config config) { jo.put(jn_openTreasureBox, config.openTreasureBox); + jo.put(jn_receiveCoinAsset, config.receiveCoinAsset); + jo.put(jn_donateCharityCoin, config.donateCharityCoin); jo.put(jn_minExchangeCount, config.minExchangeCount); @@ -1252,8 +1427,9 @@ public static String config2Json(Config config) { jo.put(jn_kbSignIn, config.kbSignIn); - }catch(Throwable t) - { + jo.put(jn_ecoLifeTick, config.ecoLifeTick); + + } catch(Throwable t) { Log.printStackTrace(TAG, t); } return formatJson(jo, false); diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java b/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java index 37ff16205..4582f5445 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/FileUtils.java @@ -1,20 +1,24 @@ package pansong291.xposed.quickenergy.util; import android.os.Environment; -import pansong291.xposed.quickenergy.R; import java.io.Closeable; import java.io.File; import java.io.FileReader; import java.io.FileWriter; +import java.util.HashMap; +import java.util.Map; public class FileUtils { private static final String TAG = FileUtils.class.getCanonicalName(); + private static File mainDirectory; private static File configDirectory; - private static File configFile; + private static Map configFileMap = new HashMap<>(); private static File friendIdMapFile; private static File cooperationIdMapFile; + private static File reserveIdMapFile; + private static File cityCodeMapFile; private static File statisticsFile; private static File exportedStatisticsFile; private static File forestLogFile; @@ -25,9 +29,25 @@ public class FileUtils private static File cityCodeFile; @SuppressWarnings("deprecation") + public static File getMainDirectoryFile() { + if(mainDirectory == null) { + mainDirectory = new File(Environment.getExternalStorageDirectory(), "xqe"); + if(mainDirectory.exists()) { + if(mainDirectory.isFile()) + { + mainDirectory.delete(); + mainDirectory.mkdirs(); + } + } else { + mainDirectory.mkdirs(); + } + } + return mainDirectory; + } + public static File getConfigDirectoryFile() { if(configDirectory == null) { - configDirectory = new File(Environment.getExternalStorageDirectory(), "xqe"); + configDirectory = new File(Environment.getExternalStorageDirectory(), "xqe/config"); if(configDirectory.exists()) { if(configDirectory.isFile()) { @@ -43,7 +63,7 @@ public static File getConfigDirectoryFile() { public static File getCityCodeFile() { if(cityCodeFile == null) { - cityCodeFile = new File(getConfigDirectoryFile(), "cityCode.json"); + cityCodeFile = new File(getMainDirectoryFile(), "cityCode.json"); if(cityCodeFile.exists() && cityCodeFile.isDirectory()) cityCodeFile.delete(); } @@ -51,17 +71,29 @@ public static File getCityCodeFile() { } public static File getConfigFile() { - if(configFile == null) { - configFile = new File(getConfigDirectoryFile(), "config.json"); - if(configFile.exists() && configFile.isDirectory()) - configFile.delete(); + return getConfigFile(null); + } + + public static File getConfigFile(String userId) { + if (!configFileMap.containsKey("Default")) { + File configFile = new File(getMainDirectoryFile(), "config.json"); + configFileMap.put("Default", configFile); } - return configFile; + if (!StringUtil.isEmpty(userId)) { + if (!configFileMap.containsKey(userId)) { + File configFile = new File(getConfigDirectoryFile(), "config-" + userId + ".json"); + if (configFile.exists()) { + configFileMap.put(userId, configFile); + return configFile; + } + } + } + return configFileMap.get("Default"); } public static File getFriendIdMapFile() { if(friendIdMapFile == null) { - friendIdMapFile = new File(getConfigDirectoryFile(), "friendId.list"); + friendIdMapFile = new File(getMainDirectoryFile(), "friendId.list"); if(friendIdMapFile.exists() && friendIdMapFile.isDirectory()) friendIdMapFile.delete(); } @@ -70,16 +102,34 @@ public static File getFriendIdMapFile() { public static File getCooperationIdMapFile() { if(cooperationIdMapFile == null) { - cooperationIdMapFile = new File(getConfigDirectoryFile(), "cooperationId.list"); + cooperationIdMapFile = new File(getMainDirectoryFile(), "cooperationId.list"); if(cooperationIdMapFile.exists() && cooperationIdMapFile.isDirectory()) cooperationIdMapFile.delete(); } return cooperationIdMapFile; } + public static File getReserveIdMapFile() { + if (reserveIdMapFile == null) { + reserveIdMapFile = new File(getMainDirectoryFile(), "reserveId.list"); + if (reserveIdMapFile.exists() && reserveIdMapFile.isDirectory()) + reserveIdMapFile.delete(); + } + return reserveIdMapFile; + } + + public static File getCityCodeMapFile() { + if (cityCodeMapFile == null) { + cityCodeMapFile = new File(getMainDirectoryFile(), "cityCode.list"); + if (cityCodeMapFile.exists() && cityCodeMapFile.isDirectory()) + cityCodeMapFile.delete(); + } + return cityCodeMapFile; + } + public static File getStatisticsFile() { if(statisticsFile == null) { - statisticsFile = new File(getConfigDirectoryFile(), "statistics.json"); + statisticsFile = new File(getMainDirectoryFile(), "statistics.json"); if(statisticsFile.exists() && statisticsFile.isDirectory()) statisticsFile.delete(); } @@ -88,7 +138,7 @@ public static File getStatisticsFile() { public static File getExportedStatisticsFile() { if(exportedStatisticsFile == null) { - exportedStatisticsFile = new File(getConfigDirectoryFile(), "statistics.json"); + exportedStatisticsFile = new File(getMainDirectoryFile(), "statistics.json"); if(exportedStatisticsFile.exists() && exportedStatisticsFile.isDirectory()) exportedStatisticsFile.delete(); } @@ -97,7 +147,7 @@ public static File getExportedStatisticsFile() { public static File getForestLogFile() { if(forestLogFile == null) { - forestLogFile = new File(getConfigDirectoryFile(), "forest.log"); + forestLogFile = new File(getMainDirectoryFile(), "forest.log"); if(forestLogFile.exists() && forestLogFile.isDirectory()) forestLogFile.delete(); if(!forestLogFile.exists()) @@ -110,7 +160,7 @@ public static File getForestLogFile() { public static File getFarmLogFile() { if(farmLogFile == null) { - farmLogFile = new File(getConfigDirectoryFile(), "farm.log"); + farmLogFile = new File(getMainDirectoryFile(), "farm.log"); if(farmLogFile.exists() && farmLogFile.isDirectory()) farmLogFile.delete(); if(!farmLogFile.exists()) @@ -123,7 +173,7 @@ public static File getFarmLogFile() { public static File getOtherLogFile() { if(otherLogFile == null) { - otherLogFile = new File(getConfigDirectoryFile(), "other.log"); + otherLogFile = new File(getMainDirectoryFile(), "other.log"); if(otherLogFile.exists() && otherLogFile.isDirectory()) otherLogFile.delete(); if(!otherLogFile.exists()) @@ -136,7 +186,7 @@ public static File getOtherLogFile() { public static File getSimpleLogFile() { if(simpleLogFile == null) { - simpleLogFile = new File(getConfigDirectoryFile(), "simple.log"); + simpleLogFile = new File(getMainDirectoryFile(), "simple.log"); if(simpleLogFile.exists() && simpleLogFile.isDirectory()) simpleLogFile.delete(); } @@ -145,7 +195,7 @@ public static File getSimpleLogFile() { public static File getRuntimeLogFile() { if(runtimeLogFile == null) { - runtimeLogFile = new File(getConfigDirectoryFile(), "runtime.log"); + runtimeLogFile = new File(getMainDirectoryFile(), "runtime.log"); if(runtimeLogFile.exists() && runtimeLogFile.isDirectory()) runtimeLogFile.delete(); } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/Log.java b/app/src/main/java/pansong291/xposed/quickenergy/util/Log.java index 0f8f06e6f..03bb9c6de 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/Log.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/Log.java @@ -55,4 +55,10 @@ public static String getFormatTime() { return getFormatDateTime().split(" ")[1]; } + public static boolean isAncientTreeWeek() { + SimpleDateFormat sdf_week = new SimpleDateFormat("EEEE", Locale.getDefault()); + String week = sdf_week.format(new Date()); + return "星期一".equals(week) || "星期三".equals(week) || "星期五".equals(week); + } + } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/RandomUtils.java b/app/src/main/java/pansong291/xposed/quickenergy/util/RandomUtils.java index b73f106c0..cd7ff5202 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/RandomUtils.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/RandomUtils.java @@ -15,4 +15,12 @@ public static int nextInt(int min, int max) { return rnd.nextInt(max - min) + min; } + + public static String getRandom(int len) { + StringBuilder rs = new StringBuilder(); + for (int i = 0; i < len; i++) { + rs.append(rnd.nextInt(10)); + } + return rs.toString(); + } } diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/ReserveIdMap.java b/app/src/main/java/pansong291/xposed/quickenergy/util/ReserveIdMap.java new file mode 100644 index 000000000..741e6f66e --- /dev/null +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/ReserveIdMap.java @@ -0,0 +1,75 @@ +package pansong291.xposed.quickenergy.util; + +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +public class ReserveIdMap +{ + private static final String TAG = ReserveIdMap.class.getCanonicalName(); + + public static boolean shouldReload = false; + + private static Map idMap; + private static boolean hasChanged = false; + + public static void putIdMap(String key, String value) { + if(key == null || key.isEmpty()) return; + if(getIdMap().containsKey(key)) { + if(!getIdMap().get(key).equals(value)) { + getIdMap().remove(key); + getIdMap().put(key, value); + hasChanged = true; + } + } else { + getIdMap().put(key, value); + hasChanged = true; + } + } + + public static void removeIdMap(String key) { + if(key == null || key.isEmpty()) return; + if(getIdMap().containsKey(key)) + { + getIdMap().remove(key); + hasChanged = true; + } + } + + public static void saveIdMap() { + if(hasChanged) { + StringBuilder sb = new StringBuilder(); + Set> idSet = getIdMap().entrySet(); + for(Map.Entry entry: idSet) { + sb.append(entry.getKey()); + sb.append(':'); + sb.append(entry.getValue()); + sb.append('\n'); + } + hasChanged = !FileUtils.write2File(sb.toString(), FileUtils.getReserveIdMapFile()); + } + } + + public static Map getIdMap() { + if(idMap == null || shouldReload) { + shouldReload = false; + idMap = new TreeMap<>(); + String str = FileUtils.readFromFile(FileUtils.getReserveIdMapFile()); + if(str != null && str.length() > 0) { + try { + String[] idSet = str.split("\n"); + for(String s: idSet) { + //Log.i(TAG, s); + int ind = s.indexOf(":"); + idMap.put(s.substring(0, ind), s.substring(ind + 1)); + } + } catch(Throwable t) { + Log.printStackTrace(TAG, t); + idMap.clear(); + } + } + } + return idMap; + } + +} diff --git a/app/src/main/java/pansong291/xposed/quickenergy/util/Statistics.java b/app/src/main/java/pansong291/xposed/quickenergy/util/Statistics.java index 0f6a64c24..fb3683b9e 100644 --- a/app/src/main/java/pansong291/xposed/quickenergy/util/Statistics.java +++ b/app/src/main/java/pansong291/xposed/quickenergy/util/Statistics.java @@ -4,26 +4,24 @@ import org.json.JSONArray; import org.json.JSONObject; -public class Statistics -{ - public enum TimeType - { YEAR, MONTH, DAY } +public class Statistics { + public enum TimeType { + YEAR, MONTH, DAY + } - public enum DataType - { TIME, COLLECTED, HELPED, WATERED } + public enum DataType { + TIME, COLLECTED, HELPED, WATERED + } - private static class TimeStatistics - { + private static class TimeStatistics { int time; int collected, helped, watered; - TimeStatistics(int i) - { + TimeStatistics(int i) { reset(i); } - public void reset(int i) - { + public void reset(int i) { time = i; collected = 0; helped = 0; @@ -31,33 +29,41 @@ public void reset(int i) } } - private static class WaterFriendLog - { + private static class WaterFriendLog { String userId; int waterCount = 0; - public WaterFriendLog(String id) - { + + public WaterFriendLog(String id) { userId = id; } } - private static class FeedFriendLog - { + private static class ReserveLog { + String projectId; + int applyCount = 0; + + public ReserveLog(String id) { + projectId = id; + } + } + + private static class FeedFriendLog { String userId; int feedCount = 0; - public FeedFriendLog(String id) - { + + public FeedFriendLog(String id) { userId = id; } } private static final String TAG = Statistics.class.getCanonicalName(); - private static final String - jn_year = "year", jn_month = "month", jn_day = "day", + private static final String jn_year = "year", jn_month = "month", jn_day = "day", jn_collected = "collected", jn_helped = "helped", jn_watered = "watered", - jn_answerQuestionList = "answerQuestionList", + jn_answerQuestionList = "answerQuestionList", jn_syncStepList = "syncStepList", + jn_exchangeList = "exchangeList", jn_questionHint = "questionHint", jn_donationEgg = "donationEgg", jn_memberSignIn = "memberSignIn", - jn_exchange = "exchange", jn_kbSignIn = "kbSignIn", jn_syncStep = "syncStep"; + jn_kbSignIn = "kbSignIn", jn_exchangeDoubleCard = "exchangeDoubleCard", + jn_exchangeTimes = "exchangeTimes"; private TimeStatistics year; private TimeStatistics month; @@ -66,6 +72,12 @@ public FeedFriendLog(String id) // forest private ArrayList waterFriendLogList; private ArrayList cooperateWaterList; + private ArrayList syncStepList; + private ArrayList reserveLogList; +// private ArrayList ancientTreeCityCodeList; + private ArrayList exchangeList; + private int exchangeDoubleCard = 0; + private int exchangeTimes = 0; // farm private ArrayList answerQuestionList; @@ -76,19 +88,16 @@ public FeedFriendLog(String id) // other private int memberSignIn = 0; - private int exchange = 0; private int kbSignIn = 0; private int syncStep = 0; private static Statistics statistics; - public static void addData(DataType dt, int i) - { + public static void addData(DataType dt, int i) { Statistics stat = getStatistics(); resetToday(); - switch(dt) - { + switch (dt) { case COLLECTED: stat.day.collected += i; stat.month.collected += i; @@ -108,13 +117,11 @@ public static void addData(DataType dt, int i) save(); } - public static int getData(TimeType tt, DataType dt) - { + public static int getData(TimeType tt, DataType dt) { Statistics stat = getStatistics(); int data = 0; TimeStatistics ts = null; - switch(tt) - { + switch (tt) { case YEAR: ts = stat.year; break; @@ -125,9 +132,8 @@ public static int getData(TimeType tt, DataType dt) ts = stat.day; break; } - if(ts != null) - switch(dt) - { + if (ts != null) + switch (dt) { case TIME: data = ts.time; break; @@ -159,7 +165,7 @@ public static String getText() { sb.append(getData(TimeType.DAY, DataType.COLLECTED)); sb.append(", 帮 ").append(getData(TimeType.DAY, DataType.HELPED)); sb.append(", 浇 ").append(getData(TimeType.DAY, DataType.WATERED)); - if(stat.questionHint != null && !stat.questionHint.isEmpty()) { + if (stat.questionHint != null && !stat.questionHint.isEmpty()) { sb.append("\nquestion hint : ").append(stat.questionHint); } return sb.toString(); @@ -168,12 +174,13 @@ public static String getText() { public static boolean canWaterFriendToday(String id, int count) { Statistics stat = getStatistics(); int index = -1; - for(int i = 0; i < stat.waterFriendLogList.size(); i++) - if(stat.waterFriendLogList.get(i).userId.equals(id)) { + for (int i = 0; i < stat.waterFriendLogList.size(); i++) + if (stat.waterFriendLogList.get(i).userId.equals(id)) { index = i; break; } - if(index < 0) return true; + if (index < 0) + return true; WaterFriendLog wfl = stat.waterFriendLogList.get(index); return wfl.waterCount < count; } @@ -182,12 +189,12 @@ public static void waterFriendToday(String id, int count) { Statistics stat = getStatistics(); WaterFriendLog wfl; int index = -1; - for(int i = 0; i < stat.waterFriendLogList.size(); i++) - if(stat.waterFriendLogList.get(i).userId.equals(id)) { + for (int i = 0; i < stat.waterFriendLogList.size(); i++) + if (stat.waterFriendLogList.get(i).userId.equals(id)) { index = i; break; } - if(index < 0) { + if (index < 0) { wfl = new WaterFriendLog(id); stat.waterFriendLogList.add(wfl); } else { @@ -197,6 +204,53 @@ public static void waterFriendToday(String id, int count) { save(); } + public static int getReserveTimes(String id) { + Statistics stat = getStatistics(); + int index = -1; + for (int i = 0; i < stat.reserveLogList.size(); i++) + if (stat.reserveLogList.get(i).projectId.equals(id)) { + index = i; + break; + } + if (index < 0) + return 0; + ReserveLog rl = stat.reserveLogList.get(index); + return rl.applyCount; + } + + public static boolean canReserveToday(String id, int count) { + Statistics stat = getStatistics(); + int index = -1; + for (int i = 0; i < stat.reserveLogList.size(); i++) + if (stat.reserveLogList.get(i).projectId.equals(id)) { + index = i; + break; + } + if (index < 0) + return true; + ReserveLog rl = stat.reserveLogList.get(index); + return rl.applyCount < count; + } + + public static void reserveToday(String id, int count) { + Statistics stat = getStatistics(); + ReserveLog rl; + int index = -1; + for (int i = 0; i < stat.reserveLogList.size(); i++) + if (stat.reserveLogList.get(i).projectId.equals(id)) { + index = i; + break; + } + if (index < 0) { + rl = new ReserveLog(id); + stat.reserveLogList.add(rl); + } else { + rl = stat.reserveLogList.get(index); + } + rl.applyCount += count; + save(); + } + public static boolean canCooperateWaterToday(String uid, String coopId) { Statistics stat = getStatistics(); return !stat.cooperateWaterList.contains(uid + "_" + coopId); @@ -205,12 +259,25 @@ public static boolean canCooperateWaterToday(String uid, String coopId) { public static void cooperateWaterToday(String uid, String coopId) { Statistics stat = getStatistics(); String v = uid + "_" + coopId; - if(!stat.cooperateWaterList.contains(v)) { + if (!stat.cooperateWaterList.contains(v)) { stat.cooperateWaterList.add(v); save(); } } +// public static boolean canAncientTreeToday(String cityCode) { +// Statistics stat = getStatistics(); +// return !stat.ancientTreeCityCodeList.contains(cityCode); +// } +// +// public static void ancientTreeToday(String cityCode) { +// Statistics stat = getStatistics(); +// if (!stat.ancientTreeCityCodeList.contains(cityCode)) { +// stat.ancientTreeCityCodeList.add(cityCode); +// save(); +// } +// } + public static boolean canAnswerQuestionToday(String uid) { Statistics stat = getStatistics(); return !stat.answerQuestionList.contains(uid); @@ -218,7 +285,7 @@ public static boolean canAnswerQuestionToday(String uid) { public static void answerQuestionToday(String uid) { Statistics stat = getStatistics(); - if(!stat.answerQuestionList.contains(uid)) { + if (!stat.answerQuestionList.contains(uid)) { stat.answerQuestionList.add(uid); save(); } @@ -226,7 +293,7 @@ public static void answerQuestionToday(String uid) { public static void setQuestionHint(String s) { Statistics stat = getStatistics(); - if(stat.questionHint == null) { + if (stat.questionHint == null) { stat.questionHint = s; save(); } @@ -235,12 +302,13 @@ public static void setQuestionHint(String s) { public static boolean canFeedFriendToday(String id, int count) { Statistics stat = getStatistics(); int index = -1; - for(int i = 0; i < stat.feedFriendLogList.size(); i++) - if(stat.feedFriendLogList.get(i).userId.equals(id)) { + for (int i = 0; i < stat.feedFriendLogList.size(); i++) + if (stat.feedFriendLogList.get(i).userId.equals(id)) { index = i; break; } - if(index < 0) return true; + if (index < 0) + return true; FeedFriendLog ffl = stat.feedFriendLogList.get(index); return ffl.feedCount < count; } @@ -249,12 +317,12 @@ public static void feedFriendToday(String id) { Statistics stat = getStatistics(); FeedFriendLog ffl; int index = -1; - for(int i = 0; i < stat.feedFriendLogList.size(); i++) - if(stat.feedFriendLogList.get(i).userId.equals(id)) { + for (int i = 0; i < stat.feedFriendLogList.size(); i++) + if (stat.feedFriendLogList.get(i).userId.equals(id)) { index = i; break; } - if(index < 0) { + if (index < 0) { ffl = new FeedFriendLog(id); stat.feedFriendLogList.add(ffl); } else { @@ -271,7 +339,7 @@ public static boolean canMemberSignInToday() { public static void memberSignInToday() { Statistics stat = getStatistics(); - if(stat.memberSignIn != stat.day.time) { + if (stat.memberSignIn != stat.day.time) { stat.memberSignIn = stat.day.time; save(); } @@ -284,25 +352,50 @@ public static boolean canDonationEgg() { public static void donationEgg() { Statistics stat = getStatistics(); - if(stat.donationEgg != stat.day.time) { + if (stat.donationEgg != stat.day.time) { stat.donationEgg = stat.day.time; save(); } } - public static boolean canExchangeToday() { + public static boolean canExchangeToday(String uid) { Statistics stat = getStatistics(); - return stat.exchange < stat.day.time; + return !stat.exchangeList.contains(uid); } - public static void exchangeToday() { + public static void exchangeToday(String uid) { Statistics stat = getStatistics(); - if(stat.exchange != stat.day.time) { - stat.exchange = stat.day.time; + if (!stat.exchangeList.contains(uid)) { + stat.exchangeList.add(uid); save(); } } + public static boolean canExchangeDoubleCardToday() { + Statistics stat = getStatistics(); + if (stat.exchangeDoubleCard < stat.day.time) { + return true; + } else return stat.exchangeTimes < Config.getExchangeEnergyDoubleClickCount(); + } + + public static void exchangeDoubleCardToday(boolean iSsuccess) { + Statistics stat = getStatistics(); + if (stat.exchangeDoubleCard != stat.day.time) { + stat.exchangeDoubleCard = stat.day.time; + } + if (iSsuccess) { + stat.exchangeTimes += 1; + } else { + stat.exchangeTimes = Config.getExchangeEnergyDoubleClickCount(); + } + save(); + } + + public static int getExchangeTimes() { + Statistics stat = getStatistics(); + return stat.exchangeTimes; + } + public static boolean canKbSignInToday() { Statistics stat = getStatistics(); return stat.kbSignIn < stat.day.time; @@ -310,29 +403,29 @@ public static boolean canKbSignInToday() { public static void KbSignInToday() { Statistics stat = getStatistics(); - if(stat.kbSignIn != stat.day.time) { + if (stat.kbSignIn != stat.day.time) { stat.kbSignIn = stat.day.time; save(); } } - public static boolean canSyncStepToday() { + public static boolean canSyncStepToday(String uid) { Statistics stat = getStatistics(); - return stat.syncStep != stat.day.time; + return !stat.syncStepList.contains(uid); } - public static void SyncStepToday() { + public static void SyncStepToday(String uid) { Statistics stat = getStatistics(); - if(stat.syncStep != stat.day.time) { - stat.syncStep = stat.day.time; + if (!stat.syncStepList.contains(uid)) { + stat.syncStepList.add(uid); save(); } } private static Statistics getStatistics() { - if(statistics == null) { + if (statistics == null) { String statJson = null; - if(FileUtils.getStatisticsFile().exists()) + if (FileUtils.getStatisticsFile().exists()) statJson = FileUtils.readFromFile(FileUtils.getStatisticsFile()); statistics = json2Statistics(statJson); } @@ -346,55 +439,65 @@ public static void resetToday() { int mo = Integer.parseInt(dateStr[1]); int da = Integer.parseInt(dateStr[2]); - if(ye > stat.year.time) { + if (ye > stat.year.time) { stat.year.reset(ye); stat.month.reset(mo); stat.day.reset(da); dayClear(); - } else if(mo > stat.month.time) { + } else if (mo > stat.month.time) { stat.month.reset(mo); stat.day.reset(da); dayClear(); - } else if(da > stat.day.time) { + } else if (da > stat.day.time) { stat.day.reset(da); dayClear(); } } - private static void dayClear() - { + private static void dayClear() { Statistics stat = getStatistics(); stat.waterFriendLogList.clear(); stat.cooperateWaterList.clear(); + stat.syncStepList.clear(); + stat.exchangeList.clear(); + stat.reserveLogList.clear(); +// stat.ancientTreeCityCodeList.clear(); stat.answerQuestionList.clear(); stat.feedFriendLogList.clear(); stat.questionHint = null; stat.donationEgg = 0; stat.memberSignIn = 0; - stat.exchange = 0; stat.kbSignIn = 0; stat.syncStep = 0; + stat.exchangeDoubleCard = 0; + stat.exchangeTimes = 0; save(); FileUtils.getForestLogFile().delete(); FileUtils.getFarmLogFile().delete(); FileUtils.getOtherLogFile().delete(); } - private static Statistics defInit() { + private static Statistics defInit() { Statistics stat = new Statistics(); String[] date = Log.getFormatDate().split("-"); - if(stat.year == null) + if (stat.year == null) stat.year = new TimeStatistics(Integer.parseInt(date[0])); - if(stat.month == null) + if (stat.month == null) stat.month = new TimeStatistics(Integer.parseInt(date[1])); - if(stat.day == null) + if (stat.day == null) stat.day = new TimeStatistics(Integer.parseInt(date[2])); - if(stat.cooperateWaterList == null) + if (stat.cooperateWaterList == null) stat.cooperateWaterList = new ArrayList<>(); - if(stat.answerQuestionList == null) + if (stat.answerQuestionList == null) stat.answerQuestionList = new ArrayList<>(); - if(stat.feedFriendLogList == null) + if (stat.feedFriendLogList == null) stat.feedFriendLogList = new ArrayList<>(); +// if (stat.ancientTreeCityCodeList == null) +// stat.ancientTreeCityCodeList = new ArrayList<>(); + if (stat.syncStepList == null) + stat.syncStepList = new ArrayList<>(); + if (stat.exchangeList == null) + stat.exchangeList = new ArrayList<>(); return stat; } @@ -414,7 +517,6 @@ private static Statistics json2Statistics(String json) { stat.year.watered = joo.getInt(jn_watered); - joo = jo.getJSONObject(jn_month); stat.month = new TimeStatistics(joo.getInt(jn_month)); @@ -424,7 +526,6 @@ private static Statistics json2Statistics(String json) { stat.month.watered = joo.getInt(jn_watered); - joo = jo.getJSONObject(jn_day); stat.day = new TimeStatistics(joo.getInt(jn_day)); @@ -434,12 +535,11 @@ private static Statistics json2Statistics(String json) { stat.day.watered = joo.getInt(jn_watered); - stat.waterFriendLogList = new ArrayList<>(); - if(jo.has(Config.jn_waterFriendList)) { + if (jo.has(Config.jn_waterFriendList)) { JSONArray ja = jo.getJSONArray(Config.jn_waterFriendList); - for(int i = 0; i < ja.length(); i++) { + for (int i = 0; i < ja.length(); i++) { JSONArray jaa = ja.getJSONArray(i); WaterFriendLog wfl = new WaterFriendLog(jaa.getString(0)); wfl.waterCount = jaa.getInt(1); @@ -450,33 +550,64 @@ private static Statistics json2Statistics(String json) { stat.cooperateWaterList = new ArrayList<>(); - if(jo.has(Config.jn_cooperateWaterList)) { + if (jo.has(Config.jn_cooperateWaterList)) { JSONArray ja = jo.getJSONArray(Config.jn_cooperateWaterList); - for(int i = 0; i < ja.length(); i++) { + for (int i = 0; i < ja.length(); i++) { stat.cooperateWaterList.add(ja.getString(i)); } } + stat.syncStepList = new ArrayList<>(); + + if (jo.has(jn_syncStepList)) { + JSONArray ja = jo.getJSONArray(jn_syncStepList); + for (int i = 0; i < ja.length(); i++) { + stat.syncStepList.add(ja.getString(i)); + + } + } + + stat.exchangeList = new ArrayList<>(); + + if (jo.has(jn_exchangeList)) { + JSONArray ja = jo.getJSONArray(jn_exchangeList); + for (int i = 0; i < ja.length(); i++) { + stat.exchangeList.add(ja.getString(i)); + + } + } + + stat.reserveLogList = new ArrayList<>(); + + if (jo.has(Config.jn_reserveList)) { + JSONArray ja = jo.getJSONArray(Config.jn_reserveList); + for (int i = 0; i < ja.length(); i++) { + JSONArray jaa = ja.getJSONArray(i); + ReserveLog rl = new ReserveLog(jaa.getString(0)); + rl.applyCount = jaa.getInt(1); + stat.reserveLogList.add(rl); + } + } + stat.answerQuestionList = new ArrayList<>(); - if(jo.has(jn_answerQuestionList)) { + if (jo.has(jn_answerQuestionList)) { JSONArray ja = jo.getJSONArray(jn_answerQuestionList); - for(int i = 0; i < ja.length(); i++) { + for (int i = 0; i < ja.length(); i++) { stat.answerQuestionList.add(ja.getString(i)); } } - if(jo.has(jn_questionHint)) + if (jo.has(jn_questionHint)) stat.questionHint = jo.getString(jn_questionHint); - stat.feedFriendLogList = new ArrayList<>(); - if(jo.has(Config.jn_feedFriendAnimalList)) { + if (jo.has(Config.jn_feedFriendAnimalList)) { JSONArray ja = jo.getJSONArray(Config.jn_feedFriendAnimalList); - for(int i = 0; i < ja.length(); i++) { + for (int i = 0; i < ja.length(); i++) { JSONArray jaa = ja.getJSONArray(i); FeedFriendLog ffl = new FeedFriendLog(jaa.getString(0)); ffl.feedCount = jaa.getInt(1); @@ -485,49 +616,43 @@ private static Statistics json2Statistics(String json) { } } - if(jo.has(jn_donationEgg)) + if (jo.has(jn_donationEgg)) stat.donationEgg = jo.getInt(jn_donationEgg); - - if(jo.has(jn_memberSignIn)) + if (jo.has(jn_memberSignIn)) stat.memberSignIn = jo.getInt(jn_memberSignIn); - - if(jo.has(jn_exchange)) - stat.exchange = jo.getInt(jn_exchange); - - - if(jo.has(jn_kbSignIn)) + if (jo.has(jn_kbSignIn)) stat.kbSignIn = jo.getInt(jn_kbSignIn); + if (jo.has(jn_exchangeDoubleCard)) + stat.exchangeDoubleCard = jo.getInt(jn_exchangeDoubleCard); - if(jo.has(jn_syncStep)) - stat.syncStep = jo.getInt(jn_syncStep); - + if (jo.has(jn_exchangeTimes)) + stat.exchangeTimes = jo.getInt(jn_exchangeTimes); } catch (Throwable t) { Log.printStackTrace(TAG, t); - if(json != null) { + if (json != null) { Log.i(TAG, "统计文件格式有误,已重置统计文件并备份原文件"); FileUtils.write2File(json, FileUtils.getBackupFile(FileUtils.getStatisticsFile())); } stat = defInit(); } String formated = statistics2Json(stat); - if(!formated.equals(json)) { + if (!formated.equals(json)) { Log.i(TAG, "重新格式化 statistics.json"); FileUtils.write2File(formated, FileUtils.getStatisticsFile()); } return stat; } - private static String statistics2Json(Statistics stat) - { + private static String statistics2Json(Statistics stat) { JSONObject jo = new JSONObject(); JSONArray ja = null; - try - { - if(stat == null) stat = Statistics.defInit(); + try { + if (stat == null) + stat = Statistics.defInit(); JSONObject joo = new JSONObject(); joo.put(jn_year, stat.year.time); joo.put(jn_collected, stat.year.collected); @@ -550,8 +675,7 @@ private static String statistics2Json(Statistics stat) jo.put(jn_day, joo); ja = new JSONArray(); - for(int i = 0; i < stat.waterFriendLogList.size(); i++) - { + for (int i = 0; i < stat.waterFriendLogList.size(); i++) { WaterFriendLog wfl = stat.waterFriendLogList.get(i); JSONArray jaa = new JSONArray(); jaa.put(wfl.userId); @@ -561,25 +685,50 @@ private static String statistics2Json(Statistics stat) jo.put(Config.jn_waterFriendList, ja); ja = new JSONArray(); - for(int i = 0; i < stat.cooperateWaterList.size(); i++) - { + for (int i = 0; i < stat.cooperateWaterList.size(); i++) { ja.put(stat.cooperateWaterList.get(i)); } jo.put(Config.jn_cooperateWaterList, ja); ja = new JSONArray(); - for(int i = 0; i < stat.answerQuestionList.size(); i++) - { + for (int i = 0; i < stat.syncStepList.size(); i++) { + ja.put(stat.syncStepList.get(i)); + } + jo.put(jn_syncStepList, ja); + + ja = new JSONArray(); + for (int i = 0; i < stat.exchangeList.size(); i++) { + ja.put(stat.exchangeList.get(i)); + } + jo.put(jn_exchangeList, ja); + +// ja = new JSONArray(); +// for (int i = 0; i < stat.ancientTreeCityCodeList.size(); i++) { +// ja.put(stat.ancientTreeCityCodeList.get(i)); +// } +// jo.put(Config.jn_ancientTreeCityCodeList, ja); + + ja = new JSONArray(); + for (int i = 0; i < stat.reserveLogList.size(); i++) { + ReserveLog rl = stat.reserveLogList.get(i); + JSONArray jaa = new JSONArray(); + jaa.put(rl.projectId); + jaa.put(rl.applyCount); + ja.put(jaa); + } + jo.put(Config.jn_reserveList, ja); + + ja = new JSONArray(); + for (int i = 0; i < stat.answerQuestionList.size(); i++) { ja.put(stat.answerQuestionList.get(i)); } jo.put(jn_answerQuestionList, ja); - if(stat.questionHint != null) + if (stat.questionHint != null) jo.put(jn_questionHint, stat.questionHint); ja = new JSONArray(); - for(int i = 0; i < stat.feedFriendLogList.size(); i++) - { + for (int i = 0; i < stat.feedFriendLogList.size(); i++) { FeedFriendLog ffl = stat.feedFriendLogList.get(i); JSONArray jaa = new JSONArray(); jaa.put(ffl.userId); @@ -592,20 +741,19 @@ private static String statistics2Json(Statistics stat) jo.put(jn_memberSignIn, stat.memberSignIn); - jo.put(jn_exchange, stat.exchange); - jo.put(jn_kbSignIn, stat.kbSignIn); - jo.put(jn_syncStep, stat.syncStep); - }catch(Throwable t) - { + jo.put(jn_exchangeDoubleCard, stat.exchangeDoubleCard); + + jo.put(jn_exchangeTimes, stat.exchangeTimes); + + } catch (Throwable t) { Log.printStackTrace(TAG, t); } return Config.formatJson(jo, false); } - private static void save() - { + private static void save() { FileUtils.write2File(statistics2Json(getStatistics()), FileUtils.getStatisticsFile()); } diff --git a/app/src/main/res/layout/include_settings.xml b/app/src/main/res/layout/include_settings.xml index a54fb2104..63657025b 100644 --- a/app/src/main/res/layout/include_settings.xml +++ b/app/src/main/res/layout/include_settings.xml @@ -357,6 +357,56 @@ android:id="@+id/btn_giveEnergyRainList" android:paddingStart="8dp"/> + + +