add address on order address pages
This commit is contained in:
@@ -1,15 +1,346 @@
|
||||
package ch.pizzalink.android.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import butterknife.BindString;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import ch.pizzalink.android.R;
|
||||
import ch.pizzalink.android.api.ApiEndPoints;
|
||||
import ch.pizzalink.android.api.ApiErrorUtils;
|
||||
import ch.pizzalink.android.api.ApiService;
|
||||
import ch.pizzalink.android.api.ResponseArray;
|
||||
import ch.pizzalink.android.api.ResponseObject;
|
||||
import ch.pizzalink.android.helper.DialogHelper;
|
||||
import ch.pizzalink.android.helper.SessionHelper;
|
||||
import ch.pizzalink.android.helper.ViewHelper;
|
||||
import ch.pizzalink.android.model.AddNewAddressResponseModel;
|
||||
import ch.pizzalink.android.model.CityModel;
|
||||
import ch.pizzalink.android.model.CountryModel;
|
||||
import ch.pizzalink.android.model.ZoneModel;
|
||||
import ch.pizzalink.android.view.PizzalinkDropdownView;
|
||||
import ch.pizzalink.android.view.PizzalinkEditText;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AddAddressActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.address1PizzalinkEditText) PizzalinkEditText address1PizzalinkEditText;
|
||||
@BindView(R.id.cityPizzalinkDropdown) PizzalinkDropdownView cityPizzalinkDropdown;
|
||||
@BindView(R.id.postcodePizzalinkDrowpdown) PizzalinkDropdownView postcodePizzalinkDrowpdown;
|
||||
@BindView(R.id.countryPizzalinkDropdown) PizzalinkDropdownView countryPizzalinkDropdown;
|
||||
@BindView(R.id.zonePizzalinkDropdown) PizzalinkDropdownView zonePizzalinkDropdown;
|
||||
|
||||
@BindString(R.string.alert_fill_all_fields) String fillAllFieldsText;
|
||||
@BindString(R.string.alert_select_country_first) String selectCountryFirstText;
|
||||
@BindString(R.string.new_address_added) String newAddressAddedText;
|
||||
|
||||
private ArrayList<CityModel> cityList = new ArrayList<>();
|
||||
private ArrayList<CountryModel> countryList = new ArrayList<>();
|
||||
private ArrayList<ZoneModel> zoneList = new ArrayList<>();
|
||||
private CityModel selectedCityModel;
|
||||
private CountryModel selectedCountryModel;
|
||||
private ZoneModel selectedZoneModel;
|
||||
|
||||
private int activeRequestCount = 0;
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_address);
|
||||
ButterKnife.bind(this);
|
||||
getCityList();
|
||||
getCountryList();
|
||||
}
|
||||
|
||||
@OnClick({R.id.cityPizzalinkDropdown, R.id.countryPizzalinkDropdown,
|
||||
R.id.zonePizzalinkDropdown, R.id.addNewAddressButton})
|
||||
protected void onClick(View view){
|
||||
switch (view.getId()){
|
||||
case R.id.cityPizzalinkDropdown:
|
||||
showCityDialog();
|
||||
break;
|
||||
case R.id.countryPizzalinkDropdown:
|
||||
showCountryDialog();
|
||||
break;
|
||||
case R.id.zonePizzalinkDropdown:
|
||||
if(selectedCountryModel != null){
|
||||
getZoneList();
|
||||
}
|
||||
else {
|
||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity, selectCountryFirstText);
|
||||
}
|
||||
break;
|
||||
case R.id.addNewAddressButton:
|
||||
ViewHelper.hideKeyboard();
|
||||
if(checkFields())
|
||||
addNewAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkFields(){
|
||||
|
||||
if(address1PizzalinkEditText.isEmail() ||
|
||||
selectedCityModel == null ||
|
||||
selectedCountryModel == null ||
|
||||
selectedZoneModel == null){
|
||||
DialogHelper.showAlertDialog(this, fillAllFieldsText);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void getCityList(){
|
||||
|
||||
if(activeRequestCount == 0)
|
||||
DialogHelper.showLoadingDialog();
|
||||
|
||||
Call<ResponseArray<CityModel>> call = ApiService.apiInterface.getCityList();
|
||||
call.enqueue(new Callback<ResponseArray<CityModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseArray<CityModel>> call, Response<ResponseArray<CityModel>> response) {
|
||||
|
||||
decreaseActiveRequestCount();
|
||||
|
||||
if(activeRequestCount == 0)
|
||||
DialogHelper.hideLoadingDialog();
|
||||
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
fillAndNotifyCityList(response.body().getData());
|
||||
}
|
||||
else if(activeRequestCount == 0){
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseArray<CityModel>> call, Throwable t) {
|
||||
decreaseActiveRequestCount();
|
||||
if(activeRequestCount == 0){
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
increaseActiveRequestCount();
|
||||
}
|
||||
|
||||
private void getCountryList(){
|
||||
|
||||
if(activeRequestCount == 0)
|
||||
DialogHelper.showLoadingDialog();
|
||||
|
||||
increaseActiveRequestCount();
|
||||
|
||||
Call<ResponseArray<CountryModel>> call = ApiService.apiInterface.getCountryList();
|
||||
call.enqueue(new Callback<ResponseArray<CountryModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseArray<CountryModel>> call, Response<ResponseArray<CountryModel>> response) {
|
||||
|
||||
decreaseActiveRequestCount();
|
||||
|
||||
if(activeRequestCount == 0)
|
||||
DialogHelper.hideLoadingDialog();
|
||||
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
fillAndNotifyCountryList(response.body().getData());
|
||||
}
|
||||
else if(activeRequestCount == 0){
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseArray<CountryModel>> call, Throwable t) {
|
||||
decreaseActiveRequestCount();
|
||||
if(activeRequestCount == 0){
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getZoneList(){
|
||||
DialogHelper.showLoadingDialog();
|
||||
Call<ResponseArray<ZoneModel>> call = ApiService.apiInterface.getZoneList(selectedCountryModel.getId());
|
||||
call.enqueue(new Callback<ResponseArray<ZoneModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseArray<ZoneModel>> call, Response<ResponseArray<ZoneModel>> response) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
fillAndShowZoneList(response.body().getData());
|
||||
}
|
||||
else {
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseArray<ZoneModel>> call, Throwable t) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fillAndNotifyCityList(ArrayList<CityModel> cities){
|
||||
CityModel.checkNull(cities);
|
||||
cityList.clear();
|
||||
cityList.addAll(cities);
|
||||
}
|
||||
|
||||
private void fillAndNotifyCountryList(ArrayList<CountryModel> countries){
|
||||
CountryModel.checkNull(countries);
|
||||
countryList.clear();
|
||||
countryList.addAll(countries);
|
||||
}
|
||||
|
||||
private void fillAndShowZoneList(ArrayList<ZoneModel> zones){
|
||||
ZoneModel.checkNull(zones);
|
||||
zoneList.clear();
|
||||
zoneList.addAll(zones);
|
||||
showZoneDialog();
|
||||
}
|
||||
|
||||
private void showCityDialog(){
|
||||
|
||||
final ArrayList<String> zoneNameList = new ArrayList<>();
|
||||
for(CityModel zone : cityList){
|
||||
zoneNameList.add(zone.getCity());
|
||||
}
|
||||
|
||||
DialogHelper.showListDialog(zoneNameList, new MaterialDialog.ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||
selectedCityModel = cityList.get(position);
|
||||
cityPizzalinkDropdown.setText(selectedCityModel.getCity());
|
||||
postcodePizzalinkDrowpdown.setText(selectedCityModel.getPostcode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showCountryDialog(){
|
||||
|
||||
final ArrayList<String> countryNameList = new ArrayList<>();
|
||||
for(CountryModel country : countryList){
|
||||
countryNameList.add(country.getName());
|
||||
}
|
||||
|
||||
DialogHelper.showListDialog(countryNameList, new MaterialDialog.ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||
selectedCountryModel = countryList.get(position);
|
||||
countryPizzalinkDropdown.setText(selectedCountryModel.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showZoneDialog(){
|
||||
|
||||
final ArrayList<String> zoneNameList = new ArrayList<>();
|
||||
for(ZoneModel zone : zoneList){
|
||||
zoneNameList.add(zone.getName());
|
||||
}
|
||||
|
||||
DialogHelper.showListDialog(zoneNameList, new MaterialDialog.ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||
selectedZoneModel = zoneList.get(position);
|
||||
zonePizzalinkDropdown.setText(selectedZoneModel.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addNewAddress(){
|
||||
DialogHelper.showLoadingDialog();
|
||||
Call<ResponseObject<AddNewAddressResponseModel>> call = ApiService.apiInterface.addNewAddress(
|
||||
ApiEndPoints.API_ADD_NEW_ADDRESS + SessionHelper.getCustomerToken().getToken(),
|
||||
getAddNewAddressRequestParams());
|
||||
call.enqueue(new Callback<ResponseObject<AddNewAddressResponseModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ResponseObject<AddNewAddressResponseModel>> call, final Response<ResponseObject<AddNewAddressResponseModel>> response) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
if(response.isSuccessful() &&
|
||||
response.body().getData() != null &&
|
||||
response.body().isSuccess()){
|
||||
DialogHelper.showOneButtonDialogWithCallback(newAddressAddedText,
|
||||
new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
dialog.dismiss();
|
||||
Intent newAddressIntent = new Intent();
|
||||
newAddressIntent.putExtra("newAddressId",
|
||||
response.body().getData().getAddressId());
|
||||
setResult(RESULT_OK, newAddressIntent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseObject<AddNewAddressResponseModel>> call, Throwable t) {
|
||||
DialogHelper.hideLoadingDialog();
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private HashMap<String, Object> getAddNewAddressRequestParams(){
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("address_1", address1PizzalinkEditText.getText());
|
||||
params.put("address_2", "");
|
||||
params.put("city", selectedCityModel.getCity());
|
||||
params.put("postcode", selectedCityModel.getPostcode());
|
||||
params.put("country_id", selectedCountryModel.getId());
|
||||
params.put("zone_id", selectedZoneModel.getZoneId());
|
||||
return params;
|
||||
}
|
||||
|
||||
private synchronized void increaseActiveRequestCount(){
|
||||
lock.lock();
|
||||
try {
|
||||
activeRequestCount++;
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void decreaseActiveRequestCount(){
|
||||
lock.lock();
|
||||
try {
|
||||
activeRequestCount--;
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class MyAddressesActivity extends BaseActivity {
|
||||
|
||||
private ArrayList<AddressModel> addressList = new ArrayList<>();
|
||||
private MyAddressesRecyclerAdapter addressesRecyclerAdapter;
|
||||
private int REQUEST_CODE_ADD_NEW_ADDRESS = 8573;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -57,7 +58,17 @@ public class MyAddressesActivity extends BaseActivity {
|
||||
|
||||
@OnClick(R.id.addNewAddressButton)
|
||||
public void onClick(){
|
||||
startActivity(new Intent(this, AddAddressActivity.class));
|
||||
Intent addNewAddressIntent = new Intent(this, AddAddressActivity.class);
|
||||
startActivityForResult(addNewAddressIntent, REQUEST_CODE_ADD_NEW_ADDRESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == REQUEST_CODE_ADD_NEW_ADDRESS &&
|
||||
resultCode == RESULT_OK){
|
||||
getCustomerAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews(){
|
||||
|
||||
@@ -47,6 +47,11 @@ public class OrderActivity extends BaseActivity {
|
||||
initViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void getDataFromIntent(){
|
||||
cartInfoModel = (CartInfoModel) getIntent().getSerializableExtra("cartInfoModel");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import retrofit2.Response;
|
||||
|
||||
public class RegisterActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.registerButton) Button registerButton;
|
||||
@BindViews({ R.id.firstnamePizzalinkEditText, R.id.lasstnamePizzalinkEditText,
|
||||
R.id.telephonePizzalinkEditText, R.id.emailPizzalinkEditText,
|
||||
R.id.passwordPizzalinkEditText, R.id.passwordAgainPizzalinkEditText,
|
||||
@@ -48,14 +47,13 @@ public class RegisterActivity extends BaseActivity {
|
||||
@BindView(R.id.postcodePizzalinkDrowpdown) PizzalinkDropdownView postcodePizzalinkDrowpdown;
|
||||
@BindView(R.id.countryPizzalinkDropdown) PizzalinkDropdownView countryPizzalinkDropdown;
|
||||
@BindView(R.id.zonePizzalinkDropdown) PizzalinkDropdownView zonePizzalinkDropdown;
|
||||
@BindView(R.id.registerButton) Button registerButton;
|
||||
|
||||
@BindString(R.string.alert_fill_all_fields) String fillAllFieldsText;
|
||||
@BindString(R.string.alert_invalid_email) String validEmailText;
|
||||
@BindString(R.string.alert_passwords_not_matched) String passwordsNotMatchedText;
|
||||
@BindString(R.string.alert_invalid_post_code) String invalidPostCodeText;
|
||||
@BindString(R.string.alert_select_country_first) String selectCountryFirstText;
|
||||
|
||||
|
||||
private ArrayList<CityModel> cityList = new ArrayList<>();
|
||||
private ArrayList<CountryModel> countryList = new ArrayList<>();
|
||||
private ArrayList<ZoneModel> zoneList = new ArrayList<>();
|
||||
@@ -76,9 +74,8 @@ public class RegisterActivity extends BaseActivity {
|
||||
//setTestFields();
|
||||
}
|
||||
|
||||
@OnClick({R.id.cityPizzalinkDropdown, R.id.postcodePizzalinkDrowpdown,
|
||||
R.id.countryPizzalinkDropdown, R.id.zonePizzalinkDropdown,
|
||||
R.id.registerButton})
|
||||
@OnClick({R.id.cityPizzalinkDropdown, R.id.countryPizzalinkDropdown,
|
||||
R.id.zonePizzalinkDropdown, R.id.registerButton})
|
||||
protected void onClick(View view){
|
||||
switch (view.getId()){
|
||||
case R.id.cityPizzalinkDropdown:
|
||||
|
||||
@@ -17,6 +17,8 @@ public class ApiEndPoints {
|
||||
public static final String API_ADD_PRODUCTS_TO_BASKET = PREFIX + "addProductsToBasket" + SUFFIX + "&token=";
|
||||
public static final String API_GET_SHIPPING_METHODS = PREFIX + "getShippingMethodsArray" + SUFFIX;
|
||||
public static final String API_GET_CUSTOMER_ADDRESSES = PREFIX + "getAddresses" + SUFFIX;
|
||||
public static final String API_ADD_NEW_ADDRESS = PREFIX + "addAddress" + SUFFIX + "&token=";
|
||||
public static final String API_DELETE_ADDRESS = PREFIX + "deleteAddress" + SUFFIX + "&token=";
|
||||
public static final String API_GET_PAYMENT_METHODS = PREFIX + "getPaymentMethodsArray" + SUFFIX;
|
||||
public static final String API_CREATE_ORDER = PREFIX + "addOrder2" + SUFFIX + "&token=";
|
||||
public static final String API_CHECK_UPDATE = PREFIX + "checkUpdate" + SUFFIX;
|
||||
@@ -26,7 +28,6 @@ public class ApiEndPoints {
|
||||
public static final String API_GET_ZONE_LIST = PREFIX + "getZones" + SUFFIX;
|
||||
public static final String API_GET_CUSTOMER_PROFILE = PREFIX + "getCustomerInfo" + SUFFIX;
|
||||
public static final String API_UPDATE_PASSWORD = PREFIX + "passwordUpdate" + SUFFIX + "&token=";
|
||||
public static final String API_DELETE_ADDRESS = PREFIX + "deleteAddress" + SUFFIX + "&token=";
|
||||
public static final String API_UPDATE_PROFILE = PREFIX + "updateCustomerInfo" + SUFFIX + "&token=";
|
||||
public static final String API_REMOVE_RPODUCT_FORM_CART = PREFIX + "removeProductFromBasket" + SUFFIX + "&token=";
|
||||
public static final String API_GET_STORE_INFO = PREFIX + "getStoreInfo" + SUFFIX;
|
||||
|
||||
@@ -2,6 +2,7 @@ package ch.pizzalink.android.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import ch.pizzalink.android.model.AddNewAddressResponseModel;
|
||||
import ch.pizzalink.android.model.AddProductToBasketResponseModel;
|
||||
import ch.pizzalink.android.model.AddressModel;
|
||||
import ch.pizzalink.android.model.AppVersionModel;
|
||||
@@ -93,6 +94,17 @@ public interface ApiInterface {
|
||||
@GET(ApiEndPoints.API_GET_CUSTOMER_ADDRESSES)
|
||||
Call<ResponseArray<AddressModel>> getCustomerAddresses(@Query("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<AddNewAddressResponseModel>> addNewAddress(@Url String url,
|
||||
@FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<DeleteAddressResponseModel>> deleteAddress(@Url String url,
|
||||
@Field("address_id") String addressId);
|
||||
|
||||
|
||||
@GET(ApiEndPoints.API_GET_PAYMENT_METHODS)
|
||||
Call<ResponseObject<PaymentMethodsResponseModel>> getPaymentMethods(@Query("token") String token);
|
||||
|
||||
@@ -125,11 +137,6 @@ public interface ApiInterface {
|
||||
@POST
|
||||
Call<ResponseObject> updatePassword(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<DeleteAddressResponseModel>> deleteAddress(@Url String url,
|
||||
@Field("address_id") String addressId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST
|
||||
Call<ResponseObject<UserModel>> updateProfile(@Url String url, @FieldMap HashMap<String, Object> body);
|
||||
@@ -142,5 +149,4 @@ public interface ApiInterface {
|
||||
@GET(ApiEndPoints.API_GET_STORE_INFO)
|
||||
Call<ResponseObject<StoreInfoModel>> getStoreInfo();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package ch.pizzalink.android.fragment.order;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -14,6 +16,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import ch.pizzalink.android.R;
|
||||
import ch.pizzalink.android.activity.AddAddressActivity;
|
||||
import ch.pizzalink.android.activity.BaseActivity;
|
||||
import ch.pizzalink.android.activity.OrderActivity;
|
||||
import ch.pizzalink.android.adapter.recycler.ShippingAddressesRecyclerAdapter;
|
||||
@@ -29,6 +32,8 @@ import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 17/10/2017.
|
||||
*/
|
||||
@@ -36,13 +41,16 @@ import retrofit2.Response;
|
||||
public class ShippingAddressFragment extends OrderBaseFragment {
|
||||
|
||||
@BindView(R.id.shippingAddressesRecyclerView) RecyclerView shippingAddressesRecyclerView;
|
||||
@BindView(R.id.addNewAddressButton) Button addNewAddressButton;
|
||||
|
||||
@BindString(R.string.alert_choose_shipping_address) String chooseShippingAddressText;
|
||||
|
||||
private ArrayList<AddressModel> addressList = new ArrayList<>();
|
||||
private ShippingAddressesRecyclerAdapter shippingAddressesRecyclerAdapter;
|
||||
|
||||
private AddressModel selectedAddress;
|
||||
private int REQUEST_CODE_ADD_NEW_ADDRESS = 2350;
|
||||
private boolean needToSortAddresses;
|
||||
private String newAddressId = "";
|
||||
|
||||
public static final java.lang.String FRAGMENT_NAME = "shippingAddressMethod";
|
||||
|
||||
@@ -66,10 +74,25 @@ public class ShippingAddressFragment extends OrderBaseFragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
@OnClick({R.id.previousTextView, R.id.nextTextView})
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(requestCode == REQUEST_CODE_ADD_NEW_ADDRESS &&
|
||||
resultCode == RESULT_OK){
|
||||
newAddressId = data.getStringExtra("newAddressId");
|
||||
getCustomerShippingAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.addNewAddressButton, R.id.previousTextView, R.id.nextTextView})
|
||||
protected void onClick(View view){
|
||||
OrderActivity orderActivity = (OrderActivity) getActivity();
|
||||
switch (view.getId()){
|
||||
case R.id.addNewAddressButton:
|
||||
Intent addNewAddressIntent = new Intent(BaseActivity.currentActivity,
|
||||
AddAddressActivity.class);
|
||||
startActivityForResult(addNewAddressIntent, REQUEST_CODE_ADD_NEW_ADDRESS);
|
||||
break;
|
||||
case R.id.previousTextView:
|
||||
orderActivity.onPreviousClicked(FRAGMENT_NAME);
|
||||
break;
|
||||
@@ -117,13 +140,21 @@ public class ShippingAddressFragment extends OrderBaseFragment {
|
||||
}
|
||||
|
||||
private void fillAndNotifyAdapter(ArrayList<AddressModel> addressModels){
|
||||
|
||||
AddressModel.checkNull(addressModels);
|
||||
addressList.clear();
|
||||
addressList.addAll(addressModels);
|
||||
|
||||
if(addressList.size() != 0){
|
||||
|
||||
if(!newAddressId.isEmpty()){
|
||||
sortAddresses();
|
||||
}
|
||||
|
||||
addressList.get(0).setSelected(true);
|
||||
selectedAddress = addressList.get(0);
|
||||
}
|
||||
|
||||
shippingAddressesRecyclerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -143,4 +174,25 @@ public class ShippingAddressFragment extends OrderBaseFragment {
|
||||
shippingAddressesRecyclerView.setLayoutManager(layoutManager);
|
||||
shippingAddressesRecyclerView.setAdapter(shippingAddressesRecyclerAdapter);
|
||||
}
|
||||
|
||||
private void sortAddresses(){
|
||||
|
||||
ArrayList<AddressModel> tempAddressList = new ArrayList<>();
|
||||
|
||||
for(AddressModel addressModel : addressList){
|
||||
if(addressModel.getId().equals(newAddressId)){
|
||||
tempAddressList.add(addressModel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(AddressModel addressModel : addressList){
|
||||
if(!addressModel.getId().equals(newAddressId)){
|
||||
tempAddressList.add(addressModel);
|
||||
}
|
||||
}
|
||||
|
||||
addressList.clear();
|
||||
addressList.addAll(tempAddressList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ch.pizzalink.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26.10.2017.
|
||||
*/
|
||||
|
||||
public class AddNewAddressResponseModel {
|
||||
|
||||
@Expose @SerializedName("address_id") private String addressId;
|
||||
|
||||
public String getAddressId() {
|
||||
return addressId;
|
||||
}
|
||||
|
||||
public void setAddressId(String addressId) {
|
||||
this.addressId = addressId;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="ch.pizzalink.android.activity.AddAddressActivity">
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white"
|
||||
tools:context="ch.pizzalink.android.activity.AddAddressActivity"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true">
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
<ch.pizzalink.android.view.PizzalinkToolbar
|
||||
android:id="@+id/addAddressToolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/activity_title_add_address"
|
||||
android:background="@color/white"
|
||||
app:showBackIcon="true"
|
||||
app:titleTextColor="@color/black" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/addAddressToolbar">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white">
|
||||
|
||||
<ch.pizzalink.android.view.PizzalinkEditText
|
||||
android:id="@+id/address1PizzalinkEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:inputType="address"
|
||||
app:hint="@string/addres_line_1"/>
|
||||
|
||||
<ch.pizzalink.android.view.PizzalinkDropdownView
|
||||
android:id="@+id/cityPizzalinkDropdown"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:dropdownHintView="@string/city"/>
|
||||
|
||||
<ch.pizzalink.android.view.PizzalinkDropdownView
|
||||
android:id="@+id/postcodePizzalinkDrowpdown"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:dropdownHintView="@string/postcode"/>
|
||||
|
||||
<ch.pizzalink.android.view.PizzalinkDropdownView
|
||||
android:id="@+id/countryPizzalinkDropdown"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:dropdownHintView="@string/country"/>
|
||||
|
||||
<ch.pizzalink.android.view.PizzalinkDropdownView
|
||||
android:id="@+id/zonePizzalinkDropdown"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:dropdownHintView="@string/zone"/>
|
||||
|
||||
<android.support.v4.widget.Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/addNewAddressButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
style="@style/PizzalinkButton"
|
||||
android:text="@string/add"
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_above="@+id/addNewAddressButton"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/addNewAddressButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
style="@style/PizzalinkButton"
|
||||
android:text="@string/add_new_address"
|
||||
android:layout_above="@+id/ordersBottomLayout"/>
|
||||
|
||||
<include layout="@layout/layout_orders_bottom"/>
|
||||
|
||||
@@ -185,12 +185,17 @@
|
||||
|
||||
<!-- MyAddressesActivity-->
|
||||
<string name="activity_title_my_addresses">Adreslerim</string>
|
||||
<string name="add_new_address">EKLE</string>
|
||||
<string name="new_address_added">Adresiniz başarı ile eklendi.</string>
|
||||
<string name="add_new_address">YENİ ADRES EKLE</string>
|
||||
<string name="alert_delete_address">Adresinizi silmek istediğinize emin misiniz?</string>
|
||||
<string name="address_deleted">Adresiniz başarı ile silindi.</string>
|
||||
<!-- MyAddressesActivity-->
|
||||
|
||||
<!-- AddAddressActivity-->
|
||||
<string name="activity_title_add_address">Yeni Adres Ekle</string>
|
||||
<string name="add">KAYDET</string>
|
||||
<string name="new_address_added">Adresiniz başarı ile eklendi.</string>
|
||||
<!-- AddAddressActivity-->
|
||||
|
||||
<string-array name="stepperLabels">
|
||||
<item>Shipping Method</item>
|
||||
<item>Shipping Address</item>
|
||||
|
||||
Reference in New Issue
Block a user