|
|
@@ -13,11 +13,15 @@ import android.view.accessibility.AccessibilityEvent;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
|
|
|
import com.wiipu.marketingrobot.AutoReplyService;
|
|
|
-import com.wiipu.marketingrobot.contract.enableAddFriendContract;
|
|
|
+import com.wiipu.marketingrobot.Constants;
|
|
|
+import com.wiipu.marketingrobot.contract.LoginContract;
|
|
|
+import com.wiipu.marketingrobot.contract.getCommonValueContract;
|
|
|
import com.wiipu.marketingrobot.contract.replyContract;
|
|
|
-import com.wiipu.marketingrobot.presenter.enableAddFriendPresenter;
|
|
|
+import com.wiipu.marketingrobot.presenter.LoginPresenter;
|
|
|
+import com.wiipu.marketingrobot.presenter.getCommonValuePresenter;
|
|
|
import com.wiipu.marketingrobot.presenter.replyPresenter;
|
|
|
-import com.wiipu.marketingrobot.response.enableAddFriendResponse;
|
|
|
+import com.wiipu.marketingrobot.response.CommonValueResponse;
|
|
|
+import com.wiipu.marketingrobot.response.LoginResponse;
|
|
|
import com.wiipu.marketingrobot.response.replyResponse;
|
|
|
import com.wiipu.marketingrobot.response.uploadFriendResponse;
|
|
|
import com.wiipu.marketingrobot.widget.AccessibilityHelper;
|
|
|
@@ -32,14 +36,15 @@ import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_BA
|
|
|
* Description:被动加好友
|
|
|
* Code: Axion
|
|
|
*/
|
|
|
-public class addFriendFunction implements replyContract.View , enableAddFriendContract.View{
|
|
|
+public class addFriendFunction implements replyContract.View , getCommonValueContract.View , LoginContract.View{
|
|
|
AccessibilityService mService;
|
|
|
private boolean hasGetmmId = false;
|
|
|
private static final String TAG = addFriendFunction.class.getSimpleName();
|
|
|
private String mmNum = null;
|
|
|
private String mmName = null;
|
|
|
private replyPresenter mReplyPresenter;
|
|
|
- private enableAddFriendPresenter mEnableAddFriendPresenter;
|
|
|
+ private getCommonValuePresenter mGetCommonValuePresenter;
|
|
|
+ private LoginPresenter mLoginPresenter;
|
|
|
private String reply;
|
|
|
private boolean needGetSelfInfo;
|
|
|
private static final String threePointInLanucher="com.tencent.mm:id/jr";//聊天界面右上角三个点
|
|
|
@@ -49,11 +54,13 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
private static final String chatListMem="com.tencent.mm:id/nj";//聊天列表头像的id
|
|
|
private static final String savedRobotName="robotName";
|
|
|
private static final String savedRobotNum="robotNum";
|
|
|
+ private static final String savedRobotId="robotId";
|
|
|
private SharedPreferences pref;
|
|
|
public addFriendFunction(AccessibilityService service) {
|
|
|
mService = service;
|
|
|
mReplyPresenter = new replyPresenter(this);
|
|
|
- mEnableAddFriendPresenter = new enableAddFriendPresenter(this);
|
|
|
+ mGetCommonValuePresenter = new getCommonValuePresenter(this);
|
|
|
+ mLoginPresenter = new LoginPresenter(this);
|
|
|
pref= mService.getSharedPreferences("robotData", Context.MODE_PRIVATE);
|
|
|
}
|
|
|
|
|
|
@@ -80,17 +87,6 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
- public void showEnableAddFriendReply(enableAddFriendResponse enableAddFriendResponse) {
|
|
|
- AutoReplyService.enableFriendsCounts = enableAddFriendResponse.getMsg();
|
|
|
- LogUtils.d(TAG + " showEnableAddFriendReply,now the enableFriendCounts is :"+AutoReplyService.enableFriendsCounts);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void showEnableError(String msg) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 最终操作
|
|
|
*/
|
|
|
@@ -103,7 +99,7 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
mmNum = null;
|
|
|
mmName = null;
|
|
|
AutoReplyService.isInAction = false;
|
|
|
- mEnableAddFriendPresenter.clearSub();
|
|
|
+ mGetCommonValuePresenter.clearSub();
|
|
|
mService.performGlobalAction(GLOBAL_ACTION_BACK);
|
|
|
RxBus.post(new eventClassFunction(true));
|
|
|
/*
|
|
|
@@ -163,11 +159,17 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
if(needGetSelfInfo){
|
|
|
AccessibilityNodeInfo addTocContract = AccessibilityHelper.findNodeInfosByText(root, "添加到通讯录");//有时候会出现这个界面,很奇特
|
|
|
if (mmId != null) {
|
|
|
- String id = mmId.getText().toString();
|
|
|
- id = id.substring(id.indexOf(":") + 2, id.length()).trim();
|
|
|
- SharedPreferences.Editor editor=pref.edit();
|
|
|
- editor.putString(savedRobotNum, id);
|
|
|
+ // 获取机器人微信号
|
|
|
+ // 保存到SharedPreferences文件中
|
|
|
+ String robotWechatNum = mmId.getText().toString();
|
|
|
+ robotWechatNum = robotWechatNum.substring(robotWechatNum.indexOf(":") + 2, robotWechatNum.length()).trim();
|
|
|
+ SharedPreferences.Editor editor = pref.edit();
|
|
|
+ editor.putString(savedRobotNum, robotWechatNum);
|
|
|
editor.apply();
|
|
|
+
|
|
|
+ // 登陆当前机器人,获取机器人id
|
|
|
+ mLoginPresenter.login(robotWechatNum);
|
|
|
+
|
|
|
} else if (addTocContract != null) {
|
|
|
AccessibilityHelper.performClick(addTocContract);
|
|
|
return;
|
|
|
@@ -219,8 +221,8 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
return;
|
|
|
}
|
|
|
LogUtils.e(TAG + " addFriend: 3");
|
|
|
- mReplyPresenter.upLoadFriends(mmName, mmNum, pref.getString(savedRobotName, null), pref.getString(savedRobotNum, null));
|
|
|
- mEnableAddFriendPresenter.getEnableAddFriend(pref.getString(savedRobotNum, null));
|
|
|
+ mReplyPresenter.upLoadFriends(mmName, mmNum, pref.getString(savedRobotName, null), pref.getString(savedRobotId, null));
|
|
|
+ mGetCommonValuePresenter.getValueByKey(pref.getString(savedRobotId, null),Constants.KEY_MAX_FRIEND_NUM);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -246,14 +248,31 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 登陆反馈
|
|
|
+ * @param loginResponse
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void showResult(LoginResponse loginResponse) {
|
|
|
+ // 保存机器人id到本地
|
|
|
+ if (loginResponse.getCode() == 1){
|
|
|
+ if (loginResponse.getMsg() != null){
|
|
|
+ SharedPreferences.Editor editor = pref.edit();
|
|
|
+ editor.putString(savedRobotId, loginResponse.getMsg().getId());
|
|
|
+ editor.apply();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获得机器人信息
|
|
|
*/
|
|
|
|
|
|
private void getTheRobotInfo(AccessibilityEvent event) {
|
|
|
- LogUtils.d(TAG + " getTheRobotInfo: ");
|
|
|
+ LogUtils.d(TAG + " 获取机器人信息: ");
|
|
|
String senderName = AutoReplyService.msgSenderName;
|
|
|
if (senderName == null) {
|
|
|
- LogUtils.e(TAG + " getTheRobotInfo: wtf!!!!");
|
|
|
+ LogUtils.e(TAG + "发消息人昵称为null");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -375,5 +394,10 @@ public class addFriendFunction implements replyContract.View , enableAddFriendCo
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public void showCommonValue(CommonValueResponse commonValueResponse, String key) {
|
|
|
+ if (key.equals(Constants.KEY_MAX_FRIEND_NUM))
|
|
|
+ AutoReplyService.enableFriendsCounts = Integer.parseInt(commonValueResponse.getMsg());
|
|
|
+ LogUtils.d(TAG + " 当前剩余可添加好友数 : "+ AutoReplyService.enableFriendsCounts);
|
|
|
+ }
|
|
|
}
|