Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.imaadv.leaynik.Activities;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.JsonObjectRequest;
- import com.imaadv.leaynik.R;
- import com.imaadv.leaynik.api.API;
- import com.imaadv.leaynik.api.ConnectionExector;
- import com.imaadv.leaynik.api.ConnectionExector.ResponseType;
- import com.imaadv.leaynik.api.ConnectionExector.onHttpRequestListener;
- import android.annotation.TargetApi;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.os.Build;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.imaadv.leaynik.api.JsonParsing;
- import com.imaadv.leaynik.api.MySingleton;
- import com.imaadv.leaynik.defs.AppConstants;
- import com.imaadv.leaynik.defs.userdata;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- import java.util.Map;
- import butterknife.Bind;
- import butterknife.ButterKnife;
- import butterknife.OnClick;
- public class Signup extends AppCompatActivity {
- @Bind(R.id.username_up)
- EditText et_username;
- @Bind(R.id.pass_up)
- EditText et_password;
- @Bind(R.id.email_up)
- EditText et_email;
- @Bind(R.id.cpass_up)
- EditText et_con_pass;
- @Bind(R.id.signup_iner)
- Button btn_Signup;
- private API api;
- private ProgressDialog progressD;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.signup);
- ButterKnife.bind(this);
- api = new API(this);
- init();
- }
- private void init() {
- progressD = new ProgressDialog(this);
- progressD.setMessage(getResources().getString(R.string.loading));
- progressD.setCancelable(false);
- progressD.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- }
- @OnClick(R.id.signup_iner)
- public void sumnitSingup(View view) {
- CheckEmpty();
- }
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- private void CheckEmpty() {
- boolean empty = false;
- API api = new API(Signup.this);
- boolean isVaild = false;
- String sUserName = et_username.getText().toString();
- String sEmail = et_email.getText().toString();
- String sPassword = et_password.getText().toString();
- String sConPassword = et_con_pass.getText().toString();
- if (sUserName.isEmpty() || sEmail.isEmpty() || sPassword.isEmpty() || sConPassword.isEmpty()) {
- empty = true;
- }
- if (empty) {
- ShowAlert(getResources().getString(R.string.enterempty));
- } else {
- if (!api.isValidEmail(sEmail)
- || !sConPassword.equals(sPassword)) {
- if (!api.isValidEmail(sEmail)) {
- ShowAlert(getResources().getString(R.string.invaildemail));
- }
- if (!sConPassword.equals(sPassword)) {
- ShowAlert(getResources()
- .getString(R.string.invaildpassword));
- }
- } else {
- userdata user = new userdata();
- user.username = sUserName;
- user.password = sPassword;
- user.email = sEmail;
- user.regID = api.getSetting("regid");
- progressD.show();
- if (api.isNetworkConnected()) {
- //api.SignUp(user, onSigningUp);
- Register_user(user);
- } else {
- Toast.makeText(Signup.this,
- getResources().getString(R.string.nointernet),
- Toast.LENGTH_LONG).show();
- }
- // Check if regid already presents
- }
- }
- }
- private void ShowAlert(String message) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
- //final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
- builder.setTitle(R.string.warning);
- builder.setMessage(message);
- builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- builder.setIcon(R.drawable.ic_launcher);
- builder.show();
- AlertDialog alert = builder.create();
- }
- onHttpRequestListener onSigningUp = new onHttpRequestListener() {
- @Override
- public void onHttpResult(
- ConnectionExector.HTTPResponse response,
- String senddata) {
- API api = new API(Signup.this);
- progressD.hide();
- if (response.response == ResponseType.SUCESS) {
- startActivity(new Intent(Signup.this, LoginActivity.class));
- api.setSetting("zft", "zft");
- finish();
- } else {
- Toast.makeText(Signup.this, response.value, Toast.LENGTH_LONG).show();
- }
- }
- };
- private void Register_user(userdata user) {
- final JsonParsing jsonParser = new JsonParsing();
- Map<String, String> params = new HashMap<>();
- params.put(AppConstants.TAG_username, user.username);
- params.put(AppConstants.TAG_userpassword, user.password);
- params.put(AppConstants.TAG_useremail, user.email);
- String URL = AppConstants.GeneralURL + AppConstants.ACTION + AppConstants.SINGUP;
- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(URL, new JSONObject(params),
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- progressD.hide();
- try {
- String res = response.getString(AppConstants.RESULT);
- if (res.equals(AppConstants.FALSE)) {
- String error = (String) response.get(AppConstants.MESSAGE);
- Toast.makeText(Signup.this, error, Toast.LENGTH_LONG).show();
- } else if (res.equals(AppConstants.TRUE)) {
- Intent intent = new Intent(Signup.this, LoginActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- finish();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- progressD.hide();
- // handle error
- }
- });
- MySingleton.getInstance(this.getApplicationContext()).getResquestQueue().add(jsonObjectRequest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement