导航菜单

页面标题

页面副标题

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

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

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


package com.clash.legends.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.AuthFailureError;
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 com.mukesh.OnOtpCompletionListener;
import com.mukesh.OtpView;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.json.JSONException;
import org.json.JSONObject;

public class OtpVerifyActivity extends AppCompatActivity {
    String apiOtp;
    Context context;
    String countryCode;
    String cpass;
    String emailId;
    String firebasetoken;
    String firstName;
    String lastName;
    LoadingDialog loadingDialog;
    FirebaseAuth mAuth;
    PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback;
    RequestQueue mQueue;
    String mobileNo;
    OtpView otpView;
    TextView otpnote;
    TextView otpnote2;
    String pass;
    String promoCode;
    TextView resend;
    Resources resources;
    String userName;
    TextView verificationtitle;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(2131558466);
        Context locale = LocaleHelper.setLocale(this);
        this.context = locale;
        this.resources = locale.getResources();
        countdown();
        this.mAuth = FirebaseAuth.getInstance();
        this.loadingDialog = new LoadingDialog(this);
        FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() {
            public final void onComplete(Task task) {
                OtpVerifyActivity.this.m141x5995ffb9(task);
            }
        });
        SharedPreferences sppi = getSharedPreferences("PLAYER_ID", 0);
        SharedPreferences.Editor editor = sppi.edit();
        try {
            editor.putString("player_id", this.firebasetoken);
            editor.apply();
        } catch (Exception e) {
        }
        Intent intent = getIntent();
        this.userName = intent.getStringExtra("USER_NAME");
        this.firstName = intent.getStringExtra("FIRST_NAME");
        this.lastName = intent.getStringExtra("LAST_NAME");
        this.mobileNo = intent.getStringExtra("MOBILE_NO");
        this.emailId = intent.getStringExtra("EMAIL_ID");
        this.pass = intent.getStringExtra("PASS");
        this.cpass = intent.getStringExtra("CPASS");
        this.promoCode = intent.getStringExtra("PROMO_CODE");
        this.apiOtp = intent.getStringExtra("API_OTP");
        this.countryCode = intent.getStringExtra("COUNTRY_CODE");
        this.otpView = findViewById(2131362960);
        this.resend = (TextView) findViewById(2131363160);
        this.verificationtitle = (TextView) findViewById(2131363734);
        this.otpnote = (TextView) findViewById(2131362967);
        TextView textView = (TextView) findViewById(2131362966);
        this.otpnote2 = textView;
        textView.setText(this.resources.getString(2131886662));
        this.otpnote.setText(this.resources.getString(2131886661));
        this.verificationtitle.setText(this.resources.getString(2131887061));
        this.resend.setClickable(false);
        this.resend.setEnabled(false);
        this.resend.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                OtpVerifyActivity.this.m142x9d211d7a(view);
            }
        });
        this.otpView.setShowSoftInputOnFocus(true);
        this.otpView.setOtpCompletionListener(new OnOtpCompletionListener() {
            public final void onOtpCompleted(String str) {
                OtpVerifyActivity.this.m143xe0ac3b3b(str);
            }
        });
        this.mCallback = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
            public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                OtpVerifyActivity.this.signInWithPhoneAuthCredential(phoneAuthCredential);
            }

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

            public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                super.onCodeSent(s, forceResendingToken);
                OtpVerifyActivity.this.loadingDialog.dismiss();
                OtpVerifyActivity.this.countdown();
                OtpVerifyActivity.this.apiOtp = s;
                Toast.makeText(OtpVerifyActivity.this.getApplicationContext(), OtpVerifyActivity.this.resources.getString(2131886663), 0).show();
            }
        };
    }

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

    void m142x9d211d7a(View v) {
        sendotp();
    }

    void m143xe0ac3b3b(String otp) {
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(this.apiOtp, otp);
        signInWithPhoneAuthCredential(credential);
    }

    public void countdown() {
        new CountDownTimer(60000L, 1000L) {
            @Override
            public void onTick(long millisUntilFinished) {
                OtpVerifyActivity.this.resend.setText(String.valueOf(millisUntilFinished / 1000));
            }

            @Override
            public void onFinish() {
                OtpVerifyActivity.this.resend.setText(OtpVerifyActivity.this.resources.getString(2131886954));
                OtpVerifyActivity.this.resend.setClickable(true);
                OtpVerifyActivity.this.resend.setEnabled(true);
            }
        }.start();
    }

    public void sendotp() {
        this.loadingDialog.show();
        PhoneAuthOptions options = PhoneAuthOptions.newBuilder(this.mAuth).setPhoneNumber(this.countryCode + this.mobileNo).setTimeout(60L, TimeUnit.SECONDS).setActivity(this).setCallbacks(this.mCallback).build();
        PhoneAuthProvider.verifyPhoneNumber(options);
        this.resend.setClickable(false);
        this.resend.setEnabled(false);
    }

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

    void m146x222a794c(Task task) {
        if (task.isSuccessful()) {
            Log.d("TAG", "signInWithCredential:success");
            registeruser(this.promoCode, this.userName, this.mobileNo, this.emailId, this.pass, this.cpass, "register");
            return;
        }
        Log.w("TAG", "signInWithCredential:failure", task.getException());
        Toast.makeText(getApplicationContext(), this.resources.getString(2131886449), 0).show();
        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
            Toast.makeText(getApplicationContext(), this.resources.getString(2131887096), 0).show();
            this.otpView.setText("");
        }
    }

    public void registeruser(String promoCode, final String userNameEt, final String mobile_no, final String emailId, final String password, String cPassword, String submit) {
        this.loadingDialog.show();
        this.mQueue = Volley.newRequestQueue(getApplicationContext());
        String URL = this.resources.getString(2131886167) + "registrationAcc";
        HashMap<String, String> params = new HashMap<>();
        params.put("promo_code", promoCode);
        params.put("first_name", this.firstName);
        params.put("last_name", this.lastName);
        params.put("user_name", userNameEt);
        params.put("player_id", this.firebasetoken);
        params.put("mobile_no", mobile_no);
        params.put("email_id", emailId);
        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) {
                OtpVerifyActivity.this.m144xcbb1c5f0(userNameEt, password, emailId, mobile_no, (JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                OtpVerifyActivity.this.m145xf3ce3b1(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(OtpVerifyActivity.this.context));
                return headers;
            }
        };
        request_json.setShouldCache(false);
        this.mQueue.add(request_json);
    }

    void m144xcbb1c5f0(String userNameEt, String password, String emailId, String mobile_no, JSONObject response) {
        Log.d("create", response.toString());
        try {
            String status = response.getString("status");
            String message = response.getString("message");
            String token = response.getString("api_token");
            if (TextUtils.equals(status, "true")) {
                String member_id = response.getString("member_id");
                CurrentUser cUser = new CurrentUser(member_id, userNameEt, password, emailId, mobile_no, token, this.firstName, this.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.loadingDialog.dismiss();
                this.mAuth.signOut();
                Toast.makeText((Context) this, (CharSequence) message, 0).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

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