导航菜单

页面标题

页面副标题

St.John's v1.0.9 - ChangePasswordActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 ChangePasswordActivity.java JAVA 源代码文件

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


package com.mcb.stjohnsemschool.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.mcb.stjohnsemschool.DB.MyClassBoardDB;
import com.mcb.stjohnsemschool.model.ChangePasswordSettingsModel;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.Constants;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ChangePasswordActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "com.mcb.stjohnsemschool.activity.ChangePasswordActivity";
    private ConnectivityManager conMgr;
    ShowHidePasswordEditText confirmNewPassword_et;
    private String confirmpassword;
    private Context context;
    private MyClassBoardDB db;
    private boolean isValid;
    private TextView mAlertText;
    private Dialog mDialogAlert;
    private TextView mDialogeAlertYes;
    SharedPreferences.Editor mEditor;
    FirebaseAnalytics mFirebaseAnalytics;
    private Typeface mMuseoSlab500;
    private TransparentProgressDialog mProgressbar;
    SharedPreferences mSharedPref;
    private int maxLength;
    private int minLength;
    private AppCompatActivity myActivity;
    ShowHidePasswordEditText newPassword_et;
    private String newpassword;
    ShowHidePasswordEditText oldPassword_et;
    private String oldpassword;
    String passwordStr;
    int primaryColor;
    private String studentEnrollmentId;
    private Button submit;
    private Toolbar toolbar;
    private String userId;
    private EditText userName_et;
    private String username;
    String usernameStr;
    private String passwordComplex = "";
    private String resultStr = "";
    private String response = "Password Changed Successfully. Please Login with your new Password and Password sent to registered email.";
    private int userTypeId = 0;
    private int orgId = 0;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.fragment_change_password);
        this.mFirebaseAnalytics = FirebaseAnalytics.getInstance(getApplicationContext());
        Context applicationContext = getApplicationContext();
        this.context = applicationContext;
        this.myActivity = this;
        SharedPreferences sharedPreferences = applicationContext.getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.mEditor = sharedPreferences.edit();
        this.userId = this.mSharedPref.getString("UseridKey", this.userId);
        getSupportActionBar();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Change Password");
        this.studentEnrollmentId = this.mSharedPref.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        this.userId = this.mSharedPref.getString("UseridKey", this.userId);
        this.orgId = this.mSharedPref.getInt("MainOrganisationId", this.orgId);
        this.userTypeId = this.mSharedPref.getInt("MainUserTypeId", this.userTypeId);
        this.db = new MyClassBoardDB(this.context);
        this.mMuseoSlab500 = Typeface.createFromAsset(this.context.getAssets(), "Roboto-Regular.ttf");
        getProfileData();
        this.mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        setUpIds();
    }

    private void setUpIds() {
        this.userName_et = (EditText) findViewById(R.id.username_et);
        this.oldPassword_et = findViewById(R.id.old_password_et);
        this.newPassword_et = findViewById(R.id.new_password_et);
        this.confirmNewPassword_et = findViewById(R.id.confirm_password_et);
        this.submit = (Button) findViewById(R.id.submit_tv);
        this.userName_et.setText(this.usernameStr);
        this.userName_et.setTypeface(this.mMuseoSlab500);
        this.oldPassword_et.setTypeface(this.mMuseoSlab500);
        this.newPassword_et.setTypeface(this.mMuseoSlab500);
        this.confirmNewPassword_et.setTypeface(this.mMuseoSlab500);
        this.submit.setTypeface(this.mMuseoSlab500);
        this.submit.setOnClickListener(this);
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        Dialog dialog = new Dialog(this, R.style.Theme_Dialog);
        this.mDialogAlert = dialog;
        WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
        attributes.dimAmount = 5.0f;
        this.mDialogAlert.getWindow().setAttributes(attributes);
        this.mDialogAlert.getWindow().addFlags(2);
        this.mDialogAlert.setContentView(R.layout.dialog_alert);
        this.mDialogAlert.setCanceledOnTouchOutside(true);
        this.mAlertText = (TextView) this.mDialogAlert.findViewById(R.id.alert_text);
        TextView textView = (TextView) this.mDialogAlert.findViewById(R.id.ok_alert_dialog);
        this.mDialogeAlertYes = textView;
        textView.setOnClickListener(this);
        getChangePasswordSettings();
    }

    private void getChangePasswordSettings() {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            changePasswordSettings();
        } else {
            Utility.showInfoDialog(this.myActivity, "Please check your internet connection");
        }
    }

    private void changePasswordSettings() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        ((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).GetChangePasswordSettings(this.orgId, this.userTypeId, Utility.getSchoolApiKey(this.context)).enqueue(new Callback<ChangePasswordSettingsModel>() {
            public void onResponse(Call<ChangePasswordSettingsModel> call, Response<ChangePasswordSettingsModel> response) {
                if (ChangePasswordActivity.this.mProgressbar != null && ChangePasswordActivity.this.mProgressbar.isShowing()) {
                    ChangePasswordActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(ChangePasswordActivity.this.myActivity);
                    return;
                }
                ChangePasswordSettingsModel changePasswordSettingsModel = (ChangePasswordSettingsModel) response.body();
                ChangePasswordActivity.this.passwordComplex = changePasswordSettingsModel.getPasswordComplex();
                ChangePasswordActivity.this.minLength = changePasswordSettingsModel.getMinLength();
                ChangePasswordActivity.this.maxLength = changePasswordSettingsModel.getMaxLength();
                if (!ChangePasswordActivity.this.passwordComplex.equalsIgnoreCase("Only Numerics")) {
                    if (ChangePasswordActivity.this.passwordComplex.equalsIgnoreCase("Only Alphabets")) {
                        ChangePasswordActivity.this.newPassword_et.setInputType(17);
                        ChangePasswordActivity.this.confirmNewPassword_et.setInputType(17);
                        return;
                    }
                    return;
                }
                ChangePasswordActivity.this.newPassword_et.setInputType(19);
                ChangePasswordActivity.this.confirmNewPassword_et.setInputType(18);
            }

            public void onFailure(Call<ChangePasswordSettingsModel> call, Throwable th) {
                if (ChangePasswordActivity.this.mProgressbar != null && ChangePasswordActivity.this.mProgressbar.isShowing()) {
                    ChangePasswordActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(ChangePasswordActivity.this.myActivity);
            }
        });
    }

    @Override
    public void onClick(View view) {
        String str;
        String str2;
        String str3;
        String str4;
        if (view == this.submit) {
            try {
                this.username = this.userName_et.getText().toString();
                this.oldpassword = this.oldPassword_et.getText().toString();
                this.newpassword = this.newPassword_et.getText().toString();
                this.confirmpassword = this.confirmNewPassword_et.getText().toString();
                if (this.username.length() <= 0 || (str = this.username) == null || str.equals("") || this.username.equals("null")) {
                    Utility.showInfoDialog(this.myActivity, "Enter Valid Username");
                } else if (this.oldpassword.length() <= 0 || (str2 = this.oldpassword) == null || str2.equals("") || this.oldpassword.equals("null")) {
                    Utility.showInfoDialog(this.myActivity, "Enter Old Password");
                } else if (this.newpassword.length() <= 0 || (str3 = this.newpassword) == null || str3.equals("") || this.newpassword.equals("null")) {
                    Utility.showInfoDialog(this.myActivity, "Enter New Password");
                } else if (this.confirmpassword.length() <= 0 || (str4 = this.confirmpassword) == null || str4.equals("") || this.confirmpassword.equals("null")) {
                    Utility.showInfoDialog(this.myActivity, "Enter Confirm New Password");
                } else if (this.oldpassword.equalsIgnoreCase(this.newpassword)) {
                    Utility.showInfoDialog(this.myActivity, "Old password and new password should not be same.");
                } else if (!this.newpassword.equalsIgnoreCase(this.confirmpassword)) {
                    Utility.showInfoDialog(this.myActivity, "New password and confirm password should be the same.");
                } else if (this.newpassword.length() < this.minLength || this.newpassword.length() > this.maxLength) {
                    Utility.showInfoDialog(this.myActivity, "Your new password must have at least minimum " + this.minLength + " and maximum " + this.maxLength + " characters");
                } else if (this.passwordComplex.equalsIgnoreCase("Only Numerics")) {
                    if (Constants.isValidNumber(this.newpassword)) {
                        loadChangePasswordData();
                    } else {
                        Utility.showInfoDialog(this.myActivity, "Please enter numbers only");
                    }
                } else if (this.passwordComplex.equalsIgnoreCase("Only Alphabets")) {
                    if (Constants.isValidAlphabets(this.newpassword)) {
                        loadChangePasswordData();
                    } else {
                        Utility.showInfoDialog(this.myActivity, "Please enter alphabets only");
                    }
                } else if (!this.passwordComplex.equalsIgnoreCase("Alphabets and Numerics")) {
                    loadChangePasswordData();
                } else if (Constants.isValidNumChar(this.newpassword)) {
                    loadChangePasswordData();
                } else {
                    Utility.showInfoDialog(this.myActivity, "Please enter alphanumeric characters only");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (view == this.mDialogeAlertYes) {
            this.mDialogAlert.dismiss();
            if (this.resultStr.equalsIgnoreCase(this.response)) {
                if (Utility.hasNetworkConnection(this.context)) {
                    Utility.LogoutStudent(this.context);
                }
                this.mEditor.putBoolean("isloggedin", false);
                this.mEditor.commit();
                Intent intent = new Intent(this.context, (Class<?>) LoginActivity.class);
                intent.putExtra("From", "FromSplash");
                intent.addFlags(268468224);
                startActivity(intent);
                finish();
            }
        }
    }

    private void getProfileData() {
        this.usernameStr = this.mSharedPref.getString("usernamekey", "");
    }

    public void onPause() {
        if (this.mProgressbar.isShowing()) {
            this.mProgressbar.dismiss();
        }
        super.onPause();
    }

    protected void onStop() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && transparentProgressDialog.isShowing()) {
            this.mProgressbar.dismiss();
        }
        super.onStop();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void loadChangePasswordData() {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
        this.conMgr = connectivityManager;
        if (connectivityManager.getActiveNetworkInfo() != null && this.conMgr.getActiveNetworkInfo().isAvailable() && this.conMgr.getActiveNetworkInfo().isConnected()) {
            changePassword();
        } else {
            Toast.makeText(this.context, "Check your Network Connection", 0).show();
        }
    }

    private void changePassword() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        HashMap hashMap = new HashMap();
        hashMap.put("username", this.username);
        hashMap.put("CurrentPassword", this.oldpassword);
        hashMap.put("NewPassword", this.newpassword);
        hashMap.put("ConfirmPassword", this.confirmpassword);
        hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).GetChangePassword(hashMap).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (ChangePasswordActivity.this.mProgressbar != null && ChangePasswordActivity.this.mProgressbar.isShowing()) {
                    ChangePasswordActivity.this.mProgressbar.dismiss();
                }
                if (response == null || response.body() == null) {
                    Utility.showAlertDialog(ChangePasswordActivity.this.myActivity);
                    return;
                }
                ChangePasswordActivity.this.resultStr = (String) response.body();
                ChangePasswordActivity.this.mAlertText.setText(ChangePasswordActivity.this.resultStr);
                Bundle bundle = new Bundle();
                bundle.putString("user_name", ChangePasswordActivity.this.usernameStr);
                ChangePasswordActivity.this.mFirebaseAnalytics.logEvent("EVENT_CHANGE_PASSWORD", bundle);
                ChangePasswordActivity.this.mDialogAlert.show();
            }

            public void onFailure(Call<String> call, Throwable th) {
                if (ChangePasswordActivity.this.mProgressbar != null && ChangePasswordActivity.this.mProgressbar.isShowing()) {
                    ChangePasswordActivity.this.mProgressbar.dismiss();
                }
                Utility.showAlertDialog(ChangePasswordActivity.this.myActivity);
            }
        });
    }

    protected void onResume() {
        super.onResume();
        String string = getSharedPreferences("", 0).getString("usernamekey", "");
        Bundle bundle = new Bundle();
        bundle.putString("user_name", string);
        FirebaseAnalytics.getInstance(this).logEvent("PAGE_CHANGE_PASSWORD", bundle);
    }
}