导航菜单

页面标题

页面副标题

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

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

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


package com.mcb.stjohnsemschool.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.location.Address;
import android.location.Geocoder;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.api.net.FetchPlaceRequest;
import com.google.android.libraries.places.api.net.FetchPlaceResponse;
import com.google.android.material.textfield.TextInputLayout;
import com.mcb.stjohnsemschool.DB.MyClassBoardDB;
import com.mcb.stjohnsemschool.adapter.GooglePlacesAutocompleteAdapter;
import com.mcb.stjohnsemschool.model.AddressModel;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AddDeliveryAddressActivity extends AppCompatActivity {
    public static final String TAG = "com.mcb.stjohnsemschool.activity.AddDeliveryAddressActivity";
    static String area = "";
    static double lat;
    static double lng;
    public static Activity myActivity;
    static ArrayList<String> placeIds = new ArrayList<>();
    String city;
    Context context;
    String firstName;
    String flat;
    int isDefault;
    String lastName;
    String locality;
    EditText mAddressTitle;
    TextInputLayout mAddressTitleTL;
    SharedPreferences.Editor mEditor;
    EditText mFirstName;
    EditText mFlat;
    RadioButton mHomeRBtn;
    EditText mLastName;
    AutoCompleteTextView mLocality;
    EditText mMobileNo;
    RadioButton mOtherBtn;
    EditText mPincode;
    private TransparentProgressDialog mProgressbar;
    SharedPreferences mSharedPref;
    EditText mStreet;
    RadioGroup mTitleRGP;
    RadioButton mWorkRBtn;
    String pincode;
    String street;
    Typeface typeface;
    String landmark = "";
    String title = "Home";
    int customerAddressDetailsId = -1;
    String address1 = "";
    String address2 = "";
    String mobileNo = "";
    ArrayList<String> results = new ArrayList<>();
    boolean isValidLocality = false;
    String userId = "0";
    String studentEnrollmentId = "0";

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_add_delivery_address);
        myActivity = this;
        Context applicationContext = getApplicationContext();
        this.context = applicationContext;
        this.typeface = Typeface.createFromAsset(applicationContext.getAssets(), "Roboto-Regular.ttf");
        getSupportActionBar().setTitle("Add Address");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        this.customerAddressDetailsId = getIntent().getExtras().getInt("addressId");
        SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
        this.mSharedPref = sharedPreferences;
        this.mEditor = sharedPreferences.edit();
        this.userId = this.mSharedPref.getString("UseridKey", this.userId);
        this.studentEnrollmentId = this.mSharedPref.getString("studentEnrollmentIdKey", this.studentEnrollmentId);
        initializations();
    }

    private void initializations() {
        this.mProgressbar = new TransparentProgressDialog(this, R.drawable.spinner_loading_imag);
        this.mTitleRGP = (RadioGroup) findViewById(R.id.rgp_title_address);
        this.mHomeRBtn = (RadioButton) findViewById(R.id.rbtn_home);
        this.mWorkRBtn = (RadioButton) findViewById(R.id.rbtn_work);
        this.mOtherBtn = (RadioButton) findViewById(R.id.rbtn_other);
        this.mAddressTitleTL = (TextInputLayout) findViewById(R.id.fl_title_address);
        this.mAddressTitle = (EditText) findViewById(R.id.edt_title_address);
        this.mFirstName = (EditText) findViewById(R.id.edt_first_name_address);
        this.mLastName = (EditText) findViewById(R.id.edt_last_name_address);
        this.mMobileNo = (EditText) findViewById(R.id.edt_mobileno_address);
        this.mFlat = (EditText) findViewById(R.id.edt_flat_address);
        this.mStreet = (EditText) findViewById(R.id.edt_street_address);
        AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.edt_location_address);
        this.mLocality = autoCompleteTextView;
        autoCompleteTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable editable) {
            }

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                if (AddDeliveryAddressActivity.this.customerAddressDetailsId <= 0) {
                    AddDeliveryAddressActivity.lng = 0.0d;
                    AddDeliveryAddressActivity.lat = 0.0d;
                }
                AddDeliveryAddressActivity.this.isValidLocality = false;
            }
        });
        this.mPincode = (EditText) findViewById(R.id.edt_pincode_address);
        this.mAddressTitle.setTypeface(this.typeface);
        this.mFirstName.setTypeface(this.typeface);
        this.mLastName.setTypeface(this.typeface);
        this.mMobileNo.setTypeface(this.typeface);
        this.mFlat.setTypeface(this.typeface);
        this.mStreet.setTypeface(this.typeface);
        this.mLocality.setTypeface(this.typeface);
        this.mPincode.setTypeface(this.typeface);
        this.mAddressTitle.setText("Home");
        this.mAddressTitleTL.setVisibility(8);
        if (this.customerAddressDetailsId > -1) {
            Bundle extras = getIntent().getExtras();
            this.title = extras.getString("title");
            this.firstName = extras.getString("firstName");
            this.lastName = extras.getString("lastName");
            this.mobileNo = extras.getString("mobileNo");
            this.address1 = extras.getString("address1");
            this.address2 = extras.getString("address2");
            this.locality = extras.getString("selectedLocation");
            lat = extras.getDouble("lat");
            lng = extras.getDouble("lang");
            this.pincode = extras.getString("pincode");
            this.mAddressTitle.setText(this.title);
            this.mFlat.setText(this.address1);
            this.mStreet.setText(this.address2);
            this.mFirstName.setText(this.firstName);
            this.mLastName.setText(this.lastName);
            this.mMobileNo.setText(this.mobileNo);
            if (this.title.equalsIgnoreCase("Home")) {
                this.mHomeRBtn.setChecked(true);
                this.mAddressTitle.setText("Home");
            } else if (this.title.equalsIgnoreCase("Work")) {
                this.mWorkRBtn.setChecked(true);
                this.mAddressTitle.setText("Work");
            } else {
                this.mOtherBtn.setChecked(true);
                this.mAddressTitleTL.setVisibility(0);
            }
            String str = this.pincode;
            if (str != null && str.length() > 0 && !this.pincode.equalsIgnoreCase("null")) {
                this.mPincode.setText(this.pincode);
            } else {
                this.mPincode.setText("");
            }
            String str2 = this.locality;
            if (str2 == null || str2.length() <= 0 || this.locality.equalsIgnoreCase("null")) {
                this.mLocality.setText("");
                this.isValidLocality = false;
            } else {
                this.mLocality.setText(this.locality);
                this.isValidLocality = true;
            }
        } else {
            getAddressOfStudent();
        }
        this.mTitleRGP.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                AddDeliveryAddressActivity.this.mAddressTitleTL.setVisibility(8);
                if (i == 2131363384) {
                    AddDeliveryAddressActivity.this.mAddressTitle.setText("Home");
                    return;
                }
                if (i == 2131363398) {
                    AddDeliveryAddressActivity.this.mAddressTitle.setText("Work");
                } else if (i == 2131363390) {
                    AddDeliveryAddressActivity.this.mAddressTitleTL.setVisibility(0);
                    AddDeliveryAddressActivity.this.mAddressTitle.setText("");
                    AddDeliveryAddressActivity.this.mAddressTitle.requestFocus();
                }
            }
        });
        this.mLocality.setAdapter(new GooglePlacesAutocompleteAdapter(this.context, R.layout.item_textview, placeIds, this.results));
        this.mLocality.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                try {
                    if (AddDeliveryAddressActivity.placeIds.size() > 0) {
                        ((InputMethodManager) AddDeliveryAddressActivity.this.getSystemService("input_method")).hideSoftInputFromWindow(AddDeliveryAddressActivity.this.mLocality.getWindowToken(), 0);
                        AddDeliveryAddressActivity.area = AddDeliveryAddressActivity.this.results.get(i);
                        AddDeliveryAddressActivity.this.mLocality.setText(AddDeliveryAddressActivity.area);
                        AddDeliveryAddressActivity.this.mLocality.setSelection(0);
                        AddDeliveryAddressActivity.this.isValidLocality = true;
                        AddDeliveryAddressActivity.this.getLatLng(AddDeliveryAddressActivity.placeIds.get(i));
                    }
                } catch (Exception unused) {
                }
            }
        });
    }

    public void getLatLng(String str) {
        Places.createClient(this.context).fetchPlace(FetchPlaceRequest.builder(str, Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG)).build()).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {
            @Override
            public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
                LatLng latLng = fetchPlaceResponse.getPlace().getLatLng();
                AddDeliveryAddressActivity.lat = latLng.latitude;
                AddDeliveryAddressActivity.lng = latLng.longitude;
                AddDeliveryAddressActivity.this.getAddressFromLocation(AddDeliveryAddressActivity.lat, AddDeliveryAddressActivity.lng);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception exc) {
            }
        });
    }

    public void getAddressFromLocation(double d, double d2) {
        Address address;
        String postalCode;
        try {
            List<Address> fromLocation = new Geocoder(this.context, Locale.getDefault()).getFromLocation(d, d2, 1);
            if (fromLocation == null || fromLocation.size() <= 0 || (address = fromLocation.get(0)) == null || (postalCode = address.getPostalCode()) == null) {
                return;
            }
            this.mPincode.setText(postalCode);
        } catch (IOException e) {
            Log.e(TAG, "Unable connect to Geocoder", e);
        }
    }

    private void getAddressOfStudent() {
        new MyClassBoardDB(this);
        String string = this.mSharedPref.getString("Parent_address", "");
        String string2 = this.mSharedPref.getString("Father_name", "");
        String string3 = this.mSharedPref.getString("Mother_name", "");
        String string4 = this.mSharedPref.getString("Father_phone", "");
        String string5 = this.mSharedPref.getString("Mother_phone", "");
        if (string != null && string.length() > 0 && !string.equalsIgnoreCase("null")) {
            this.mFlat.setText(string);
        } else {
            this.mFlat.setText("");
        }
        if (string2 == null || string2.length() == 0 || string2.equalsIgnoreCase("null")) {
            string2 = string3;
        }
        if (string2 != null && string2.length() > 0 && !string2.equalsIgnoreCase("null")) {
            this.mFirstName.setText(string2);
        } else {
            this.mFirstName.setText("");
        }
        if (string4 == null || string4.length() == 0 || string4.equalsIgnoreCase("null")) {
            string4 = string5;
        }
        if (string4 != null && string4.length() > 0 && !string4.equalsIgnoreCase("null")) {
            this.mMobileNo.setText(string4);
        } else {
            this.mMobileNo.setText("");
        }
    }

    protected void onStart() {
        super.onStart();
    }

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

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.save_icon_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        }
        if (itemId == 2131361885) {
            next();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    public void next() {
        this.title = this.mAddressTitle.getText().toString().trim();
        this.firstName = this.mFirstName.getText().toString().trim();
        this.lastName = this.mLastName.getText().toString().trim();
        this.mobileNo = this.mMobileNo.getText().toString().trim();
        this.flat = this.mFlat.getText().toString().trim();
        this.street = this.mStreet.getText().toString().trim();
        this.locality = this.mLocality.getText().toString().trim();
        this.pincode = this.mPincode.getText().toString().trim();
        if (this.title.length() > 0 && this.firstName.length() > 0 && this.lastName.length() > 0 && this.mobileNo.length() > 0 && this.flat.length() > 0 && this.street.length() > 0 && this.pincode.length() > 0) {
            this.address1 = this.flat;
            this.address2 = this.street;
            addAddress();
            return;
        }
        if (this.title.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Address Title", 0).show();
            return;
        }
        if (this.firstName.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter First Name", 0).show();
            return;
        }
        if (this.lastName.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Last Name", 0).show();
            return;
        }
        if (this.mobileNo.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Mobile Number", 0).show();
            return;
        }
        if (this.flat.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Flat/House/Office No", 0).show();
        } else if (this.street.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Street/Society/Office Name", 0).show();
        } else if (this.pincode.length() == 0) {
            Toast.makeText(getApplicationContext(), "Enter Pincode", 0).show();
        }
    }

    private void addAddress() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
            saveSchoolStoreAddresses();
        } else {
            Toast.makeText(getApplicationContext(), "Check your Network Connection", 1).show();
        }
    }

    private void saveSchoolStoreAddresses() {
        TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
        if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
            this.mProgressbar.show();
        }
        String string = this.mSharedPref.getString("studentEnrollmentIdKey", "0");
        HashMap hashMap = new HashMap();
        hashMap.put("Address1", this.address1);
        hashMap.put("Address2", this.address2);
        hashMap.put("CityID", String.valueOf(0));
        hashMap.put("StateId", String.valueOf(0));
        hashMap.put("Pincode", this.pincode);
        hashMap.put("Mobile", this.mobileNo);
        hashMap.put("FirstName", this.firstName);
        hashMap.put("MiddleName", "");
        hashMap.put("LastName", this.lastName);
        hashMap.put("IsDefault", String.valueOf(this.isDefault));
        hashMap.put("StudentEnrollmentID", string);
        hashMap.put("SchoolStoreStudentAddressDetailsID", String.valueOf(this.customerAddressDetailsId));
        hashMap.put("Locality", "");
        hashMap.put("Latitude", String.valueOf(lat));
        hashMap.put("Langitude", String.valueOf(lng));
        hashMap.put("AddressTitle", this.title);
        hashMap.put("selectedLocation", this.locality);
        hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
        ((ApiInterface) ApiClient.getClient1(getApplicationContext()).create(ApiInterface.class)).SaveSchoolStoreAddresses(hashMap).enqueue(new Callback<ArrayList<AddressModel>>() {
            public void onResponse(Call<ArrayList<AddressModel>> call, Response<ArrayList<AddressModel>> response) {
                if (AddDeliveryAddressActivity.this.mProgressbar != null && AddDeliveryAddressActivity.this.mProgressbar.isShowing()) {
                    AddDeliveryAddressActivity.this.mProgressbar.dismiss();
                }
                if (response != null && response.body() != null) {
                    new ArrayList();
                    ArrayList arrayList = (ArrayList) response.body();
                    if (arrayList != null && arrayList.size() > 0) {
                        Toast.makeText(AddDeliveryAddressActivity.this.getApplicationContext(), "Address Added Successfully", 0).show();
                        AddressModel addressModel = (AddressModel) arrayList.get(0);
                        int addressId = addressModel.getAddressId();
                        String addressTitle = addressModel.getAddressTitle();
                        String str = addressModel.getFirstName() + " " + addressModel.getLastName();
                        String mobileNo = addressModel.getMobileNo();
                        String address1 = addressModel.getAddress1();
                        String address2 = addressModel.getAddress2();
                        String cityName = addressModel.getCityName();
                        String stateName = addressModel.getStateName();
                        String pincode = addressModel.getPincode();
                        String str2 = addressModel.getLatitude() + "";
                        String str3 = addressModel.getLangitude() + "";
                        Intent intent = new Intent();
                        intent.putExtra("addressId", addressId);
                        intent.putExtra("title", addressTitle);
                        intent.putExtra(AppMeasurementSdk.ConditionalUserProperty.NAME, str);
                        intent.putExtra("mobileNo", mobileNo);
                        intent.putExtra("address1", address1);
                        intent.putExtra("address2", address2);
                        intent.putExtra("city", cityName);
                        intent.putExtra("state", stateName);
                        intent.putExtra("pincode", pincode);
                        intent.putExtra("latitude", Double.parseDouble(str2));
                        intent.putExtra("langitude", Double.parseDouble(str3));
                        intent.putExtra("SelectedLocality", addressModel.getSelectedLocality());
                        AddDeliveryAddressActivity.this.setResult(200, intent);
                        AddDeliveryAddressActivity.this.finish();
                        return;
                    }
                    Toast.makeText(AddDeliveryAddressActivity.this.getApplicationContext(), "Address not saved", 0).show();
                    return;
                }
                Utility.showAlertDialog(AddDeliveryAddressActivity.myActivity);
            }

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

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