Commit 3670128a01c02dd498c67561549e5dac2c20077d
1 parent
1fbabddd
1 新增上传JSON数据接口
Showing
12 changed files
with
489 additions
and
109 deletions
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/presenter/SetFriendsRolePresenter.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.frame.presenter; |
| 2 | 2 | |
| 3 | +import android.app.Activity; | |
| 3 | 4 | import android.content.Context; |
| 4 | 5 | import android.util.Log; |
| 5 | 6 | import android.view.View; |
| ... | ... | @@ -9,36 +10,88 @@ import com.cnlive.libs.base.logic.callback.DataCallback; |
| 9 | 10 | import com.cnlive.libs.base.logic.callback.FailureCallback; |
| 10 | 11 | import com.cnlive.libs.base.logic.callback.SuccessCallback; |
| 11 | 12 | import com.cnlive.strike.xiaojiaspeaker.frame.view.SetFriendsRoleView; |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.netWork.ApiServiceCMCC; | |
| 12 | 14 | import com.cnlive.strike.xiaojiaspeaker.netWork.ApiServiceXiaoJia; |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.netWork.CmccRequest; | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.InvitFamilyBean1; | |
| 13 | 17 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.RoleNetBean; |
| 14 | 18 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.APIBaseInfo; |
| 15 | 19 | import com.cnlive.strike.xiaojiaspeaker.netWork.result.SubscriptionRequest; |
| 20 | +import com.cnlive.strike.xiaojiaspeaker.util.GsonUtil; | |
| 16 | 21 | import com.cnlive.strike.xiaojiaspeaker.util.QMUITipDialogUtil; |
| 22 | +import com.cnlive.strike.xiaojiaspeaker.util.subutil.util.http.Request; | |
| 17 | 23 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 18 | 24 | |
| 19 | 25 | import java.util.HashMap; |
| 20 | 26 | import java.util.Map; |
| 21 | 27 | |
| 22 | 28 | import io.reactivex.disposables.Disposable; |
| 29 | +import okhttp3.MediaType; | |
| 30 | +import okhttp3.RequestBody; | |
| 31 | +import retrofit2.Call; | |
| 32 | +import retrofit2.Callback; | |
| 33 | +import retrofit2.Response; | |
| 23 | 34 | |
| 24 | 35 | public class SetFriendsRolePresenter extends MvpBasePresenter<SetFriendsRoleView> { |
| 25 | 36 | |
| 26 | 37 | private String TAG = "SetFriendsRolePresenter"; |
| 27 | 38 | |
| 28 | - public void invitFamilyMember(Context context, String contactsInvite) { | |
| 39 | + | |
| 40 | + public void queryConfigDeviceNetResult(Activity context, String contactsInvite) { | |
| 41 | + InvitFamilyBean1 bean1=new InvitFamilyBean1(); | |
| 42 | + bean1.setType("2"); | |
| 43 | + bean1.setContactsInvite(GsonUtil.jsonToList(contactsInvite, InvitFamilyBean1.ContactsInviteBean.class)); | |
| 44 | + | |
| 45 | + CmccRequest.getInstance(ApiServiceCMCC.class) | |
| 46 | + .invitFamilyMember(bean1) | |
| 47 | + .enqueue(new Callback<APIBaseInfo>() { | |
| 48 | + @Override | |
| 49 | + public void onResponse(Call<APIBaseInfo> call, Response<APIBaseInfo> response) { | |
| 50 | + if (null == getView()) { | |
| 51 | + return; | |
| 52 | + } | |
| 53 | + QMUITipDialogUtil.dismessDialog(); | |
| 54 | +// ConfigDeviceNetResult result = response.body(); | |
| 55 | +// //响应成功 | |
| 56 | +// if (CmccRequest.SUCCRSS == result.getResult()) { | |
| 57 | +// Log.e(TAG, "onResponse: "); | |
| 58 | +// if ("success".equals(result.getData().getResult())) { | |
| 59 | +// context.finish(); | |
| 60 | +// ConnBluetoothSuccessActivity.startActivity(context); | |
| 61 | +// } else { | |
| 62 | +// AlertUtil.showDeftToast(context, "配网失败,请稍后重试"); | |
| 63 | +// } | |
| 64 | +// } else { | |
| 65 | +// //响应失败 | |
| 66 | +// AlertUtil.showDeftToast(context, "配网失败,请稍后重试"); | |
| 67 | +// } | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public void onFailure(Call<APIBaseInfo> call, Throwable t) { | |
| 72 | + QMUITipDialogUtil.dismessDialog(); | |
| 73 | + } | |
| 74 | + }); | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void invitFamilyMember(Context context, String contactsInvite) { | |
| 29 | 78 | if (null == getView()) { |
| 30 | 79 | return; |
| 31 | 80 | } |
| 32 | 81 | QMUITipDialogUtil.loadingDialog(context, "请稍后", true); |
| 33 | - getView().showLoadingView(); | |
| 34 | - Map<String, String> map = new HashMap<>(); | |
| 35 | - map.put("type", "2");//联系人邀请 | |
| 36 | - map.put("contactsInvite", contactsInvite); | |
| 37 | - Logic.create(map) | |
| 38 | - .action(new Logic.Action<Map<String, String>, APIBaseInfo>() { | |
| 82 | +// Map<String, RequestBody> map = new HashMap<>(); | |
| 83 | +// map.put("type", getRequestString("2"));//联系人邀请 | |
| 84 | +// map.put("contactsInvite", getRequestString(contactsInvite)); | |
| 85 | + InvitFamilyBean1 bean1=new InvitFamilyBean1(); | |
| 86 | + bean1.setType("2"); | |
| 87 | + bean1.setContactsInvite(GsonUtil.jsonToList(contactsInvite, InvitFamilyBean1.ContactsInviteBean.class)); | |
| 88 | + String test=GsonUtil.GsonString(bean1); | |
| 89 | + RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),test); | |
| 90 | + Logic.create(bean1) | |
| 91 | + .action(new Logic.Action<RequestBody , APIBaseInfo>() { | |
| 39 | 92 | @Override |
| 40 | - public Disposable action(Map<String, String> paramsMap, DataCallback<APIBaseInfo> dataCallback) { | |
| 41 | - return SubscriptionRequest.service(ApiServiceXiaoJia.class, api -> api.invitFamilyMember(paramsMap)).subscribe(context, dataCallback); | |
| 93 | + public Disposable action(RequestBody invitFamilyBean1, DataCallback<APIBaseInfo> dataCallback) { | |
| 94 | + return SubscriptionRequest.service(ApiServiceXiaoJia.class, api -> api.invitFamilyMember(invitFamilyBean1)).subscribe(context, dataCallback); | |
| 42 | 95 | } |
| 43 | 96 | }).<APIBaseInfo>event() |
| 44 | 97 | .setSuccessCallback(new SuccessCallback<APIBaseInfo>() { |
| ... | ... | @@ -50,6 +103,7 @@ public class SetFriendsRolePresenter extends MvpBasePresenter<SetFriendsRoleView |
| 50 | 103 | return; |
| 51 | 104 | } |
| 52 | 105 | QMUITipDialogUtil.dismessDialog(); |
| 106 | + QMUITipDialogUtil.successDialog(context, "邀请成功", 1); | |
| 53 | 107 | } |
| 54 | 108 | }) |
| 55 | 109 | .setFailureCallback(new FailureCallback() { |
| ... | ... | @@ -68,6 +122,11 @@ public class SetFriendsRolePresenter extends MvpBasePresenter<SetFriendsRoleView |
| 68 | 122 | .start(); |
| 69 | 123 | } |
| 70 | 124 | |
| 125 | + private static RequestBody getRequestString(String value) { | |
| 126 | + RequestBody requestString = RequestBody.create(MediaType.parse("text/plain"), value); | |
| 127 | + return requestString; | |
| 128 | + } | |
| 129 | + | |
| 71 | 130 | /** |
| 72 | 131 | * 获取用户角色 |
| 73 | 132 | * | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SelectIMFriendView.java
| ... | ... | @@ -40,6 +40,10 @@ public class SelectIMFriendView implements MvpView, LetterBarView.OnLetterSelect |
| 40 | 40 | private String TAG = "SelectIMFriendView"; |
| 41 | 41 | private boolean isFirst = true; |
| 42 | 42 | |
| 43 | + public void setCurrentSelectFamilyId(String currentSelectFamilyId) { | |
| 44 | + this.currentSelectFamilyId = currentSelectFamilyId; | |
| 45 | + } | |
| 46 | + | |
| 43 | 47 | public SelectIMFriendView(SelectIMFriendFragment fragment) { |
| 44 | 48 | this.fragment = fragment; |
| 45 | 49 | } |
| ... | ... | @@ -96,82 +100,86 @@ public class SelectIMFriendView implements MvpView, LetterBarView.OnLetterSelect |
| 96 | 100 | }); |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | - public void initView(List<IMFriendNoLetterInfo> noLetterInfoList) { | |
| 103 | + public void initView(List<IMFriendNoLetterInfo> list) { | |
| 100 | 104 | //设置按钮不可点击 |
| 101 | 105 | nextBtnCanNotClick(); |
| 102 | 106 | //假设这个是原有数据 |
| 103 | - this.noLetterInfoList = noLetterInfoList; | |
| 104 | -// IMFriendNoLetterInfo noLetterInfo = new IMFriendNoLetterInfo(); | |
| 105 | -// noLetterInfo.setUserName("韩亚云"); | |
| 106 | -// noLetterInfo.setCantSelect(true); | |
| 107 | -// noLetterInfo.setId("352660"); | |
| 108 | -// noLetterInfoList.add(noLetterInfo); | |
| 109 | -// | |
| 110 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 111 | -// noLetterInfo.setUserName("杨帅"); | |
| 112 | -// noLetterInfo.setId("352668"); | |
| 113 | -// noLetterInfoList.add(noLetterInfo); | |
| 114 | -// | |
| 115 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 116 | -// noLetterInfo.setUserName("杨杨"); | |
| 117 | -// noLetterInfo.setId("352700"); | |
| 118 | -// noLetterInfoList.add(noLetterInfo); | |
| 119 | -// | |
| 120 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 121 | -// noLetterInfo.setUserName("杨天"); | |
| 122 | -// noLetterInfo.setId("352782"); | |
| 123 | -// noLetterInfoList.add(noLetterInfo); | |
| 124 | -// | |
| 125 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 126 | -// noLetterInfo.setUserName("郭瑞鹏"); | |
| 127 | -// noLetterInfo.setId("352898"); | |
| 128 | -// noLetterInfoList.add(noLetterInfo); | |
| 129 | -// | |
| 130 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 131 | -// noLetterInfo.setUserName("殷巧娟"); | |
| 132 | -// noLetterInfo.setId("353001"); | |
| 133 | -// noLetterInfoList.add(noLetterInfo); | |
| 134 | -// | |
| 135 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 136 | -// noLetterInfo.setUserName("张晓文"); | |
| 137 | -// noLetterInfo.setId("353036"); | |
| 138 | -// noLetterInfoList.add(noLetterInfo); | |
| 139 | -// | |
| 140 | -// | |
| 141 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 142 | -// noLetterInfo.setUserName("小明"); | |
| 143 | -// noLetterInfo.setId("353360"); | |
| 144 | -// noLetterInfoList.add(noLetterInfo); | |
| 145 | -// | |
| 146 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 147 | -// noLetterInfo.setUserName("小红"); | |
| 148 | -// noLetterInfo.setId("353417"); | |
| 149 | -// noLetterInfoList.add(noLetterInfo); | |
| 150 | -// | |
| 151 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 152 | -// noLetterInfo.setUserName("小绿"); | |
| 153 | -// noLetterInfo.setId("353557"); | |
| 154 | -// noLetterInfoList.add(noLetterInfo); | |
| 155 | -// | |
| 156 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 157 | -// noLetterInfo.setUserName("小黄"); | |
| 158 | -// noLetterInfo.setId("353651"); | |
| 159 | -// noLetterInfoList.add(noLetterInfo); | |
| 160 | -// | |
| 161 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 162 | -// noLetterInfo.setUserName("张三"); | |
| 163 | -// noLetterInfo.setId("353728"); | |
| 164 | -// noLetterInfoList.add(noLetterInfo); | |
| 165 | -// | |
| 166 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 167 | -// noLetterInfo.setUserName("李四"); | |
| 168 | -// noLetterInfo.setId("353777"); | |
| 169 | -// noLetterInfoList.add(noLetterInfo); | |
| 170 | -// | |
| 171 | -// noLetterInfo = new IMFriendNoLetterInfo(); | |
| 172 | -// noLetterInfo.setUserName("王五"); | |
| 173 | -// noLetterInfo.setId("353789"); | |
| 174 | -// noLetterInfoList.add(noLetterInfo); | |
| 107 | +// this.noLetterInfoList = noLetterInfoList; | |
| 108 | + | |
| 109 | + this.noLetterInfoList=new ArrayList<>(); | |
| 110 | + IMFriendNoLetterInfo noLetterInfo = new IMFriendNoLetterInfo(); | |
| 111 | + noLetterInfo.setUserName("韩亚云"); | |
| 112 | + noLetterInfo.setCantSelect(true); | |
| 113 | + noLetterInfo.setId("352660"); | |
| 114 | + noLetterInfoList.add(noLetterInfo); | |
| 115 | + | |
| 116 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 117 | + noLetterInfo.setUserName("杨帅"); | |
| 118 | + noLetterInfo.setId("352668"); | |
| 119 | + noLetterInfoList.add(noLetterInfo); | |
| 120 | + | |
| 121 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 122 | + noLetterInfo.setUserName("杨杨"); | |
| 123 | + noLetterInfo.setId("352700"); | |
| 124 | + noLetterInfoList.add(noLetterInfo); | |
| 125 | + | |
| 126 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 127 | + noLetterInfo.setUserName("杨天"); | |
| 128 | + noLetterInfo.setId("352782"); | |
| 129 | + noLetterInfoList.add(noLetterInfo); | |
| 130 | + | |
| 131 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 132 | + noLetterInfo.setUserName("郭瑞鹏"); | |
| 133 | + noLetterInfo.setId("352898"); | |
| 134 | + noLetterInfoList.add(noLetterInfo); | |
| 135 | + | |
| 136 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 137 | + noLetterInfo.setUserName("殷巧娟"); | |
| 138 | + noLetterInfo.setId("353001"); | |
| 139 | + noLetterInfoList.add(noLetterInfo); | |
| 140 | + | |
| 141 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 142 | + noLetterInfo.setUserName("张晓文"); | |
| 143 | + noLetterInfo.setId("353036"); | |
| 144 | + noLetterInfoList.add(noLetterInfo); | |
| 145 | + | |
| 146 | + | |
| 147 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 148 | + noLetterInfo.setUserName("小明"); | |
| 149 | + noLetterInfo.setId("353360"); | |
| 150 | + noLetterInfoList.add(noLetterInfo); | |
| 151 | + | |
| 152 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 153 | + noLetterInfo.setUserName("小红"); | |
| 154 | + noLetterInfo.setId("353417"); | |
| 155 | + noLetterInfoList.add(noLetterInfo); | |
| 156 | + | |
| 157 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 158 | + noLetterInfo.setUserName("小绿"); | |
| 159 | + noLetterInfo.setId("353557"); | |
| 160 | + noLetterInfoList.add(noLetterInfo); | |
| 161 | + | |
| 162 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 163 | + noLetterInfo.setUserName("小黄"); | |
| 164 | + noLetterInfo.setId("353651"); | |
| 165 | + noLetterInfoList.add(noLetterInfo); | |
| 166 | + | |
| 167 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 168 | + noLetterInfo.setUserName("张三"); | |
| 169 | + noLetterInfo.setId("353728"); | |
| 170 | + noLetterInfoList.add(noLetterInfo); | |
| 171 | + | |
| 172 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 173 | + noLetterInfo.setUserName("李四"); | |
| 174 | + noLetterInfo.setId("353777"); | |
| 175 | + noLetterInfoList.add(noLetterInfo); | |
| 176 | + | |
| 177 | + noLetterInfo = new IMFriendNoLetterInfo(); | |
| 178 | + noLetterInfo.setUserName("王五"); | |
| 179 | + noLetterInfo.setId("353789"); | |
| 180 | + noLetterInfoList.add(noLetterInfo); | |
| 181 | + | |
| 182 | + | |
| 175 | 183 | //对数据进行排序 |
| 176 | 184 | Collections.sort(noLetterInfoList, new LetterComparator()); |
| 177 | 185 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SetFriendsRoleView.java
| ... | ... | @@ -101,7 +101,7 @@ public class SetFriendsRoleView implements MvpView { |
| 101 | 101 | if (null != adapter) { |
| 102 | 102 | String result = adapter.getRoleSetResult(); |
| 103 | 103 | if (!TextUtils.isEmpty(result)) { |
| 104 | - fragment.getPresenter().invitFamilyMember(getContext(), result); | |
| 104 | + fragment.getPresenter().queryConfigDeviceNetResult(getContext(), result); | |
| 105 | 105 | } else { |
| 106 | 106 | AlertUtil.showDeftToast(getContext(), "发送参数异常"); |
| 107 | 107 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/ApiServiceCMCC.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.netWork; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.APIBaseInfo; | |
| 4 | 5 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.ConfigDeviceNetParam; |
| 6 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.InvitFamilyBean1; | |
| 5 | 7 | import com.cnlive.strike.xiaojiaspeaker.netWork.result.ConfigDeviceNetResult; |
| 6 | 8 | |
| 9 | +import io.reactivex.Observable; | |
| 10 | +import okhttp3.RequestBody; | |
| 7 | 11 | import retrofit2.Call; |
| 12 | +import retrofit2.adapter.rxjava2.Result; | |
| 8 | 13 | import retrofit2.http.Body; |
| 14 | +import retrofit2.http.Headers; | |
| 9 | 15 | import retrofit2.http.POST; |
| 10 | 16 | |
| 11 | 17 | /** |
| ... | ... | @@ -20,4 +26,8 @@ public interface ApiServiceCMCC { |
| 20 | 26 | */ |
| 21 | 27 | @POST("users/custom") |
| 22 | 28 | Call<ConfigDeviceNetResult> queryDeviceConfigNet(@Body ConfigDeviceNetParam param); |
| 29 | + | |
| 30 | + | |
| 31 | + @POST("Daren/sound/familyGroupInviteYD.action") | |
| 32 | + Call<APIBaseInfo> invitFamilyMember(@Body InvitFamilyBean1 body); | |
| 23 | 33 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/ApiServiceXiaoJia.java
| ... | ... | @@ -4,6 +4,7 @@ package com.cnlive.strike.xiaojiaspeaker.netWork; |
| 4 | 4 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.DeviceDetail; |
| 5 | 5 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.FamilyListBean; |
| 6 | 6 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.FamilyRoleBean; |
| 7 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.InvitFamilyBean1; | |
| 7 | 8 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.NetworkResultBean; |
| 8 | 9 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.RoleNetBean; |
| 9 | 10 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.APIBaseInfo; |
| ... | ... | @@ -12,9 +13,14 @@ import com.cnlive.strike.xiaojiaspeaker.netWork.bean.XiaoJiaContactInfo; |
| 12 | 13 | import java.util.Map; |
| 13 | 14 | |
| 14 | 15 | import io.reactivex.Observable; |
| 16 | +import okhttp3.RequestBody; | |
| 15 | 17 | import retrofit2.adapter.rxjava2.Result; |
| 18 | +import retrofit2.http.Body; | |
| 16 | 19 | import retrofit2.http.GET; |
| 20 | +import retrofit2.http.Headers; | |
| 21 | +import retrofit2.http.Multipart; | |
| 17 | 22 | import retrofit2.http.POST; |
| 23 | +import retrofit2.http.PartMap; | |
| 18 | 24 | import retrofit2.http.QueryMap; |
| 19 | 25 | |
| 20 | 26 | /** |
| ... | ... | @@ -140,10 +146,11 @@ public interface ApiServiceXiaoJia { |
| 140 | 146 | * } |
| 141 | 147 | * ] |
| 142 | 148 | * |
| 143 | - * @param maps | |
| 144 | 149 | * @return |
| 145 | 150 | */ |
| 146 | 151 | @POST("/Daren/sound/familyGroupInviteYD.action") |
| 147 | - Observable<Result<APIBaseInfo>> invitFamilyMember(@QueryMap() Map<String, String> maps); | |
| 152 | + @Headers({"Content-Type: application/json","Accept: application/json"})//需要添加头 | |
| 153 | +// @Multipart | |
| 154 | + Observable<Result<APIBaseInfo>> invitFamilyMember( @Body RequestBody body); | |
| 148 | 155 | } |
| 149 | 156 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/BasicParamsInterceptor.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | +import android.text.TextUtils; | |
| 4 | + | |
| 5 | +import java.io.IOException; | |
| 6 | +import java.util.ArrayList; | |
| 7 | +import java.util.HashMap; | |
| 8 | +import java.util.Iterator; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Map; | |
| 11 | + | |
| 12 | +import okhttp3.FormBody; | |
| 13 | +import okhttp3.Headers; | |
| 14 | +import okhttp3.HttpUrl; | |
| 15 | +import okhttp3.Interceptor; | |
| 16 | +import okhttp3.MediaType; | |
| 17 | +import okhttp3.Request; | |
| 18 | +import okhttp3.RequestBody; | |
| 19 | +import okhttp3.Response; | |
| 20 | +import okio.Buffer; | |
| 21 | + | |
| 22 | +public class BasicParamsInterceptor implements Interceptor { | |
| 23 | + Map<String, String> queryParamsMap = new HashMap<>(); // 添加到 URL 末尾,Get Post 方法都使用 | |
| 24 | + Map<String, String> paramsMap = new HashMap<>(); // 添加到公共参数到消息体,适用 Post 请求 | |
| 25 | + Map<String, String> headerParamsMap = new HashMap<>(); // 公共 Headers 添加 | |
| 26 | + List<String> headerLinesList = new ArrayList<>(); // 消息头 集合形式,一次添加一行 | |
| 27 | + | |
| 28 | + // 私有构造器 | |
| 29 | + private BasicParamsInterceptor() { | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Response intercept(Chain chain) throws IOException { | |
| 34 | + | |
| 35 | + Request request = chain.request(); | |
| 36 | + Request.Builder requestBuilder = request.newBuilder(); | |
| 37 | + | |
| 38 | + // process header params inject | |
| 39 | + Headers.Builder headerBuilder = request.headers().newBuilder(); | |
| 40 | + // 以 Entry 添加消息头 | |
| 41 | + if (headerParamsMap.size() > 0) { | |
| 42 | + Iterator iterator = headerParamsMap.entrySet().iterator(); | |
| 43 | + while (iterator.hasNext()) { | |
| 44 | + Map.Entry entry = (Map.Entry) iterator.next(); | |
| 45 | + headerBuilder.add((String) entry.getKey(), (String) entry.getValue()); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + // 以 String 形式添加消息头 | |
| 49 | + if (headerLinesList.size() > 0) { | |
| 50 | + for (String line : headerLinesList) { | |
| 51 | + headerBuilder.add(line); | |
| 52 | + } | |
| 53 | + requestBuilder.headers(headerBuilder.build()); | |
| 54 | + } | |
| 55 | + // process header params end | |
| 56 | + | |
| 57 | + | |
| 58 | + // process queryParams inject whatever it's GET or POST | |
| 59 | + if (queryParamsMap.size() > 0) { | |
| 60 | + request = injectParamsIntoUrl(request.url().newBuilder(), requestBuilder, queryParamsMap); | |
| 61 | + } | |
| 62 | + | |
| 63 | + // process post body inject | |
| 64 | + if (paramsMap.size() > 0) { | |
| 65 | + if (canInjectIntoBody(request)) { | |
| 66 | + FormBody.Builder formBodyBuilder = new FormBody.Builder(); | |
| 67 | + for (Map.Entry<String, String> entry : paramsMap.entrySet()) { | |
| 68 | + formBodyBuilder.add((String) entry.getKey(), (String) entry.getValue()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + RequestBody formBody = formBodyBuilder.build(); | |
| 72 | + String postBodyString = bodyToString(request.body()); | |
| 73 | + postBodyString += ((postBodyString.length() > 0) ? "&" : "") + bodyToString(formBody); | |
| 74 | + requestBuilder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded;charset=UTF-8"), postBodyString)); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + request = requestBuilder.build(); | |
| 78 | + return chain.proceed(request); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * 确认是否是 post 请求 | |
| 83 | + * | |
| 84 | + * @param request 发出的请求 | |
| 85 | + * @return true 需要注入公共参数 | |
| 86 | + */ | |
| 87 | + private boolean canInjectIntoBody(Request request) { | |
| 88 | + if (request == null) { | |
| 89 | + return false; | |
| 90 | + } | |
| 91 | + if (!TextUtils.equals(request.method(), "POST")) { | |
| 92 | + return false; | |
| 93 | + } | |
| 94 | + RequestBody body = request.body(); | |
| 95 | + if (body == null) { | |
| 96 | + return false; | |
| 97 | + } | |
| 98 | + MediaType mediaType = body.contentType(); | |
| 99 | + if (mediaType == null) { | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | + if (!TextUtils.equals(mediaType.subtype(), "x-www-form-urlencoded")) { | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + return true; | |
| 106 | + } | |
| 107 | + | |
| 108 | + // func to inject params into url | |
| 109 | + private Request injectParamsIntoUrl(HttpUrl.Builder httpUrlBuilder, Request.Builder requestBuilder, Map<String, String> paramsMap) { | |
| 110 | + if (paramsMap.size() > 0) { | |
| 111 | + Iterator iterator = paramsMap.entrySet().iterator(); | |
| 112 | + while (iterator.hasNext()) { | |
| 113 | + Map.Entry entry = (Map.Entry) iterator.next(); | |
| 114 | + httpUrlBuilder.addQueryParameter((String) entry.getKey(), (String) entry.getValue()); | |
| 115 | + } | |
| 116 | + requestBuilder.url(httpUrlBuilder.build()); | |
| 117 | + return requestBuilder.build(); | |
| 118 | + } | |
| 119 | + return null; | |
| 120 | + } | |
| 121 | + | |
| 122 | + private static String bodyToString(final RequestBody request) { | |
| 123 | + try { | |
| 124 | + final RequestBody copy = request; | |
| 125 | + final Buffer buffer = new Buffer(); | |
| 126 | + if (copy != null) | |
| 127 | + copy.writeTo(buffer); | |
| 128 | + else | |
| 129 | + return ""; | |
| 130 | + return buffer.readUtf8(); | |
| 131 | + } catch (final IOException e) { | |
| 132 | + return "did not work"; | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + public static class Builder { | |
| 137 | + | |
| 138 | + BasicParamsInterceptor interceptor; | |
| 139 | + | |
| 140 | + public Builder() { | |
| 141 | + interceptor = new BasicParamsInterceptor(); | |
| 142 | + } | |
| 143 | + | |
| 144 | + // 添加公共参数到 post 消息体 | |
| 145 | + public Builder addParam(String key, String value) { | |
| 146 | + interceptor.paramsMap.put(key, value); | |
| 147 | + return this; | |
| 148 | + } | |
| 149 | + | |
| 150 | + // 添加公共参数到 post 消息体 | |
| 151 | + public Builder addParamsMap(Map<String, String> paramsMap) { | |
| 152 | + interceptor.paramsMap.putAll(paramsMap); | |
| 153 | + return this; | |
| 154 | + } | |
| 155 | + | |
| 156 | + // 添加公共参数到消息头 | |
| 157 | + public Builder addHeaderParam(String key, String value) { | |
| 158 | + interceptor.headerParamsMap.put(key, value); | |
| 159 | + return this; | |
| 160 | + } | |
| 161 | + | |
| 162 | + // 添加公共参数到消息头 | |
| 163 | + public Builder addHeaderParamsMap(Map<String, String> headerParamsMap) { | |
| 164 | + interceptor.headerParamsMap.putAll(headerParamsMap); | |
| 165 | + return this; | |
| 166 | + } | |
| 167 | + | |
| 168 | + // 添加公共参数到消息头 | |
| 169 | + public Builder addHeaderLine(String headerLine) { | |
| 170 | + int index = headerLine.indexOf(":"); | |
| 171 | + if (index == -1) { | |
| 172 | + throw new IllegalArgumentException("Unexpected header: " + headerLine); | |
| 173 | + } | |
| 174 | + interceptor.headerLinesList.add(headerLine); | |
| 175 | + return this; | |
| 176 | + } | |
| 177 | + | |
| 178 | + // 添加公共参数到消息头 | |
| 179 | + public Builder addHeaderLinesList(List<String> headerLinesList) { | |
| 180 | + for (String headerLine : headerLinesList) { | |
| 181 | + int index = headerLine.indexOf(":"); | |
| 182 | + if (index == -1) { | |
| 183 | + throw new IllegalArgumentException("Unexpected header: " + headerLine); | |
| 184 | + } | |
| 185 | + interceptor.headerLinesList.add(headerLine); | |
| 186 | + } | |
| 187 | + return this; | |
| 188 | + } | |
| 189 | + | |
| 190 | + // 添加公共参数到 URL | |
| 191 | + public Builder addQueryParam(String key, String value) { | |
| 192 | + interceptor.queryParamsMap.put(key, value); | |
| 193 | + return this; | |
| 194 | + } | |
| 195 | + | |
| 196 | + // 添加公共参数到 URL | |
| 197 | + public Builder addQueryParamsMap(Map<String, String> queryParamsMap) { | |
| 198 | + interceptor.queryParamsMap.putAll(queryParamsMap); | |
| 199 | + return this; | |
| 200 | + } | |
| 201 | + | |
| 202 | + public BasicParamsInterceptor build() { | |
| 203 | + return interceptor; | |
| 204 | + } | |
| 205 | + | |
| 206 | + } | |
| 207 | + | |
| 208 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/CmccRequest.java
| ... | ... | @@ -17,7 +17,9 @@ public class CmccRequest { |
| 17 | 17 | private static Class mclass; |
| 18 | 18 | //移动官方接口 |
| 19 | 19 | private static final String CMCC_API_DEBUG_URL = "http://storybox.roobo.net/"; |
| 20 | - private static final String CMCC_API_REA_URL = "https://storybox-api.roobo.com/rtoy/"; | |
| 20 | + // private static final String CMCC_API_REA_URL = "https://storybox-api.roobo.com/rtoy/"; | |
| 21 | + private static final String CMCC_API_REA_URL = "http://apiwjjtest.cnlive.com/"; | |
| 22 | + | |
| 21 | 23 | private static String TAG = "CmccRequest"; |
| 22 | 24 | |
| 23 | 25 | //错误状态码 |
| ... | ... | @@ -26,20 +28,27 @@ public class CmccRequest { |
| 26 | 28 | |
| 27 | 29 | public static ApiServiceCMCC getInstance(Class<ApiServiceCMCC> mclass) { |
| 28 | 30 | if (null == retrofit) { |
| 31 | + BasicParamsInterceptor basicParamsInterceptor = new BasicParamsInterceptor.Builder() | |
| 32 | + .addQueryParam("loginSid", "10510277") //添加公共参数到 post 请求体 | |
| 33 | + .addHeaderParam("Content-Type", "application/json;charset=UTF-8") | |
| 34 | +// .addQueryParam("version","1") // 添加公共版本号,加在 URL 后面 | |
| 35 | + .build(); | |
| 29 | 36 | // 创建Retrofit对象 |
| 30 | 37 | retrofit = new Retrofit.Builder() |
| 31 | 38 | .baseUrl(CMCC_API_REA_URL)//设置网络请求url,后面一段写在网络请求接口里面 |
| 32 | 39 | .addConverterFactory(GsonConverterFactory.create())//添加Gson支持,然后Retrofit就会使用Gson将响应体(api接口的Take)转换我们想要的类型。 |
| 33 | - .client(new OkHttpClient.Builder().addInterceptor(new Interceptor() { | |
| 34 | - @Override | |
| 35 | - public Response intercept(Chain chain) throws IOException { | |
| 36 | - Request request = chain.request() | |
| 37 | - .newBuilder() | |
| 38 | - .addHeader("Content-Type", "application/json;charset=UTF-8") | |
| 39 | - .build(); | |
| 40 | - return chain.proceed(request); | |
| 41 | - } | |
| 42 | - }).build()) | |
| 40 | +// .client(new OkHttpClient.Builder().addInterceptor(new Interceptor() { | |
| 41 | +// @Override | |
| 42 | +// public Response intercept(Chain chain) throws IOException { | |
| 43 | +// Request request = chain.request() | |
| 44 | +// .newBuilder() | |
| 45 | +// .addHeader("Content-Type", "application/json;charset=UTF-8") | |
| 46 | +// .build(); | |
| 47 | +// return chain.proceed(request); | |
| 48 | +// } | |
| 49 | +// }).build()) | |
| 50 | + .client(new OkHttpClient.Builder().addInterceptor(basicParamsInterceptor).build()) | |
| 51 | +// .client(new OkHttpClient.Builder().addInterceptor(basicParamsInterceptor)) | |
| 43 | 52 | .build(); |
| 44 | 53 | } |
| 45 | 54 | return retrofit.create(mclass); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/bean/InvitFamilyBean1.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork.bean; | |
| 2 | + | |
| 3 | +import java.io.Serializable; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 邀请家人上传的数据 | |
| 8 | + */ | |
| 9 | +public class InvitFamilyBean1 implements Serializable { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * type : 2 | |
| 13 | + * contactsInvite : [{"familyId":"1111","sid":105102771,"roleId":1},{"familyId":"1111","sid":105102772,"roleId":1}] | |
| 14 | + */ | |
| 15 | + | |
| 16 | + private String type; | |
| 17 | + private List<ContactsInviteBean> contactsInvite; | |
| 18 | + | |
| 19 | + public String getType() { | |
| 20 | + return type; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void setType(String type) { | |
| 24 | + this.type = type; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public List<ContactsInviteBean> getContactsInvite() { | |
| 28 | + return contactsInvite; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public void setContactsInvite(List<ContactsInviteBean> contactsInvite) { | |
| 32 | + this.contactsInvite = contactsInvite; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static class ContactsInviteBean implements Serializable{ | |
| 36 | + /** | |
| 37 | + * familyId : 1111 | |
| 38 | + * sid : 105102771 | |
| 39 | + * roleId : 1 | |
| 40 | + */ | |
| 41 | + | |
| 42 | + private String familyId; | |
| 43 | + private int sid; | |
| 44 | + private int roleId; | |
| 45 | + | |
| 46 | + public String getFamilyId() { | |
| 47 | + return familyId; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setFamilyId(String familyId) { | |
| 51 | + this.familyId = familyId; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public int getSid() { | |
| 55 | + return sid; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setSid(int sid) { | |
| 59 | + this.sid = sid; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public int getRoleId() { | |
| 63 | + return roleId; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setRoleId(int roleId) { | |
| 67 | + this.roleId = roleId; | |
| 68 | + } | |
| 69 | + } | |
| 70 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/SetFriendsRoleActivity.java
| ... | ... | @@ -4,7 +4,9 @@ import android.app.Activity; |
| 4 | 4 | import android.content.Intent; |
| 5 | 5 | import android.support.v7.app.AppCompatActivity; |
| 6 | 6 | import android.os.Bundle; |
| 7 | +import android.text.TextUtils; | |
| 7 | 8 | |
| 9 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 8 | 10 | import com.cnlive.strike.xiaojiaspeaker.R; |
| 9 | 11 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SelectWifiFragment; |
| 10 | 12 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SetFriendsRoleFragment; |
| ... | ... | @@ -20,15 +22,19 @@ public class SetFriendsRoleActivity extends AppCompatActivity { |
| 20 | 22 | setContentView(R.layout.activity_set_friends_role); |
| 21 | 23 | if (null != getIntent().getExtras()) { |
| 22 | 24 | String selectUid = getIntent().getExtras().getString("selectUid"); |
| 23 | - String currentSelectFamilyId= getIntent().getExtras().getString("currentSelectFamilyId"); | |
| 24 | - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, SetFriendsRoleFragment.newInstance(selectUid,currentSelectFamilyId)).commitAllowingStateLoss(); | |
| 25 | + String currentSelectFamilyId = getIntent().getExtras().getString("currentSelectFamilyId"); | |
| 26 | + if (!TextUtils.isEmpty(selectUid) && !TextUtils.isEmpty(currentSelectFamilyId)) { | |
| 27 | + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, SetFriendsRoleFragment.newInstance(selectUid, currentSelectFamilyId)).commitAllowingStateLoss(); | |
| 28 | + }else { | |
| 29 | + AlertUtil.showDeftToast(this,"参数异常"); | |
| 30 | + } | |
| 25 | 31 | } else { |
| 26 | 32 | finish(); |
| 27 | 33 | } |
| 28 | 34 | |
| 29 | 35 | } |
| 30 | 36 | |
| 31 | - public static void startActivity(Activity activity, String selectUid,String currentSelectFamilyId) { | |
| 37 | + public static void startActivity(Activity activity, String selectUid, String currentSelectFamilyId) { | |
| 32 | 38 | Intent intent = new Intent(activity, SetFriendsRoleActivity.class); |
| 33 | 39 | intent.putExtra("selectUid", selectUid); |
| 34 | 40 | intent.putExtra("currentSelectFamilyId", currentSelectFamilyId); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/AllRoleDetailAdapter.java
| ... | ... | @@ -123,26 +123,26 @@ public class AllRoleDetailAdapter extends RecyclerView.Adapter { |
| 123 | 123 | binding.checkBox.toggle(); |
| 124 | 124 | //开始设置全局状态 |
| 125 | 125 | if (binding.checkBox.isChecked()) { |
| 126 | - if (null != onAllRoleClickListener) { | |
| 127 | - onAllRoleClickListener.onSelect(allRoleList.get(position).getId()); | |
| 128 | - } | |
| 129 | - if (null != onDialogRoleClickListener) { | |
| 130 | - onDialogRoleClickListener.onSelect(allRoleList.get(position)); | |
| 131 | - } | |
| 132 | 126 | //添加到选中的集合 |
| 133 | 127 | if (!selectId.equals(currentRoleId)) { |
| 134 | 128 | //重置状态 |
| 135 | 129 | allowSelectMap.put(selectId, true); |
| 136 | 130 | setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).setSelectId(currentRoleId); |
| 137 | 131 | } |
| 132 | + if (null != onAllRoleClickListener) { | |
| 133 | + onAllRoleClickListener.onSelect(allRoleList.get(position).getId()); | |
| 134 | + } | |
| 135 | + if (null != onDialogRoleClickListener) { | |
| 136 | + onDialogRoleClickListener.onSelect(allRoleList.get(position)); | |
| 137 | + } | |
| 138 | 138 | } else { |
| 139 | + setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).setSelectId(""); | |
| 139 | 140 | if (null != onAllRoleClickListener) { |
| 140 | 141 | onAllRoleClickListener.onCancel(); |
| 141 | 142 | } |
| 142 | 143 | if (null != onDialogRoleClickListener) { |
| 143 | 144 | onDialogRoleClickListener.onCancel(); |
| 144 | 145 | } |
| 145 | - setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).setSelectId(""); | |
| 146 | 146 | } |
| 147 | 147 | //设置全局不允许选择 |
| 148 | 148 | allowSelectMap.put(currentRoleId, !binding.checkBox.isChecked()); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/SetRoleAdapter.java
| ... | ... | @@ -15,6 +15,7 @@ import com.cnlive.strike.xiaojiaspeaker.R; |
| 15 | 15 | import com.cnlive.strike.xiaojiaspeaker.databinding.ItemListSetRoleBinding; |
| 16 | 16 | import com.cnlive.strike.xiaojiaspeaker.model.RoleInfo; |
| 17 | 17 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.InvitFamilyBean; |
| 18 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.InvitFamilyBean1; | |
| 18 | 19 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.RoleNetBean; |
| 19 | 20 | import com.cnlive.strike.xiaojiaspeaker.util.GsonUtil; |
| 20 | 21 | |
| ... | ... | @@ -71,9 +72,9 @@ public class SetRoleAdapter extends RecyclerView.Adapter { |
| 71 | 72 | if (TextUtils.isEmpty(currentSelectFamilyId)) { |
| 72 | 73 | return result; |
| 73 | 74 | } |
| 74 | - List<InvitFamilyBean> invitFamilyBeanList = new ArrayList<>(); | |
| 75 | + List<InvitFamilyBean1.ContactsInviteBean> invitFamilyBeanList = new ArrayList<>(); | |
| 75 | 76 | for (int i = 0; i < roleInfoList.size(); i++) { |
| 76 | - InvitFamilyBean bean = new InvitFamilyBean(); | |
| 77 | + InvitFamilyBean1.ContactsInviteBean bean=new InvitFamilyBean1.ContactsInviteBean(); | |
| 77 | 78 | bean.setFamilyId(currentSelectFamilyId); |
| 78 | 79 | bean.setRoleId(Integer.parseInt(roleInfoList.get(i).getSelectId())); |
| 79 | 80 | bean.setSid(Integer.parseInt(roleInfoList.get(i).getUid())); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/SelectIMFriendFragment.java
| ... | ... | @@ -49,7 +49,9 @@ public class SelectIMFriendFragment extends MvpBindingFragment<SelectIMFriendVie |
| 49 | 49 | if (null != getArguments()) { |
| 50 | 50 | String currentSelectFamilyId = getArguments().getString("currentSelectFamilyId"); |
| 51 | 51 | if (!TextUtils.isEmpty(currentSelectFamilyId)) { |
| 52 | - getPresenter().getFamilyMember(getActivity(), currentSelectFamilyId); | |
| 52 | + getMvpView().setCurrentSelectFamilyId(currentSelectFamilyId); | |
| 53 | + getMvpView().initView(null); | |
| 54 | +// getPresenter().getFamilyMember(getActivity(), currentSelectFamilyId); | |
| 53 | 55 | } |
| 54 | 56 | } |
| 55 | 57 | ... | ... |