PopWindowPresneter.java 40 KB

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