导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - CreateNewAccount.java 源代码

正在查看: Clash Legends v0.0.1 应用的 CreateNewAccount.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.clash.legends.ui.activities;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Base64;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.clash.legends.models.CurrentUser;
import com.clash.legends.utils.LoadingDialog;
import com.clash.legends.utils.LocaleHelper;
import com.clash.legends.utils.UserLocalStore;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.firebase.messaging.FirebaseMessaging;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class CreateNewAccount extends AppCompatActivity {
    EditText confirmPasswordEt;
    Context context;
    TextView countrycodespinner;
    EditText emailEt;
    EditText firstNameEt;
    EditText lastNameEt;
    LoadingDialog loadingDialog;
    FirebaseAuth mAuth;
    PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback;
    RequestQueue mQueue;
    EditText mobileEt;
    EditText passwordEt;
    EditText promoCodeEt;
    Button registerNewAccount;
    TextView registertitle;
    Resources resources;
    TextView signIn;
    List<String> spinnerArray;
    List<String> spinnerArrayCountryCode;
    EditText userNameEt;
    String firstName = "";
    String lastName = "";
    String userName = "";
    String email = "";
    String mobileNumber = "";
    String password = "";
    String confirmPasssword = "";
    String promoCode = "";
    String countryCode = "";
    String fireabasetoken = "";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(2131558442);
        FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() {
            public final void onComplete(Task task) {
                CreateNewAccount.this.m16xa7b288c3(task);
            }
        });
        FirebaseMessaging.getInstance().subscribeToTopic("all").addOnCompleteListener(new OnCompleteListener<Void>() {
            public void onComplete(Task<Void> task) {
                if (!task.isSuccessful()) {
                }
            }
        });
        Context locale = LocaleHelper.setLocale(this);
        this.context = locale;
        this.resources = locale.getResources();
        this.mAuth = FirebaseAuth.getInstance();
        this.loadingDialog = new LoadingDialog(this);
        this.firstNameEt = (EditText) findViewById(2131363144);
        this.lastNameEt = (EditText) findViewById(2131363145);
        this.userNameEt = (EditText) findViewById(2131363149);
        this.emailEt = (EditText) findViewById(2131363143);
        this.mobileEt = (EditText) findViewById(2131363146);
        this.passwordEt = (EditText) findViewById(2131363147);
        this.promoCodeEt = (EditText) findViewById(2131363148);
        this.confirmPasswordEt = (EditText) findViewById(2131363142);
        this.registerNewAccount = (Button) findViewById(2131363154);
        this.registertitle = (TextView) findViewById(2131363155);
        TextView textView = (TextView) findViewById(2131362192);
        this.countrycodespinner = textView;
        textView.setHint(this.resources.getString(2131886347));
        this.registerNewAccount.setText(this.resources.getString(2131886108));
        this.spinnerArray = new ArrayList();
        this.spinnerArrayCountryCode = new ArrayList();
        this.countrycodespinner.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CreateNewAccount.this.m18x7caf7b20(view);
            }
        });
        viewallcountry();
        RequestQueue newRequestQueue = Volley.newRequestQueue(getApplicationContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        this.userNameEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                charSequence.length();
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        this.promoCodeEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.length() <= 0) {
                    CreateNewAccount.this.registerNewAccount.setEnabled(true);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        TextView textView2 = (TextView) findViewById(2131363344);
        this.signIn = textView2;
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CreateNewAccount.this.m19x6e59213f(view);
            }
        });
        this.registerNewAccount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CreateNewAccount createNewAccount = CreateNewAccount.this;
                createNewAccount.firstName = createNewAccount.firstNameEt.getText().toString().trim();
                CreateNewAccount createNewAccount2 = CreateNewAccount.this;
                createNewAccount2.lastName = createNewAccount2.lastNameEt.getText().toString().trim();
                CreateNewAccount createNewAccount3 = CreateNewAccount.this;
                createNewAccount3.userName = createNewAccount3.userNameEt.getText().toString().trim();
                CreateNewAccount createNewAccount4 = CreateNewAccount.this;
                createNewAccount4.email = createNewAccount4.emailEt.getText().toString().trim();
                CreateNewAccount createNewAccount5 = CreateNewAccount.this;
                createNewAccount5.mobileNumber = createNewAccount5.mobileEt.getText().toString().trim();
                CreateNewAccount createNewAccount6 = CreateNewAccount.this;
                createNewAccount6.password = createNewAccount6.passwordEt.getText().toString().trim();
                CreateNewAccount createNewAccount7 = CreateNewAccount.this;
                createNewAccount7.confirmPasssword = createNewAccount7.passwordEt.getText().toString().trim();
                CreateNewAccount createNewAccount8 = CreateNewAccount.this;
                createNewAccount8.promoCode = createNewAccount8.promoCodeEt.getText().toString().trim();
                if (TextUtils.isEmpty(CreateNewAccount.this.firstName)) {
                    CreateNewAccount.this.firstNameEt.setError("First name required...");
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.lastName)) {
                    CreateNewAccount.this.lastNameEt.setError("Last name required...");
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.userName)) {
                    CreateNewAccount.this.userNameEt.setError(CreateNewAccount.this.resources.getString(2131887060));
                    return;
                }
                if (CreateNewAccount.this.userName.contains(" ")) {
                    CreateNewAccount.this.userNameEt.setError(CreateNewAccount.this.resources.getString(2131886637));
                    return;
                }
                if (TextUtils.equals(CreateNewAccount.this.countryCode.trim(), "")) {
                    Toast.makeText(CreateNewAccount.this.getApplicationContext(), CreateNewAccount.this.resources.getString(2131886912), 0).show();
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.mobileNumber)) {
                    CreateNewAccount.this.mobileEt.setError(CreateNewAccount.this.resources.getString(2131886568));
                    return;
                }
                if (CreateNewAccount.this.mobileNumber.length() < 7 || CreateNewAccount.this.mobileNumber.length() > 15) {
                    CreateNewAccount.this.mobileEt.setError(CreateNewAccount.this.resources.getString(2131887095));
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.email)) {
                    CreateNewAccount.this.emailEt.setError(CreateNewAccount.this.resources.getString(2131886429));
                    return;
                }
                if (!Patterns.EMAIL_ADDRESS.matcher(CreateNewAccount.this.email).matches()) {
                    CreateNewAccount.this.emailEt.setError(CreateNewAccount.this.resources.getString(2131887094));
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.password)) {
                    CreateNewAccount.this.passwordEt.setError(CreateNewAccount.this.resources.getString(2131886668));
                    return;
                }
                if (TextUtils.isEmpty(CreateNewAccount.this.confirmPasssword)) {
                    CreateNewAccount.this.confirmPasswordEt.setError(CreateNewAccount.this.resources.getString(2131886965));
                    return;
                }
                if (!TextUtils.equals(CreateNewAccount.this.password, CreateNewAccount.this.confirmPasssword)) {
                    CreateNewAccount.this.confirmPasswordEt.setError(CreateNewAccount.this.resources.getString(2131886667));
                    return;
                }
                SharedPreferences sp = CreateNewAccount.this.getSharedPreferences("SMINFO", 0);
                if (TextUtils.equals(sp.getString("otp", "no"), "no")) {
                    CreateNewAccount createNewAccount9 = CreateNewAccount.this;
                    createNewAccount9.registeruser(createNewAccount9.firstName, CreateNewAccount.this.lastName, CreateNewAccount.this.promoCode, CreateNewAccount.this.userName, CreateNewAccount.this.mobileNumber, CreateNewAccount.this.email, CreateNewAccount.this.password, CreateNewAccount.this.confirmPasssword, "register");
                } else {
                    CreateNewAccount.this.mCallback = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                            CreateNewAccount.this.signInWithPhoneAuthCredential(phoneAuthCredential);
                        }

                        public void onVerificationFailed(FirebaseException e) {
                            e.printStackTrace();
                            Log.d("failed", e.getMessage());
                            CreateNewAccount.this.loadingDialog.dismiss();
                            Toast.makeText((Context) CreateNewAccount.this, (CharSequence) "Something went wrong, Please try again", 0).show();
                        }

                        public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                            super.onCodeSent(s, forceResendingToken);
                            Toast.makeText(CreateNewAccount.this.getApplicationContext(), CreateNewAccount.this.resources.getString(2131886663), 0).show();
                            CreateNewAccount.this.loadingDialog.dismiss();
                            Intent intent = new Intent(CreateNewAccount.this.getApplicationContext(), (Class<?>) OtpVerifyActivity.class);
                            intent.putExtra("FIRST_NAME", CreateNewAccount.this.firstName);
                            intent.putExtra("LAST_NAME", CreateNewAccount.this.lastName);
                            intent.putExtra("USER_NAME", CreateNewAccount.this.userName);
                            intent.putExtra("MOBILE_NO", CreateNewAccount.this.mobileNumber);
                            intent.putExtra("EMAIL_ID", CreateNewAccount.this.email);
                            intent.putExtra("PASS", CreateNewAccount.this.password);
                            intent.putExtra("CPASS", CreateNewAccount.this.confirmPasssword);
                            intent.putExtra("PROMO_CODE", CreateNewAccount.this.promoCode);
                            intent.putExtra("API_OTP", s);
                            intent.putExtra("COUNTRY_CODE", CreateNewAccount.this.countryCode);
                            CreateNewAccount.this.startActivity(intent);
                        }
                    };
                    CreateNewAccount createNewAccount10 = CreateNewAccount.this;
                    createNewAccount10.sendotp(createNewAccount10.promoCode, CreateNewAccount.this.userName, CreateNewAccount.this.mobileNumber, CreateNewAccount.this.email, CreateNewAccount.this.password, CreateNewAccount.this.confirmPasssword, "register");
                }
            }
        });
    }

    void m16xa7b288c3(Task task) {
        if (!task.isSuccessful()) {
            Log.d("FIREBASE TOKEN EXCEPTION", "ERROR");
        } else {
            Log.d("FIREBASE TOKEN", "LENGTH" + ((String) task.getResult()).length() + " : " + ((String) task.getResult()));
            this.fireabasetoken = (String) task.getResult();
        }
    }

    void m18x7caf7b20(View v) {
        final Dialog builder = new Dialog(this);
        builder.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        builder.setCancelable(false);
        WindowManager.LayoutParams wlmp = builder.getWindow().getAttributes();
        builder.getWindow().setAttributes(wlmp);
        builder.setContentView(2131558785);
        ImageView cancel = (ImageView) builder.findViewById(2131363369);
        LinearLayout ll = (LinearLayout) builder.findViewById(2131363371);
        for (int i = 0; i < this.spinnerArray.size(); i++) {
            LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(-1, -2);
            View view = getLayoutInflater().inflate(2131558784, (ViewGroup) null);
            view.setLayoutParams(lparams);
            TextView tv = (TextView) view.findViewById(2131363558);
            tv.setText(this.spinnerArrayCountryCode.get(i) + " (" + this.spinnerArray.get(i) + ")");
            final int finalI = i;
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view2) {
                    CreateNewAccount.this.m17x995c2ee2(finalI, builder, view2);
                }
            });
            ll.addView(view);
        }
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                builder.dismiss();
            }
        });
        builder.create();
        builder.show();
    }

    void m17x995c2ee2(int finalI, Dialog builder, View v12) {
        this.countrycodespinner.setText(this.spinnerArrayCountryCode.get(finalI));
        this.countryCode = this.spinnerArrayCountryCode.get(finalI);
        builder.dismiss();
    }

    void m19x6e59213f(View view) {
        startActivity(new Intent(getApplicationContext(), (Class<?>) MainActivity.class));
    }

    public void sendotp(String promoCode, String userNameEt, final String mobile_no, String emailId, String password, String cpassword, String submit) {
        this.loadingDialog.show();
        RequestQueue newRequestQueue = Volley.newRequestQueue(getApplicationContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String URL = this.resources.getString(2131886167) + "checkMember";
        HashMap<String, String> params = new HashMap<>();
        params.put("promo_code", promoCode);
        params.put("user_name", userNameEt);
        params.put("mobile_no", mobile_no);
        params.put("country_code", this.countryCode);
        params.put("email_id", emailId);
        params.put("password", password);
        params.put("cpassword", cpassword);
        params.put("submit", submit);
        Log.d(URL, new JSONObject(params).toString());
        JsonObjectRequest request_json = new JsonObjectRequest(1, URL, new JSONObject(params), new Response.Listener() {
            public final void onResponse(Object obj) {
                CreateNewAccount.this.m22xfc4311d0(mobile_no, (JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                CreateNewAccount.lambda$sendotp$6(volleyError);
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                headers.put("x-localization", LocaleHelper.getPersist(CreateNewAccount.this.context));
                return headers;
            }
        };
        request_json.setShouldCache(false);
        this.mQueue.add(request_json);
    }

    void m22xfc4311d0(String mobile_no, JSONObject response) {
        Log.d("send otp", response.toString());
        try {
            String status = response.getString("status");
            if (TextUtils.equals(status, "true")) {
                Toast.makeText(getApplicationContext(), this.resources.getString(2131886663), 0).show();
                PhoneAuthOptions options = PhoneAuthOptions.newBuilder(this.mAuth).setPhoneNumber(this.countryCode + mobile_no).setTimeout(60L, TimeUnit.SECONDS).setActivity(this).setCallbacks(this.mCallback).build();
                PhoneAuthProvider.verifyPhoneNumber(options);
            } else {
                this.loadingDialog.dismiss();
                Toast.makeText(getApplicationContext(), response.getString("message"), 0).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    static void lambda$sendotp$6(VolleyError error) {
        VolleyLog.e("Error: ", new Object[]{error.getMessage()});
        NetworkResponse response = error.networkResponse;
        if (response != null && response.data != null) {
            String errorString = new String(response.data);
            Log.d("erorostring ", errorString);
        }
    }

    public void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        this.mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener() {
            public final void onComplete(Task task) {
                CreateNewAccount.this.m23x8555a94c(task);
            }
        });
    }

    void m23x8555a94c(Task task) {
        if (task.isSuccessful()) {
            Log.d("TAG", "signInWithCredential:success");
            registeruser(this.firstName, this.lastName, this.promoCode, this.userName, this.mobileNumber, this.email, this.password, this.confirmPasssword, "register");
        } else {
            Log.w("TAG", "signInWithCredential:failure", task.getException());
            Toast.makeText(getApplicationContext(), this.resources.getString(2131886449), 0).show();
            boolean z = task.getException() instanceof FirebaseAuthInvalidCredentialsException;
        }
    }

    public void registeruser(final String firstName, final String lastName, String promoCode, final String userNameEt, final String mobile_no, final String emailId, final String password, String cPassword, String submit) {
        this.loadingDialog.show();
        String URL = this.resources.getString(2131886167) + "registrationAcc";
        HashMap<String, String> params = new HashMap<>();
        params.put("promo_code", promoCode);
        params.put("first_name", firstName);
        params.put("last_name", lastName);
        params.put("user_name", userNameEt);
        params.put("mobile_no", mobile_no);
        params.put("email_id", emailId);
        params.put("player_id", this.fireabasetoken);
        params.put("password", password);
        params.put("cpassword", cPassword);
        params.put("country_code", this.countryCode);
        params.put("submit", submit);
        Log.d(URL, new JSONObject(params).toString());
        JsonObjectRequest request_json = new JsonObjectRequest(URL, new JSONObject(params), new Response.Listener() {
            public final void onResponse(Object obj) {
                CreateNewAccount.this.m20xd5203828(userNameEt, password, emailId, mobile_no, firstName, lastName, (JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                CreateNewAccount.this.m21xc6c9de47(volleyError);
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                headers.put("x-localization", LocaleHelper.getPersist(CreateNewAccount.this.context));
                return headers;
            }
        };
        request_json.setShouldCache(false);
        this.mQueue.add(request_json);
    }

    void m20xd5203828(String userNameEt, String password, String emailId, String mobile_no, String firstName, String lastName, JSONObject response) {
        Log.d("create", response.toString());
        try {
            String status = response.getString("status");
            String message = response.getString("message");
            if (TextUtils.equals(status, "true")) {
                String token = response.getString("api_token");
                String member_id = response.getString("member_id");
                CurrentUser cUser = new CurrentUser(member_id, userNameEt, password, emailId, mobile_no, token, firstName, lastName);
                UserLocalStore userLocalStore = new UserLocalStore(getApplicationContext());
                userLocalStore.storeUserData(cUser);
                this.loadingDialog.dismiss();
                Toast.makeText((Context) this, (CharSequence) this.resources.getString(2131886953), 0).show();
                startActivity(new Intent(getApplicationContext(), (Class<?>) HomeActivity.class));
            } else {
                this.mAuth.signOut();
                this.loadingDialog.dismiss();
                Toast.makeText((Context) this, (CharSequence) message, 0).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    void m21xc6c9de47(VolleyError error) {
        this.mAuth.signOut();
        VolleyLog.e("Error: ", new Object[]{error.getMessage()});
    }

    public void viewallcountry() {
        RequestQueue newRequestQueue = Volley.newRequestQueue(getApplicationContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String url = this.resources.getString(2131886167) + "all_country";
        final UserLocalStore userLocalStore = new UserLocalStore(getApplicationContext());
        JsonObjectRequest request = new JsonObjectRequest(0, url, null, new Response.Listener() {
            public final void onResponse(Object obj) {
                CreateNewAccount.this.m24x4cb0a41b((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                Log.e("**VolleyError", "error" + volleyError.getMessage());
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = userLocalStore.getLoggedInUser();
                String credentials = user.getUsername() + ":" + user.getPassword();
                String auth = "Basic " + Base64.encodeToString(credentials.getBytes(), 2);
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", auth);
                headers.put("x-localization", LocaleHelper.getPersist(CreateNewAccount.this.context));
                return headers;
            }
        };
        request.setShouldCache(false);
        this.mQueue.add(request);
    }

    void m24x4cb0a41b(JSONObject response) {
        this.loadingDialog.dismiss();
        try {
            JSONArray arr = response.getJSONArray("all_country");
            TextUtils.equals(response.getString("all_country"), "[]");
            JSON_PARSE_DATA_AFTER_WEBCALL(arr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        this.loadingDialog.dismiss();
    }

    public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
        for (int i = 0; i < array.length(); i++) {
            try {
                JSONObject json = array.getJSONObject(i);
                this.spinnerArray.add(json.getString("country_name"));
                this.spinnerArrayCountryCode.add(json.getString("p_code"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}