UserRetrievePwdFragment.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package com.yyrh.ui.fragment;
  2. import android.app.Activity;
  3. import android.app.Fragment;
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.os.CountDownTimer;
  7. import android.support.annotation.NonNull;
  8. import android.support.annotation.Nullable;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.ImageButton;
  15. import android.widget.TextView;
  16. import com.yyrh.constant.SDKSettings;
  17. import com.yyrh.constant.URLConstants;
  18. import com.yyrh.networking.NetRequestApi;
  19. import com.yyrh.ui.dialog.WvPageListDialog;
  20. import com.yyrh.ui.userlist.DatabaseHelper;
  21. import com.yyrh.utils.ResourceUtil;
  22. import com.yyrh.utils.TosUtil;
  23. import com.yyrh.utils.Utils;
  24. import java.util.HashMap;
  25. public class UserRetrievePwdFragment extends BaseFragment {
  26. private EditText et_user_phone,et_user_code,et_user_pwd;
  27. private Button btn_get_code,reg_compete_btn;
  28. private ImageButton close_btn;
  29. private TextView tv_tip_2;
  30. @Nullable
  31. @Override
  32. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  33. View view = inflater.inflate(ResourceUtil.getLayoutId(getActivity(),"qj_retrieve_pwd"), container, false);
  34. view.setClickable(true);
  35. return view;
  36. }
  37. @Override
  38. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  39. super.onViewCreated(view, savedInstanceState);
  40. et_user_phone = view.findViewById(ResourceUtil.getId(getActivity(), "et_user_phone"));
  41. et_user_code = view.findViewById(ResourceUtil.getId(getActivity(), "et_user_code"));
  42. et_user_pwd = view.findViewById(ResourceUtil.getId(getActivity(), "et_user_pwd"));
  43. btn_get_code = view.findViewById(ResourceUtil.getId(getActivity(), "btn_get_code"));
  44. reg_compete_btn = view.findViewById(ResourceUtil.getId(getActivity(), "reg_compete_btn"));
  45. tv_tip_2 = view.findViewById(ResourceUtil.getId(getActivity(), "tv_tip_2"));
  46. tv_tip_2.setOnClickListener(this);
  47. close_btn = view.findViewById(ResourceUtil.getId(getActivity(), "close_btn"));
  48. btn_get_code.setOnClickListener(this);
  49. close_btn.setOnClickListener(this);
  50. reg_compete_btn.setOnClickListener(this);
  51. }
  52. @Override
  53. public void onClick(View v) {
  54. super.onClick(v);
  55. int id = v.getId();
  56. if (id == ResourceUtil.getId(getActivity(), "btn_get_code")) {
  57. String phone = et_user_phone.getText().toString();
  58. if (phone.length() < 10) {
  59. new TosUtil(getActivity(),TosUtil.TOAST_ERROR, getString(ResourceUtil.getStringId(getActivity(), "qj_pls_input_right_phone"))).show();
  60. return;
  61. }
  62. getPhoneCaptcha(getActivity(),phone,"modify_pwd");
  63. }else if (id == ResourceUtil.getId(getActivity(), "reg_compete_btn")) {
  64. String phone = et_user_phone.getText().toString();
  65. String code = et_user_code.getText().toString();
  66. final String pwd = et_user_pwd.getText().toString();
  67. if (phone.length() < 10) {
  68. new TosUtil(getActivity(),TosUtil.TOAST_ERROR,getString(ResourceUtil.getStringId(getActivity(), "qj_pls_input_right_phone"))).show();
  69. return;
  70. }
  71. if(code.length() < 4 || Utils.judgeStrNull(code))
  72. {
  73. new TosUtil(getActivity(),TosUtil.TOAST_ERROR,getString(ResourceUtil.getStringId(getActivity(), "qj_pls_input_right_code"))).show();
  74. return;
  75. }
  76. if(pwd.length() < 6 || Utils.judgeStrNull(pwd))
  77. {
  78. new TosUtil(getActivity(),TosUtil.TOAST_ERROR, getString(ResourceUtil.getStringId(getActivity(), "qj_pwd_limit_6"))).show();
  79. return;
  80. }
  81. resetPwdWithPhone(getActivity(),phone,code,pwd);
  82. }else if (id == ResourceUtil.getId(getActivity(), "close_btn")) {
  83. Fragment accountLoginFragment = FragmentUtils.getSdkFragment(getActivity(),FragmentUtils.SDK_LOGIN_TAG);
  84. replaceFragmentToActivity(getFragmentManager(),accountLoginFragment,ResourceUtil.getId(getActivity(),"qj_content"));
  85. }else if (id == ResourceUtil.getId(getActivity(), "tv_tip_2")) {
  86. if (!Utils.judgeStrNull(SDKSettings.initConfig.service_center)){
  87. new WvPageListDialog(getActivity(),ResourceUtil.getStyleId(getActivity(),"qj_half_black_dialog"),SDKSettings.initConfig.service_center).show();
  88. }
  89. }
  90. }
  91. private void getPhoneCaptcha(Activity activity, String phone, String action){
  92. NetRequestApi.getPhoneCaptcha(activity, phone, action, new UserPhoneLoginFragment.CaptchaCallback() {
  93. @Override
  94. public void onGetSuccess(String msg) {
  95. getCodeSuccess();
  96. new TosUtil(getActivity(),TosUtil.TOAST_GREEN, getString(ResourceUtil.getStringId(getActivity(), "qj_send_code_success"))).show();
  97. }
  98. @Override
  99. public void onGetFailed(String msg) {
  100. new TosUtil(getActivity(),TosUtil.TOAST_ERROR, msg).show();
  101. }
  102. });
  103. }
  104. private void getCodeSuccess() {
  105. btn_get_code.setEnabled(false);
  106. btn_get_code.setText("60s");
  107. TimeCount time = new TimeCount(60000, 1000);
  108. time.start();
  109. }
  110. class TimeCount extends CountDownTimer {
  111. public TimeCount(long millisInFuture, long countDownInterval) {
  112. super(millisInFuture, countDownInterval);
  113. // TODO Auto-generated constructor stub
  114. }
  115. @Override
  116. public void onTick(long millisUntilFinished) {
  117. // TODO Auto-generated method stub
  118. btn_get_code.setText(millisUntilFinished / 1000 + "s");
  119. }
  120. @Override
  121. public void onFinish() {
  122. // TODO Auto-generated method stub
  123. btn_get_code.setEnabled(true);
  124. btn_get_code.setText(ResourceUtil.getStringId(getActivity(), "qj_get_phone_code"));
  125. }
  126. }
  127. public interface ResetPwdCallback {
  128. void onResetSuccess(String msg);
  129. void onResetFailed(String msg);
  130. }
  131. private void resetPwdWithPhone(final Activity activity, final String phone, String code, final String pwd) {
  132. NetRequestApi.resetPwdWithPhone(activity, phone, code, pwd, new ResetPwdCallback() {
  133. @Override
  134. public void onResetSuccess(String msg) {
  135. SharedPreferences sp = getActivity()
  136. .getSharedPreferences("yyrh",
  137. Activity.MODE_PRIVATE);
  138. SharedPreferences.Editor editor = sp.edit();
  139. editor.putString("username", phone);
  140. editor.putString("password", pwd);
  141. editor.putString("login_token", "");
  142. editor.commit();
  143. String timeStamp = System.currentTimeMillis() + "";
  144. String delete_sql = "delete from user where name = '" + phone + "'";
  145. String insert_sql = "insert into user(name,pwd,login_token,time) values('" + phone
  146. + "','" + pwd + "','" + "" + "','" + timeStamp + "')";
  147. DatabaseHelper.excuteSql(getActivity(), delete_sql);
  148. DatabaseHelper.excuteSql(getActivity(), insert_sql);
  149. new TosUtil(getActivity(),TosUtil.TOAST_GREEN, msg).show();
  150. Fragment accountLoginFragment = FragmentUtils.getSdkFragment(getActivity(),FragmentUtils.SDK_LOGIN_TAG);
  151. replaceFragmentToActivity(getFragmentManager(),accountLoginFragment,ResourceUtil.getId(getActivity(),"qj_content"));
  152. }
  153. @Override
  154. public void onResetFailed(String msg) {
  155. new TosUtil(getActivity(),TosUtil.TOAST_ERROR, msg).show();
  156. }
  157. });
  158. }
  159. }