Blame view

app/src/main/java/com/dinhcv/lifelogpedometer/activity/InputConfirmCodeActivity.java 4.39 KB
7f095a929   chudinhbka@gmail.com   Create GIT Project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  package com.dinhcv.lifelogpedometer.activity;
  
  import android.app.AlertDialog;
  import android.app.ProgressDialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.WindowManager;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.dinhcv.lifelogpedometer.R;
  import com.dinhcv.lifelogpedometer.interfaces.LLAPIManagerListener;
  import com.dinhcv.lifelogpedometer.model.Shareprefer.Setting;
5520a4b27   Dinh Chu   update
16
  import com.dinhcv.lifelogpedometer.portal.ApiServices;
7f095a929   chudinhbka@gmail.com   Create GIT Project
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  import com.dinhcv.lifelogpedometer.portal.LLAPIManager;
  import com.dinhcv.lifelogpedometer.utils.Const;
  import com.dinhcv.lifelogpedometer.utils.Debug;
  
  import org.json.JSONObject;
  
  import butterknife.BindView;
  import butterknife.ButterKnife;
  import butterknife.OnClick;
  
  public class InputConfirmCodeActivity extends ActivityBase {
  
      @BindView(R.id.edt_confirmCode)
      TextView edtConfirmCode;
      @BindView(R.id.btn_confirm)
      Button btnConfirm;
  
      private ProgressDialog progressDialog;
      private String mEmail;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_input_confirm_code);
          ButterKnife.bind(this);
          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
          Intent intent = getIntent();
          if (intent != null) {
              mEmail = intent.getStringExtra(Const.EMAIL);
              Debug.normal("Email request: "+mEmail);
              if(mEmail == null){
                  Debug.error("Email is null");
                  return;
              }
          }else {
              Debug.error("Email is null");
              return;
          }
  
      }
  
      private void handleGetNewPass(String code){
          progressDialog = new ProgressDialog(InputConfirmCodeActivity.this);
          progressDialog.setMessage(getResources().getString(R.string.waite_some_minute));
          progressDialog.setCancelable(false);
          progressDialog.show();
5520a4b27   Dinh Chu   update
63
          ApiServices.forgetPassConfirm(mEmail, code, new LLAPIManagerListener() {
7f095a929   chudinhbka@gmail.com   Create GIT Project
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
              @Override
              public void onError(Error error) {
                  progressDialog.dismiss();
                  Debug.error("Send confirm JSON result: ERROR " + error);
                  String err = getResources().getString(R.string.request_pass_error);
                  notifyErr(err);
              }
  
              @Override
              public void onSuccess(String json) {
                  Debug.warn("Send confirm JSON result: " + json.toString());
                  progressDialog.dismiss();
  
                  confirmDone();
              }
  
              @Override
              public void onSuccess(JSONObject object) {
                  Debug.warn("Send confirm JSON object result: Success");
                  progressDialog.dismiss();
              }
          });
      }
  
      private void confirmDone(){
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this);
          alertDialog.setMessage(getResources().getString(R.string.password_have_send));
          alertDialog.setCancelable(false);
          alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
          });
          alertDialog.show();
      }
  
      private void notifyErr(String err) {
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(InputConfirmCodeActivity.this);
          alertDialog.setMessage(err);
          alertDialog.setCancelable(false);
          alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
          });
          alertDialog.show();
      }
  
      @OnClick({R.id.btn_confirm})
      public void onClick(View v) {
          switch (v.getId()) {
              case R.id.btn_confirm:
                  // handle login
                  String code = edtConfirmCode.getText().toString();
                  if (code.isEmpty()){
                      showAlerDialog(InputConfirmCodeActivity.this, getResources().getString(R.string.please_input_confirm));
                      return;
                  }
  
                  handleGetNewPass(code);
                  break;
  
              default:
                  break;
          }
      }
  }