Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.smartfanssolutions.riotpointsjob1;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v4.app.ActivityCompat;
- import android.util.Log;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import org.json.JSONObject;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Timer;
- import java.util.TimerTask;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import com.smartfanssolutions.riotpointsjob1.app.App;
- import com.smartfanssolutions.riotpointsjob1.common.ActivityBase;
- import com.smartfanssolutions.riotpointsjob1.util.CustomRequest;
- import com.smartfanssolutions.riotpointsjob1.util.Helper;
- public class SignupActivity extends ActivityBase {
- EditText signupUsername, signupFullname, signupPassword, signupEmail, signupReferrer;
- Button signupJoinBtn;
- private String username, fullname, password, email , referrercode ;
- private PrefManager prf;
- private boolean referrerExisting = false, isReferrerCheating=false;
- public Timer AdTimer;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_sign_up);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true);
- signupUsername = (EditText) findViewById(R.id.signupUsername);
- signupFullname = (EditText) findViewById(R.id.signupFullname);
- signupPassword = (EditText) findViewById(R.id.signupPassword);
- signupEmail = (EditText) findViewById(R.id.signupEmail);
- signupReferrer = (EditText) findViewById(R.id.signupReferrer);
- signupJoinBtn = (Button) findViewById(R.id.signupJoinBtn);
- signupJoinBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- username = signupUsername.getText().toString();
- fullname = signupFullname.getText().toString();
- password = signupPassword.getText().toString();
- email = signupEmail.getText().toString();
- referrercode = signupReferrer.getText().toString();
- check_referrer(username,referrercode);
- if (verifyRegForm()) {
- if (App.getInstance().isConnected()) {
- showpDialog();
- CustomRequest jsonReq = new CustomRequest(Request.Method.POST, METHOD_ACCOUNT_SIGNUP, null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- Log.e("Profile", "Malformed JSON: \"" + response.toString() + "\"");
- if (App.getInstance().authorize(response)) {
- Intent i = new Intent(getApplicationContext(), MainActivity.class);
- startActivity(i);
- ActivityCompat.finishAffinity(SignupActivity.this);
- AdTimer = new Timer();
- // Prepare an Interstitial Ad Listener
- // Call displayInterstitial() function with timer
- if (AdTimer != null) {
- AdTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(SignupActivity.this,"setting the referrer",Toast.LENGTH_SHORT).show();
- }
- });
- }
- }, 4000);
- }
- } else {
- switch (App.getInstance().getErrorCode()) {
- case 300 : {
- signupUsername.setError(getString(R.string.error_login_taken));
- break;
- }
- case 301 : {
- signupEmail.setError(getString(R.string.error_email_taken));
- break;
- }
- default: {
- Log.e("Profile", "Could not parse malformed JSON: \"" + response.toString() + "\"");
- break;
- }
- }
- }
- hidepDialog();
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
- Log.e("Profile", "Malformed JSON: \"" + error.getMessage() + "\"");
- hidepDialog();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("username", username);
- params.put("fullname", fullname);
- params.put("password", password);
- params.put("email", email);
- params.put("clientId", CLIENT_ID);
- return params;
- }
- };
- App.getInstance().addToRequestQueue(jsonReq);
- } else {
- Toast.makeText(getApplicationContext(), R.string.msg_network_error, Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- }
- // check the response
- void check_referrer( String referral, String referrer) {
- String awr = Config.Base_Url + "get/checkref.php";
- final String v1 = "1"; // OK
- final String v0 = "0"; // The referrer is not existing
- final String v2 = "2"; // cheating
- StringRequest stringRequest = new StringRequest(Request.Method.POST, awr,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- if (response.intern() == v1.intern()) {
- referrerExisting = true;
- }
- if (response.intern() == v0.intern()) {
- referrerExisting = false;
- }
- if (response.intern() == v2.intern()) {
- isReferrerCheating = true;
- }
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- }
- }) {
- @Override
- protected Map<String,String> getParams(){
- Map<String,String> params = new HashMap<String, String>();
- params.put("user",username);
- params.put("ref", referrercode);
- return params;
- }
- };
- RequestQueue requestQueue = Volley.newRequestQueue(this);
- requestQueue.add(stringRequest);
- }
- public Boolean verifyRegForm() {
- signupUsername.setError(null);
- signupFullname.setError(null);
- signupPassword.setError(null);
- signupEmail.setError(null);
- signupReferrer.setError(null);
- Helper helper = new Helper();
- if (username.length() == 0) {
- signupUsername.setError(getString(R.string.error_field_empty));
- return false;
- }
- if (username.length() < 5) {
- signupUsername.setError(getString(R.string.error_small_username));
- return false;
- }
- if (!helper.isValidLogin(username)) {
- signupUsername.setError(getString(R.string.error_wrong_format));
- return false;
- }
- if (fullname.length() == 0) {
- signupFullname.setError(getString(R.string.error_field_empty));
- return false;
- }
- if (password.length() == 0) {
- signupPassword.setError(getString(R.string.error_field_empty));
- return false;
- }
- if (password.length() < 6) {
- signupPassword.setError(getString(R.string.error_small_password));
- return false;
- }
- if (!helper.isValidPassword(password)) {
- signupPassword.setError(getString(R.string.error_wrong_format));
- return false;
- }
- if (email.length() == 0) {
- signupEmail.setError(getString(R.string.error_field_empty));
- return false;
- }
- if (email.length() == 0) {
- signupEmail.setError(getString(R.string.error_field_empty));
- return false;
- }
- if (email.length() == 0) {
- signupEmail.setError(getString(R.string.error_field_empty));
- return false;
- }
- // verif username == referrer
- if (referrercode.equals(username)) {
- signupReferrer.setError(getString(R.string.error_Referall_signup));
- return false;
- }
- // verif Referrer Existing
- if (referrerExisting==false) {
- signupReferrer.setError(getString(R.string.error_Referall_signup_NotExisting));
- return false;
- }
- // verif user & Referrer cheating
- if (isReferrerCheating == true) {
- signupReferrer.setError(getString(R.string.error_Referall_signup_Cheating));
- return false;
- }
- if (!helper.isValidEmail(email)) {
- signupEmail.setError(getString(R.string.error_wrong_format));
- return false;
- }
- return true;
- }
- @Override
- public void onBackPressed(){
- finish();
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- switch (item.getItemId()) {
- case android.R.id.home: {
- finish();
- return true;
- }
- default: {
- return super.onOptionsItemSelected(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement