PopWindowPresneter.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. package com.edufound.reader.presenter;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.graphics.Rect;
  6. import android.os.Handler;
  7. import android.os.Message;
  8. import android.text.TextUtils;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.view.inputmethod.InputMethodManager;
  12. import android.widget.EditText;
  13. import android.widget.FrameLayout;
  14. import android.widget.ImageView;
  15. import android.widget.LinearLayout;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18. import androidx.annotation.NonNull;
  19. import androidx.recyclerview.widget.LinearLayoutManager;
  20. import androidx.recyclerview.widget.RecyclerView;
  21. import com.edufound.reader.R;
  22. import com.edufound.reader.activity.MainActivity;
  23. import com.edufound.reader.adapter.PopupMyOrderAdapter;
  24. import com.edufound.reader.adapter.RankListItemAdapter;
  25. import com.edufound.reader.apiserver.OrderApiServerImpl;
  26. import com.edufound.reader.apiserver.UserApiServerImpl;
  27. import com.edufound.reader.application.EApplication;
  28. import com.edufound.reader.bean.ChannelCodeEnum;
  29. import com.edufound.reader.bean.HttpResultBean;
  30. import com.edufound.reader.bean.MyInfoBean;
  31. import com.edufound.reader.bean.MyOrderListBean;
  32. import com.edufound.reader.bean.RankListBean;
  33. import com.edufound.reader.bean.RecordResultBean;
  34. import com.edufound.reader.bean.SignBean;
  35. import com.edufound.reader.bean.UserBean;
  36. import com.edufound.reader.bean.UserEventEnum;
  37. import com.edufound.reader.bean.UserRecordBean;
  38. import com.edufound.reader.cusview.CusToast;
  39. import com.edufound.reader.listener.PopupRecordStatusListener;
  40. import com.edufound.reader.miutil.MiSoundSDKUtil;
  41. import com.edufound.reader.model.PopWindowModelImpl;
  42. import com.edufound.reader.popwindow.PopWindowUtil;
  43. import com.edufound.reader.util.Consts;
  44. import com.edufound.reader.util.DeviceUuidFactory;
  45. import com.edufound.reader.util.EfunboxUtil;
  46. import com.edufound.reader.util.GlideUtils;
  47. import com.edufound.reader.util.OkHttpClient;
  48. import com.edufound.reader.util.QRCodeUtil;
  49. import com.edufound.reader.util.SizeUtils;
  50. import com.google.gson.Gson;
  51. import com.google.gson.reflect.TypeToken;
  52. import com.jakewharton.rxbinding4.view.RxView;
  53. import com.okhttplib.HttpInfo;
  54. import com.okhttplib.callback.Callback;
  55. import com.okhttplib.callback.ProgressCallback;
  56. import com.orhanobut.logger.Logger;
  57. import org.json.JSONObject;
  58. import java.io.IOException;
  59. import java.util.ArrayList;
  60. import java.util.HashMap;
  61. import java.util.List;
  62. import java.util.Map;
  63. import java.util.concurrent.TimeUnit;
  64. public class PopWindowPresneter {
  65. PopWindowModelImpl mModel;
  66. ProgressCallback mUploadProgressBack;
  67. Gson mGson;
  68. UserApiServerImpl userApi;
  69. Activity mActivity;
  70. OrderApiServerImpl mOrderApi;
  71. public PopWindowPresneter() {
  72. userApi = new UserApiServerImpl();
  73. mOrderApi = new OrderApiServerImpl();
  74. mModel = new PopWindowModelImpl();
  75. mGson = new Gson();
  76. }
  77. public void initRecordStatusWindow(Activity activity, View dialog_view, RecordResultBean bean, UserRecordBean.UserRead userread, PopupRecordStatusListener listener) {
  78. mActivity = activity;
  79. FrameLayout mOverFrame = dialog_view.findViewById(R.id.popupwindow_record_status_over_frame);
  80. FrameLayout mUploadingFrame = dialog_view.findViewById(R.id.popupwindow_record_status_uploading_frame);
  81. FrameLayout mUploadingSuccessFrame = dialog_view.findViewById(R.id.popupwindow_record_status_uploading_success_frame);
  82. FrameLayout mUploadingErrorFrame = dialog_view.findViewById(R.id.popupwindow_record_status_uploading_error_frame);
  83. LinearLayout startLayout = mOverFrame.findViewById(R.id.popupwindow_record_status_over_start_layout);
  84. FrameLayout mRePlay = mOverFrame.findViewById(R.id.popupwindow_record_status_over_replay);
  85. FrameLayout mUpload = mOverFrame.findViewById(R.id.popupwindow_record_status_over_upload);
  86. // float a = bean.getOverall() / 100f;//百分制
  87. int integrity = bean.getIntegrity();
  88. int accuracy = bean.getAccuracy();
  89. int speedd = bean.getSpeed();
  90. int tone = bean.getTone();
  91. int score = (int) ((integrity * 0.5) + (bean.getOverall() * 0.3) + (speedd * 0.1) + (tone * 0.1));
  92. int startCount = 0;
  93. if (score > 0 && score <= 20) {
  94. //1个星星
  95. startCount = 1;
  96. } else if (score > 20 && score <= 40) {
  97. //2个星星
  98. startCount = 2;
  99. } else if (score > 40 && score <= 60) {
  100. //3个星星
  101. startCount = 3;
  102. } else if (score > 60 && score <= 80) {
  103. //4个星星
  104. startCount = 4;
  105. } else if (score > 80 && score <= 100) {
  106. //5个星星
  107. startCount = 5;
  108. }
  109. //先显示评测报告,处理测评报告逻辑
  110. {
  111. mOverFrame.setVisibility(View.VISIBLE);
  112. startLayout.removeAllViews();
  113. for (int i = 0; i < 5; i++) {
  114. ImageView start = new ImageView(activity);
  115. if (i < startCount) {
  116. start.setImageResource(R.drawable.popup_record_status_over_stars_true);
  117. } else {
  118. start.setImageResource(R.drawable.popup_record_status_over_stars_false);
  119. }
  120. start.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1));
  121. startLayout.addView(start);
  122. }
  123. TextView completionText = mOverFrame.findViewById(R.id.popupwindow_record_status_over_completion_text);
  124. TextView correctrateText = mOverFrame.findViewById(R.id.popupwindow_record_status_over_correctrate_text);
  125. TextView speedText = mOverFrame.findViewById(R.id.popupwindow_record_status_over_speed_text);
  126. TextView intonationText = mOverFrame.findViewById(R.id.popupwindow_record_status_over_intonation_text);
  127. completionText.post(new Runnable() {
  128. @Override
  129. public void run() {
  130. for (int completionPoint = 0; completionPoint < integrity; completionPoint++) {
  131. Message msg = new Message();
  132. msg.obj = completionText;
  133. msg.arg1 = completionPoint + 1;
  134. msg.what = 0x0131;
  135. handler.sendMessageDelayed(msg, 50 * completionPoint);
  136. }
  137. }
  138. });
  139. correctrateText.post(new Runnable() {
  140. @Override
  141. public void run() {
  142. for (int correctrate = 0; correctrate < accuracy; correctrate++) {
  143. Message msg = new Message();
  144. msg.obj = correctrateText;
  145. msg.arg1 = correctrate + 1;
  146. msg.what = 0x0131;
  147. handler.sendMessageDelayed(msg, 50 * correctrate);
  148. }
  149. }
  150. });
  151. speedText.post(new Runnable() {
  152. @Override
  153. public void run() {
  154. for (int speed = 0; speed < speedd; speed++) {
  155. Message msg = new Message();
  156. msg.obj = speedText;
  157. msg.arg1 = speed + 1;
  158. msg.what = 0x0131;
  159. handler.sendMessageDelayed(msg, 50 * speed);
  160. }
  161. }
  162. });
  163. intonationText.post(new Runnable() {
  164. @Override
  165. public void run() {
  166. for (int intonation = 0; intonation < tone; intonation++) {
  167. Message msg = new Message();
  168. msg.obj = intonationText;
  169. msg.arg1 = intonation + 1;
  170. msg.what = 0x0131;
  171. handler.sendMessageDelayed(msg, 50 * intonation);
  172. }
  173. }
  174. });
  175. mUploadProgressBack = new ProgressCallback() {
  176. @Override
  177. public void onResponseMain(String filePath, HttpInfo info) {
  178. super.onResponseMain(filePath, info);
  179. Logger.e("onResponseMain:" + info.getRetDetail());
  180. Logger.e("onResponseMain--netCode:" + info.getNetCode());
  181. if (info.getNetCode() == 200) {
  182. //上传完成了
  183. //上传成功逻辑
  184. {
  185. HttpResultBean<String> bean = info.getRetDetail(new TypeToken<HttpResultBean<String>>() {
  186. }.getType());
  187. Logger.e("filePath:" + bean.getData());
  188. //请求发布接口
  189. Map<String, String> postUserRead = new HashMap<>();
  190. postUserRead.put("audioPath", bean.getData());
  191. postUserRead.put("coverImg", userread.getCoverImg());
  192. postUserRead.put("exampleId", userread.getExampleId());
  193. postUserRead.put("originVideo", userread.getOriginVideo());
  194. postUserRead.put("shareImg", userread.getShareImg());
  195. postUserRead.put("title", userread.getTitle());
  196. postUserRead.put("type", "READ");
  197. postUserRead.put("uid", Consts.getUID());
  198. mModel.postUserRead(activity, mGson.toJson(postUserRead), new Callback() {
  199. @Override
  200. public void onSuccess(HttpInfo info) throws IOException {
  201. //发布朗读成功了,成功之后求情评测数据接口
  202. Logger.e("发布朗读成功了:" + info.getRetDetail());
  203. HttpResultBean<UserRecordBean.UserRead> read = info.getRetDetail(new TypeToken<HttpResultBean<UserRecordBean.UserRead>>() {
  204. }.getType());
  205. Map<String, String> postAssessment = new HashMap<>();
  206. postAssessment.put("complete", String.valueOf(integrity));
  207. postAssessment.put("speed", String.valueOf(speedd));
  208. postAssessment.put("intonation", String.valueOf(tone));
  209. postAssessment.put("score", String.valueOf(score));
  210. postAssessment.put("accuracy", String.valueOf(accuracy));
  211. postAssessment.put("userReadId", read.getData().getId());
  212. mModel.postAssessment(activity, mGson.toJson(postAssessment), new Callback() {
  213. @Override
  214. public void onSuccess(HttpInfo info) throws IOException {
  215. Logger.e("请求评测成功:" + info.getRetDetail());
  216. mUploadingSuccessFrame.setVisibility(View.VISIBLE);
  217. FrameLayout toLisMySelf = mUploadingSuccessFrame.findViewById(R.id.popup_record_status_upload_success_btn);
  218. toLisMySelf.setOnClickListener(new View.OnClickListener() {
  219. @Override
  220. public void onClick(View view) {
  221. PopWindowUtil.hidePopupWindow();
  222. // Toast.makeText(context, "去听听(首页->我的tab)", Toast.LENGTH_SHORT).show();
  223. EApplication.reloadApp(0);
  224. }
  225. });
  226. }
  227. @Override
  228. public void onFailure(HttpInfo info) throws IOException {
  229. Logger.e("请求评测失败:" + info.getRetDetail());
  230. }
  231. });
  232. }
  233. @Override
  234. public void onFailure(HttpInfo info) throws IOException {
  235. Logger.e("发布朗读失败了:" + info.getRetDetail());
  236. }
  237. });
  238. }
  239. } else {
  240. //失败逻辑
  241. {
  242. mUploadingErrorFrame.setVisibility(View.VISIBLE);
  243. FrameLayout mCancelUpload = mUploadingErrorFrame.findViewById(R.id.popupwindow_record_status_uploading_error_cancel_upload);
  244. FrameLayout mReUpload = mUploadingErrorFrame.findViewById(R.id.popupwindow_record_status_uploading_error_re_upload);
  245. mCancelUpload.setOnClickListener(new View.OnClickListener() {
  246. @Override
  247. public void onClick(View view) {
  248. PopWindowUtil.hidePopupWindow();
  249. }
  250. });
  251. mReUpload.setOnClickListener(new View.OnClickListener() {
  252. @Override
  253. public void onClick(View view) {
  254. // Toast.makeText(context, "重新上传", Toast.LENGTH_SHORT).show();
  255. Logger.e("重新上传");
  256. mUploadingErrorFrame.setVisibility(View.GONE);
  257. mUploadingFrame.setVisibility(View.VISIBLE);
  258. userApi.postUserEvent(activity, UserEventEnum.EVENT_UPLOAD.getEvent());
  259. mModel.upLoadRecord(activity, Consts.getRecordUpLoadFileUrl(), mUploadProgressBack);
  260. }
  261. });
  262. }
  263. }
  264. }
  265. @Override
  266. public void onProgressAsync(int percent, long bytesWritten, long contentLength, boolean done) {
  267. super.onProgressAsync(percent, bytesWritten, contentLength, done);
  268. }
  269. @Override
  270. public void onProgressMain(int percent, long bytesWritten, long contentLength, boolean done) {
  271. super.onProgressMain(percent, bytesWritten, contentLength, done);
  272. }
  273. };
  274. mUpload.setOnClickListener(new View.OnClickListener() {
  275. @Override
  276. public void onClick(View view) {
  277. //上传录音
  278. mOverFrame.setVisibility(View.GONE);
  279. mUploadingFrame.setVisibility(View.VISIBLE);
  280. userApi.postUserEvent(activity, UserEventEnum.EVENT_UPLOAD.getEvent());
  281. mModel.upLoadRecord(activity, Consts.getRecordUpLoadFileUrl(), mUploadProgressBack);
  282. }
  283. });
  284. mRePlay.setOnClickListener(new View.OnClickListener() {
  285. @Override
  286. public void onClick(View view) {
  287. listener.clickReRecord();
  288. }
  289. });
  290. }
  291. }
  292. public void myOrderWindowInit(Activity context, View view) {
  293. // for (int i = 0; i < 30; i++) {
  294. // mDataList.add("i=" + i);
  295. // }
  296. OkHttpClient.doGetAsync(context, new HttpInfo.Builder().setUrl(Consts.getFinalApi() + "/order"), new Callback() {
  297. @Override
  298. public void onSuccess(HttpInfo info) throws IOException {
  299. Logger.e("info:" + info.getRetDetail());
  300. HttpResultBean<List<MyOrderListBean>> bean = info.getRetDetail(new TypeToken<HttpResultBean<List<MyOrderListBean>>>() {
  301. }.getType());
  302. if (bean.getData() != null && bean.getData().size() > 0) {
  303. RecyclerView rv = view.findViewById(R.id.popupwindow_myorder_recyclerview);
  304. PopupMyOrderAdapter popupMyOrderAdapter = new PopupMyOrderAdapter(context, bean.getData());
  305. rv.addItemDecoration(new OrderSpacesItemDecoration(SizeUtils.dp2px(context, 10), bean.getData().size()));
  306. rv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
  307. rv.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
  308. @Override
  309. public void onChildViewAttachedToWindow(@androidx.annotation.NonNull View view) {
  310. }
  311. @Override
  312. public void onChildViewDetachedFromWindow(@androidx.annotation.NonNull View view) {
  313. }
  314. });
  315. rv.setAdapter(popupMyOrderAdapter);
  316. } else {
  317. view.findViewById(R.id.popupwindow_myorder_noitem).setVisibility(View.VISIBLE);
  318. }
  319. }
  320. @Override
  321. public void onFailure(HttpInfo info) throws IOException {
  322. }
  323. });
  324. }
  325. public void getBindWeChatPath(Activity activity, ImageView imageView) {
  326. mActivity = activity;
  327. userApi.getBindWeChatPath(activity, new Callback() {
  328. @Override
  329. public void onSuccess(HttpInfo info) throws IOException {
  330. Logger.e("获取绑定微信成功:" + info.getRetDetail());
  331. HttpResultBean<String> bean = info.getRetDetail(new TypeToken<HttpResultBean<String>>() {
  332. }.getType());
  333. imageView.setImageBitmap(QRCodeUtil.createQRCode(bean.getData(), SizeUtils.dp2px(activity, 900)));
  334. }
  335. @Override
  336. public void onFailure(HttpInfo info) throws IOException {
  337. Logger.e("获取绑定微信失败:" + info.getRetDetail());
  338. }
  339. });
  340. }
  341. public void getMyInfo(Activity activity, TextView textView) {
  342. mActivity = activity;
  343. userApi.getMyInfo(activity, new Callback() {
  344. @Override
  345. public void onSuccess(HttpInfo info) throws IOException {
  346. HttpResultBean<MyInfoBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<MyInfoBean>>() {
  347. }.getType());
  348. if (bean.getData().getUser().getOpenId() == null || bean.getData().getUser().getOpenId().equals("")) {
  349. textView.setText("");
  350. } else {
  351. textView.setText("微信昵称:" + bean.getData().getUser().getWechatName());
  352. textView.setVisibility(View.VISIBLE);
  353. }
  354. }
  355. @Override
  356. public void onFailure(HttpInfo info) throws IOException {
  357. }
  358. });
  359. Message message = new Message();
  360. message.obj = textView;
  361. message.what = 0x1312;
  362. handler.sendMessageDelayed(message, 3000);
  363. }
  364. /**
  365. * 排行榜
  366. */
  367. public void rankListInit(Context context, View dialog_view, String id) {
  368. Logger.e("id:" + id);
  369. //请求排行榜接口
  370. userApi.getRankList(id, new Callback() {
  371. @Override
  372. public void onSuccess(HttpInfo info) throws IOException {
  373. HttpResultBean<RankListBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<RankListBean>>() {
  374. }.getType());
  375. //设置数据
  376. if (bean.getData().getActivityUserReadList() != null && bean.getData().getActivityUserReadList().size() > 0) {
  377. RankListItemAdapter adapter = new RankListItemAdapter(context, bean.getData().getActivityUserReadList());
  378. LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
  379. RecyclerView recyclerView = dialog_view.findViewById(R.id.popupwindow_ranklist_recyclerview);
  380. recyclerView.setLayoutManager(linearLayoutManager);
  381. recyclerView.setAdapter(adapter);
  382. FrameLayout myInfoLayout = dialog_view.findViewById(R.id.popupwindow_ranklist_myinfo_layout);
  383. TextView myNum = dialog_view.findViewById(R.id.popupwindow_show_ranklist_my_num);
  384. TextView myName = dialog_view.findViewById(R.id.popupwindow_show_ranklist_my_name);
  385. TextView myThumb = dialog_view.findViewById(R.id.popupwindow_show_ranklist_my_thumb);
  386. TextView myCollection = dialog_view.findViewById(R.id.popupwindow_show_ranklist_my_collection);
  387. TextView myScore = dialog_view.findViewById(R.id.popupwindow_show_ranklist_my_score);
  388. myInfoLayout.setVisibility(View.GONE);
  389. boolean getMyRank = false;
  390. for (int i = 0; i < bean.getData().getActivityUserReadList().size(); i++) {
  391. if (getMyRank == false && bean.getData().getActivityUserReadList().get(i).getUser().getUid().equals(Consts.getUID())) {
  392. //获取到数据了,并且只获取第一次得到的
  393. getMyRank = true;
  394. myName.setText("我自己");
  395. myNum.setText((i + 1) + "");
  396. myThumb.setText(bean.getData().getActivityUserReadList().get(i).getUserRead().getLikeAmount());
  397. myCollection.setText(bean.getData().getActivityUserReadList().get(i).getUserRead().getFavoritesAmount());
  398. myScore.setText(bean.getData().getActivityUserReadList().get(i).getUserRead().getScore());
  399. myInfoLayout.setVisibility(View.VISIBLE);
  400. }
  401. }
  402. } else {
  403. LinearLayout recyParent = dialog_view.findViewById(R.id.popupwindow_ranklist_recyclerview_layout);
  404. recyParent.setVisibility(View.GONE);
  405. ImageView noList = dialog_view.findViewById(R.id.popupwindow_ranklist_recyclerview_layout_nolist);
  406. noList.setVisibility(View.VISIBLE);
  407. }
  408. }
  409. @Override
  410. public void onFailure(HttpInfo info) throws IOException {
  411. }
  412. });
  413. }
  414. boolean loginSuccess = false;
  415. MISoundLoginCallBack miSoundLoginCallback;
  416. int mVCodeCount = 60;
  417. TextView getVCodeTimeText;
  418. public void initMiSoundLoginWindow(Context context, View dialog_view, int type, MISoundLoginCallBack callBack) {
  419. miSoundLoginCallback = callBack;
  420. switch (type) {
  421. case MiSoundSDKUtil.MI_SOUND_QRCODE_TYPE:
  422. ImageView qrcode = dialog_view.findViewById(R.id.popupwindow_mi_sound_qrcode);
  423. userApi.getLoginQRCode(new Callback() {
  424. @Override
  425. public void onSuccess(HttpInfo info) throws IOException {
  426. Logger.e("info:" + info.getRetDetail());
  427. HttpResultBean<String> bean = info.getRetDetail(new TypeToken<HttpResultBean<String>>() {
  428. }.getType());
  429. Logger.e("bean.getData:" + bean.getData());
  430. if (bean.getCode().equals("200") && bean.getSuccess()) {
  431. Logger.e("加载二维码");
  432. GlideUtils.loadImageSizeKipMemoryCache(context, bean.getData(), qrcode);
  433. loginSuccess = false;
  434. handler.sendEmptyMessageDelayed(0x1313, 1000);
  435. } else {
  436. Logger.e("加载二维码失败");
  437. }
  438. }
  439. @Override
  440. public void onFailure(HttpInfo info) throws IOException {
  441. Logger.e("获取登录二维码失败");
  442. }
  443. });
  444. break;
  445. case MiSoundSDKUtil.MI_SOUND_BIND_PHONENUM: {
  446. EditText bindPhoneNumEdit = dialog_view.findViewById(R.id.popupwindow_mi_sound_bind_phone_num_edit);
  447. EditText bindPhoneNumGetVCode = dialog_view.findViewById(R.id.popupwindow_mi_sound_bind_phone_vcode_edit);
  448. getVCodeTimeText = dialog_view.findViewById(R.id.popupwindow_mi_sound_bind_phone_getvcode_text);
  449. FrameLayout mBindSubmit = dialog_view.findViewById(R.id.popupwindow_mi_sound_bind_phone_num_submit);
  450. TextView mErrorText = dialog_view.findViewById(R.id.popupwindow_mi_sound_bind_phone_error_text);
  451. mErrorText.setVisibility(View.GONE);
  452. // {
  453. // //测试
  454. // bindPhoneNumEdit.setText("18611822573");
  455. // bindPhoneNumGetVCode.setText("9999");
  456. // }
  457. RxView.focusChanges(bindPhoneNumEdit).subscribe(hasFocus -> {
  458. if (!hasFocus) {
  459. hideSoftInput(bindPhoneNumEdit);
  460. }
  461. });
  462. RxView.focusChanges(bindPhoneNumGetVCode).subscribe(hasFocus -> {
  463. if (!hasFocus) {
  464. hideSoftInput(bindPhoneNumGetVCode);
  465. }
  466. });
  467. //获取验证码
  468. RxView.clicks(getVCodeTimeText).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
  469. String mobile = bindPhoneNumEdit.getText().toString().trim();
  470. if (!EfunboxUtil.isMobileNO(mobile)) {
  471. //弹不出来
  472. // CusToast.getInstance(context).show("请输入正确的手机号", 1000);
  473. mErrorText.setText("请输入正确的手机号");
  474. mErrorText.setVisibility(View.VISIBLE);
  475. return;
  476. }
  477. OkHttpClient.doGetAsync(HttpInfo.Builder().setUrl(Consts.getFinalApi() + "/user/verifyCode").addParam("mobileNo", mobile), new Callback() {
  478. @Override
  479. public void onSuccess(HttpInfo info) throws IOException {
  480. getVCodeTimeText.setText(String.valueOf(mVCodeCount));
  481. getVCodeTimeText.setEnabled(false);
  482. getVCodeTimeText.setClickable(false);
  483. handler.sendEmptyMessageDelayed(0x1314, 1000);
  484. }
  485. @Override
  486. public void onFailure(HttpInfo info) throws IOException {
  487. //弹不出来
  488. // CusToast.getInstance(Consts.getmApplicAtion()).show("获取验证码失败", 1000);
  489. mErrorText.setText("获取验证码失败:" + info.getRetDetail());
  490. mErrorText.setVisibility(View.VISIBLE);
  491. getVCodeTimeText.setEnabled(true);
  492. getVCodeTimeText.setClickable(true);
  493. }
  494. });
  495. });
  496. //提交绑定手机号
  497. RxView.clicks(mBindSubmit).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
  498. String mobile = bindPhoneNumEdit.getText().toString().trim();
  499. if (!EfunboxUtil.isMobileNO(mobile)) {
  500. // CusToast.getInstance(context).show("请输入正确的手机号", 1000);
  501. mErrorText.setText("请输入正确的手机号");
  502. mErrorText.setVisibility(View.VISIBLE);
  503. return;
  504. }
  505. userApi.bindPhoneNum(mobile, new Callback() {
  506. @Override
  507. public void onSuccess(HttpInfo info) throws IOException {
  508. HttpResultBean<UserBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<UserBean>>() {
  509. }.getType());
  510. Logger.e("绑定手机号:" + info.getRetDetail());
  511. if (bean.getCode().equals("200")) {
  512. if (bean.getSuccess()) {
  513. Logger.e("绑定手机号成功:" + info.getRetDetail());
  514. Consts.setmConstsUserBean(bean.getData());
  515. Toast.makeText(context, "绑定手机号成功", Toast.LENGTH_LONG).show();
  516. mErrorText.setText("绑定手机号成功");
  517. mErrorText.setVisibility(View.VISIBLE);
  518. miSoundLoginCallback.success();
  519. }
  520. } else if (bean.getCode().equals("706")) {
  521. mErrorText.setText("绑定手机号失败:" + bean.getMessage());
  522. mErrorText.setVisibility(View.VISIBLE);
  523. }
  524. }
  525. @Override
  526. public void onFailure(HttpInfo info) throws IOException {
  527. Logger.e("绑定手机号失败:" + info.getRetDetail());
  528. mErrorText.setText("绑定手机号失败:" + info.getRetDetail());
  529. mErrorText.setVisibility(View.VISIBLE);
  530. }
  531. });
  532. });
  533. }
  534. break;
  535. case MiSoundSDKUtil.MI_SOUND_SHOW_BINDPHONENUM: {
  536. TextView tv = dialog_view.findViewById(R.id.popupwindow_mi_sound_show_bind_phoneNum_layout_phoneNum);
  537. tv.setText("手机号码 :" + Consts.getmConstsUserBean().getMobile());
  538. }
  539. break;
  540. }
  541. }
  542. private void hideSoftInput(View view) {
  543. InputMethodManager manager = ((InputMethodManager) Consts.getmApplicAtion().getSystemService(Context.INPUT_METHOD_SERVICE));
  544. if (manager != null) {
  545. manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
  546. }
  547. }
  548. public Handler getPopHandler() {
  549. return handler;
  550. }
  551. private Handler handler = new Handler(new Handler.Callback() {
  552. @Override
  553. public boolean handleMessage(@NonNull Message message) {
  554. switch (message.what) {
  555. case 0x0131:
  556. ((TextView) message.obj).setText(message.arg1 + "/100");
  557. break;
  558. case 0x1312:
  559. getMyInfo(mActivity, (TextView) message.obj);
  560. break;
  561. case 0x1313:
  562. //小米绑定手机号轮询查询用户逻辑
  563. if (loginSuccess) {
  564. handler.removeMessages(0x1313);
  565. return true;
  566. }
  567. userApi.MiSoundIsLogin(DeviceUuidFactory.getUuid(), new Callback() {
  568. @Override
  569. public void onSuccess(HttpInfo info) throws IOException {
  570. try {
  571. JSONObject object = new JSONObject(info.getRetDetail());
  572. if (object.getString("code").equals("300") || object.getInt("code") == 300) {
  573. //暂无数据
  574. Logger.e("暂无数据");
  575. handler.sendEmptyMessageDelayed(0x1313, 1000);
  576. return;
  577. } else {
  578. Logger.e("info.getR:" + info.getRetDetail());
  579. handler.removeMessages(0x1313);
  580. loginSuccess = true;
  581. HttpResultBean<UserBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<UserBean>>() {
  582. }.getType());
  583. Consts.setUID(bean.getData().getUid());
  584. //用户是否登录,登录了,创建Consts的userbean
  585. Consts.setmConstsUserBean(bean.getData());
  586. userApi.loginSign(null, new Callback() {
  587. @Override
  588. public void onSuccess(HttpInfo info) throws IOException {
  589. try {
  590. HttpResultBean<SignBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<SignBean>>() {
  591. }.getType());
  592. if (bean.getData().getIsSign()) {
  593. CusToast.getInstance(Consts.getmApplicAtion()).show("恭喜签到成功\n奖励" + bean.getData().getCount() + "朵小红花", 2000);
  594. }
  595. } catch (Exception e) {
  596. e.printStackTrace();
  597. } finally {
  598. miSoundLoginCallback.success();
  599. if (Consts.getUmengChannel().equals(ChannelCodeEnum.YIFANG.getChannelCode()) ||
  600. Consts.getUmengChannel().equals(ChannelCodeEnum.TMAIL.getChannelCode()) ||
  601. Consts.getUmengChannel().equals(ChannelCodeEnum.MISOUND.getChannelCode())
  602. ) {
  603. //义方渠道检查权限
  604. if (Consts.getmConstsUserBean() != null) {
  605. mOrderApi.getAuth(new Callback() {
  606. @Override
  607. public void onSuccess(HttpInfo info) throws IOException {
  608. HttpResultBean<String> bean = info.getRetDetail(new TypeToken<HttpResultBean<String>>() {
  609. }.getType());
  610. if (!TextUtils.isEmpty(bean.getData())) {
  611. Consts.setIsYFVip(true);
  612. }
  613. }
  614. @Override
  615. public void onFailure(HttpInfo info) throws IOException {
  616. }
  617. });
  618. }
  619. }
  620. }
  621. }
  622. @Override
  623. public void onFailure(HttpInfo info) throws IOException {
  624. Logger.e("info:" + info.getRetDetail());
  625. }
  626. });
  627. }
  628. } catch (Exception e) {
  629. e.printStackTrace();
  630. } finally {
  631. }
  632. }
  633. @Override
  634. public void onFailure(HttpInfo info) throws IOException {
  635. Logger.e("misound_login_error_info.get:" + info.getRetDetail());
  636. }
  637. });
  638. break;
  639. case 0x1314:
  640. //小米绑定手机号倒计时逻辑
  641. if (mVCodeCount == 0) {
  642. mVCodeCount = 60;
  643. handler.removeMessages(0x1314);
  644. getVCodeTimeText.setEnabled(true);
  645. getVCodeTimeText.setClickable(true);
  646. getVCodeTimeText.setText("获取验证码");
  647. return true;
  648. } else {
  649. mVCodeCount--;
  650. getVCodeTimeText.setText(String.valueOf(mVCodeCount));
  651. handler.sendEmptyMessageDelayed(0x1314, 1000);
  652. }
  653. break;
  654. }
  655. return false;
  656. }
  657. });
  658. public interface MISoundLoginCallBack {
  659. void success();
  660. }
  661. }
  662. class OrderSpacesItemDecoration extends RecyclerView.ItemDecoration {
  663. private int space;
  664. private int maxCount;
  665. public OrderSpacesItemDecoration(int space, int max) {
  666. this.space = space;
  667. this.maxCount = max;
  668. }
  669. @Override
  670. public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
  671. int position = parent.getChildAdapterPosition(view);
  672. Logger.e("position:" + position);
  673. Logger.e("parent:" + parent.getChildCount());
  674. if (position < 1) {
  675. outRect.top = space * 10;
  676. outRect.bottom = space;
  677. } else {
  678. outRect.bottom = space;
  679. }
  680. if (position == maxCount - 1) {
  681. outRect.bottom = space * 10;
  682. }
  683. }
  684. }