Advertisement
minafaw3

leaynik Singup

Oct 4th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. package com.imaadv.leaynik.Activities;
  2.  
  3.  
  4. import com.android.volley.Response;
  5. import com.android.volley.VolleyError;
  6. import com.android.volley.toolbox.JsonObjectRequest;
  7. import com.imaadv.leaynik.R;
  8. import com.imaadv.leaynik.api.API;
  9. import com.imaadv.leaynik.api.ConnectionExector;
  10. import com.imaadv.leaynik.api.ConnectionExector.ResponseType;
  11. import com.imaadv.leaynik.api.ConnectionExector.onHttpRequestListener;
  12.  
  13. import android.annotation.TargetApi;
  14. import android.app.AlertDialog;
  15. import android.app.ProgressDialog;
  16. import android.content.DialogInterface;
  17. import android.content.Intent;
  18. import android.os.Build;
  19. import android.os.Bundle;
  20. import android.support.v7.app.AppCompatActivity;
  21. import android.view.View;
  22. import android.widget.Button;
  23. import android.widget.EditText;
  24. import android.widget.Toast;
  25.  
  26. import com.imaadv.leaynik.api.JsonParsing;
  27. import com.imaadv.leaynik.api.MySingleton;
  28. import com.imaadv.leaynik.defs.AppConstants;
  29. import com.imaadv.leaynik.defs.userdata;
  30.  
  31. import org.json.JSONException;
  32. import org.json.JSONObject;
  33.  
  34. import java.util.HashMap;
  35. import java.util.Map;
  36.  
  37. import butterknife.Bind;
  38. import butterknife.ButterKnife;
  39. import butterknife.OnClick;
  40.  
  41. public class Signup extends AppCompatActivity {
  42.  
  43. @Bind(R.id.username_up)
  44. EditText et_username;
  45.  
  46. @Bind(R.id.pass_up)
  47. EditText et_password;
  48.  
  49. @Bind(R.id.email_up)
  50. EditText et_email;
  51.  
  52. @Bind(R.id.cpass_up)
  53. EditText et_con_pass;
  54.  
  55. @Bind(R.id.signup_iner)
  56. Button btn_Signup;
  57.  
  58. private API api;
  59. private ProgressDialog progressD;
  60.  
  61. @Override
  62. protected void onCreate(Bundle savedInstanceState) {
  63. // TODO Auto-generated method stub
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.signup);
  66. ButterKnife.bind(this);
  67.  
  68. api = new API(this);
  69. init();
  70.  
  71.  
  72. }
  73.  
  74. private void init() {
  75. progressD = new ProgressDialog(this);
  76. progressD.setMessage(getResources().getString(R.string.loading));
  77. progressD.setCancelable(false);
  78. progressD.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  79.  
  80.  
  81. }
  82.  
  83. @OnClick(R.id.signup_iner)
  84. public void sumnitSingup(View view) {
  85. CheckEmpty();
  86. }
  87.  
  88.  
  89. @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  90. private void CheckEmpty() {
  91. boolean empty = false;
  92. API api = new API(Signup.this);
  93. boolean isVaild = false;
  94.  
  95. String sUserName = et_username.getText().toString();
  96. String sEmail = et_email.getText().toString();
  97. String sPassword = et_password.getText().toString();
  98. String sConPassword = et_con_pass.getText().toString();
  99.  
  100. if (sUserName.isEmpty() || sEmail.isEmpty() || sPassword.isEmpty() || sConPassword.isEmpty()) {
  101. empty = true;
  102. }
  103.  
  104. if (empty) {
  105. ShowAlert(getResources().getString(R.string.enterempty));
  106. } else {
  107. if (!api.isValidEmail(sEmail)
  108. || !sConPassword.equals(sPassword)) {
  109. if (!api.isValidEmail(sEmail)) {
  110. ShowAlert(getResources().getString(R.string.invaildemail));
  111. }
  112. if (!sConPassword.equals(sPassword)) {
  113. ShowAlert(getResources()
  114. .getString(R.string.invaildpassword));
  115.  
  116. }
  117. } else {
  118.  
  119. userdata user = new userdata();
  120. user.username = sUserName;
  121. user.password = sPassword;
  122. user.email = sEmail;
  123. user.regID = api.getSetting("regid");
  124.  
  125. progressD.show();
  126. if (api.isNetworkConnected()) {
  127. //api.SignUp(user, onSigningUp);
  128. Register_user(user);
  129.  
  130. } else {
  131. Toast.makeText(Signup.this,
  132. getResources().getString(R.string.nointernet),
  133. Toast.LENGTH_LONG).show();
  134. }
  135.  
  136. // Check if regid already presents
  137.  
  138. }
  139. }
  140.  
  141. }
  142.  
  143.  
  144. private void ShowAlert(String message) {
  145. final AlertDialog.Builder builder = new AlertDialog.Builder(this);
  146.  
  147. //final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
  148. builder.setTitle(R.string.warning);
  149. builder.setMessage(message);
  150. builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
  151. public void onClick(DialogInterface dialog, int which) {
  152.  
  153. }
  154. });
  155. builder.setIcon(R.drawable.ic_launcher);
  156. builder.show();
  157.  
  158. AlertDialog alert = builder.create();
  159.  
  160. }
  161.  
  162.  
  163. onHttpRequestListener onSigningUp = new onHttpRequestListener() {
  164.  
  165. @Override
  166. public void onHttpResult(
  167. ConnectionExector.HTTPResponse response,
  168. String senddata) {
  169. API api = new API(Signup.this);
  170. progressD.hide();
  171. if (response.response == ResponseType.SUCESS) {
  172. startActivity(new Intent(Signup.this, LoginActivity.class));
  173. api.setSetting("zft", "zft");
  174. finish();
  175.  
  176. } else {
  177.  
  178. Toast.makeText(Signup.this, response.value, Toast.LENGTH_LONG).show();
  179. }
  180.  
  181. }
  182. };
  183.  
  184.  
  185. private void Register_user(userdata user) {
  186. final JsonParsing jsonParser = new JsonParsing();
  187. Map<String, String> params = new HashMap<>();
  188. params.put(AppConstants.TAG_username, user.username);
  189. params.put(AppConstants.TAG_userpassword, user.password);
  190. params.put(AppConstants.TAG_useremail, user.email);
  191.  
  192. String URL = AppConstants.GeneralURL + AppConstants.ACTION + AppConstants.SINGUP;
  193.  
  194. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(URL, new JSONObject(params),
  195. new Response.Listener<JSONObject>() {
  196. @Override
  197. public void onResponse(JSONObject response) {
  198. progressD.hide();
  199. try {
  200. String res = response.getString(AppConstants.RESULT);
  201.  
  202. if (res.equals(AppConstants.FALSE)) {
  203. String error = (String) response.get(AppConstants.MESSAGE);
  204. Toast.makeText(Signup.this, error, Toast.LENGTH_LONG).show();
  205. } else if (res.equals(AppConstants.TRUE)) {
  206. Intent intent = new Intent(Signup.this, LoginActivity.class);
  207. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  208. startActivity(intent);
  209. finish();
  210.  
  211. }
  212.  
  213.  
  214. } catch (JSONException e) {
  215. e.printStackTrace();
  216. }
  217. }
  218. }, new Response.ErrorListener() {
  219.  
  220. @Override
  221. public void onErrorResponse(VolleyError error) {
  222. progressD.hide();
  223. // handle error
  224. }
  225. });
  226.  
  227. MySingleton.getInstance(this.getApplicationContext()).getResquestQueue().add(jsonObjectRequest);
  228.  
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement