|
|
|
|
@@ -9,6 +9,8 @@ import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
import butterknife.BindString;
|
|
|
|
|
@@ -49,10 +51,10 @@ public class ProductDetailsActivity extends BaseActivity {
|
|
|
|
|
@BindView(R.id.productPriceTextView) TextView productPriceTextView;
|
|
|
|
|
@BindView(R.id.productDescriptionTextView) TextView productDescriptionTextView;
|
|
|
|
|
@BindView(R.id.addToCartButton) Button addToCartButton;
|
|
|
|
|
@BindView(R.id.radioRecyclerHeaderTextView) TextView radioRecyclerHeaderTextView;
|
|
|
|
|
@BindView(R.id.radioRecyclerView) RecyclerView radioRecyclerView;
|
|
|
|
|
@BindView(R.id.checkboxRecyclerHeaderTextView) TextView checkboxRecyclerHeaderTextView;
|
|
|
|
|
@BindView(R.id.checkboxRecyclerView) RecyclerView checkboxRecyclerView;
|
|
|
|
|
@BindView(R.id.recycler1HeaderTextView) TextView recycler1HeaderTextView;
|
|
|
|
|
@BindView(R.id.recyclerView1) RecyclerView recyclerView1;
|
|
|
|
|
@BindView(R.id.recycler2HeaderTextView) TextView recycler2HeaderTextView;
|
|
|
|
|
@BindView(R.id.recyclerView2) RecyclerView recyclerView2;
|
|
|
|
|
@BindView(R.id.increaseProductCountImageView) ImageView increaseProductCountImageView;
|
|
|
|
|
@BindView(R.id.deccreaseProductCountImageView) ImageView deccreaseProductCountImageView;
|
|
|
|
|
@BindView(R.id.productCountTextView) TextView productCountTextView;
|
|
|
|
|
@@ -63,11 +65,6 @@ public class ProductDetailsActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
private MenuProductModel menuProductModel;
|
|
|
|
|
|
|
|
|
|
private ArrayList<MenuProductOptionValueModel> productRadioOptionValueList = new ArrayList<>();
|
|
|
|
|
private ArrayList<MenuProductOptionValueModel> productCheckboxOptionValueList = new ArrayList<>();
|
|
|
|
|
private ProductRadioOptionsRecyclerAdapter productRadioOptionsRecyclerAdapter;
|
|
|
|
|
private ProductCheckboxOptionsRecyclerAdapter productCheckboxOptionsRecyclerAdapter;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
@@ -159,74 +156,88 @@ public class ProductDetailsActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
private void initViews(){
|
|
|
|
|
setFields();
|
|
|
|
|
fillRadioAndCheckboxOptionLists();
|
|
|
|
|
switch (menuProductModel.getProductOptionType()){
|
|
|
|
|
case RADIO_AND_CHECKBOX:
|
|
|
|
|
radioRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
checkboxRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
radioRecyclerHeaderTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
checkboxRecyclerHeaderTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
initRadioRecyclerView();
|
|
|
|
|
initCheckboxRecyclerView();
|
|
|
|
|
break;
|
|
|
|
|
case RADIO:
|
|
|
|
|
radioRecyclerHeaderTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
radioRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
checkboxRecyclerView.setVisibility(View.GONE);
|
|
|
|
|
checkboxRecyclerHeaderTextView.setVisibility(View.GONE);
|
|
|
|
|
initRadioRecyclerView();
|
|
|
|
|
break;
|
|
|
|
|
case CHECKBOX:
|
|
|
|
|
radioRecyclerHeaderTextView.setVisibility(View.GONE);
|
|
|
|
|
radioRecyclerView.setVisibility(View.GONE);
|
|
|
|
|
checkboxRecyclerHeaderTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
checkboxRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
initCheckboxRecyclerView();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
initRecyclerViews();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMenuProductModel(MenuProductModel menuProductModel){
|
|
|
|
|
this.menuProductModel = menuProductModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initRadioRecyclerView(){
|
|
|
|
|
radioRecyclerView.setNestedScrollingEnabled(false);
|
|
|
|
|
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
|
|
|
|
|
radioRecyclerView.setLayoutManager(gridLayoutManager);
|
|
|
|
|
productRadioOptionsRecyclerAdapter = new ProductRadioOptionsRecyclerAdapter(productRadioOptionValueList, new RecyclerItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
|
if(!productRadioOptionValueList.get(position).isSelected()){
|
|
|
|
|
for(MenuProductOptionValueModel menuProductOptionValueModel : productRadioOptionValueList){
|
|
|
|
|
menuProductOptionValueModel.setSelected(false);
|
|
|
|
|
}
|
|
|
|
|
productRadioOptionValueList.get(position).setSelected(true);
|
|
|
|
|
productRadioOptionsRecyclerAdapter.notifyDataSetChanged();
|
|
|
|
|
productPriceTextView.setText(PriceHelper.calculatePriceAfterRadioOptionValueChanged(
|
|
|
|
|
productCount, menuProductModel, productRadioOptionValueList.get(position)));
|
|
|
|
|
}
|
|
|
|
|
private void initRecyclerViews(){
|
|
|
|
|
fixRadioAndCheckbox();
|
|
|
|
|
for(int i = 0; i < menuProductModel.getProductOptionList().size(); i++){
|
|
|
|
|
MenuProductOptionModel menuProductOptionModel = menuProductModel.getProductOptionList().get(i);
|
|
|
|
|
setSelectedPriceShowingOptions(menuProductOptionModel);
|
|
|
|
|
switch (i){
|
|
|
|
|
case 0:
|
|
|
|
|
initRecyclerView(
|
|
|
|
|
recycler1HeaderTextView,
|
|
|
|
|
recyclerView1,
|
|
|
|
|
menuProductOptionModel);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
initRecyclerView(
|
|
|
|
|
recycler2HeaderTextView,
|
|
|
|
|
recyclerView2,
|
|
|
|
|
menuProductOptionModel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
radioRecyclerView.setAdapter(productRadioOptionsRecyclerAdapter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initCheckboxRecyclerView(){
|
|
|
|
|
checkboxRecyclerView.setNestedScrollingEnabled(false);
|
|
|
|
|
private void initRecyclerView(TextView headerTextView,
|
|
|
|
|
RecyclerView recyclerView,
|
|
|
|
|
final MenuProductOptionModel menuProductOptionModel){
|
|
|
|
|
headerTextView.setText(menuProductOptionModel.getName());
|
|
|
|
|
recyclerView.setNestedScrollingEnabled(false);
|
|
|
|
|
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
|
|
|
|
|
checkboxRecyclerView.setLayoutManager(gridLayoutManager);
|
|
|
|
|
productCheckboxOptionsRecyclerAdapter = new ProductCheckboxOptionsRecyclerAdapter(productCheckboxOptionValueList, new RecyclerItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
|
productCheckboxOptionValueList.get(position).setSelected(
|
|
|
|
|
!productCheckboxOptionValueList.get(position).isSelected());
|
|
|
|
|
productCheckboxOptionsRecyclerAdapter.notifyItemChanged(position);
|
|
|
|
|
productPriceTextView.setText(
|
|
|
|
|
PriceHelper.calculatePriceAfterCheckboxOptionValueChanged(
|
|
|
|
|
productCount, menuProductModel, productCheckboxOptionValueList));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
checkboxRecyclerView.setAdapter(productCheckboxOptionsRecyclerAdapter);
|
|
|
|
|
recyclerView.setLayoutManager(gridLayoutManager);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(menuProductOptionModel.getType().toLowerCase().equals("radio") ||
|
|
|
|
|
menuProductOptionModel.getType().toLowerCase().equals("select")){
|
|
|
|
|
|
|
|
|
|
final ProductRadioOptionsRecyclerAdapter productRadioOptionsRecyclerAdapter =
|
|
|
|
|
new ProductRadioOptionsRecyclerAdapter(menuProductOptionModel.getOptionValueModelList());
|
|
|
|
|
productRadioOptionsRecyclerAdapter.setRecyclerItemClickListener(new RecyclerItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
|
ArrayList<MenuProductOptionValueModel> optionValueList = menuProductOptionModel.getOptionValueModelList();
|
|
|
|
|
if(!optionValueList.get(position).isSelected()){
|
|
|
|
|
for(MenuProductOptionValueModel menuProductOptionValueModel : optionValueList){
|
|
|
|
|
menuProductOptionValueModel.setSelected(false);
|
|
|
|
|
}
|
|
|
|
|
optionValueList.get(position).setSelected(true);
|
|
|
|
|
productRadioOptionsRecyclerAdapter.notifyDataSetChanged();
|
|
|
|
|
productPriceTextView.setText(PriceHelper.calculatePriceAfterRadioOptionValueChanged(
|
|
|
|
|
productCount, menuProductModel, optionValueList.get(position)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
recyclerView.setAdapter(productRadioOptionsRecyclerAdapter);
|
|
|
|
|
headerTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
final ProductCheckboxOptionsRecyclerAdapter productCheckboxOptionsRecyclerAdapter =
|
|
|
|
|
new ProductCheckboxOptionsRecyclerAdapter(menuProductOptionModel.getOptionValueModelList());
|
|
|
|
|
productCheckboxOptionsRecyclerAdapter.setRecyclerItemClickListener(new RecyclerItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
|
ArrayList<MenuProductOptionValueModel> optionValueList = menuProductOptionModel.getOptionValueModelList();
|
|
|
|
|
optionValueList.get(position).setSelected(
|
|
|
|
|
!optionValueList.get(position).isSelected());
|
|
|
|
|
productCheckboxOptionsRecyclerAdapter.notifyItemChanged(position);
|
|
|
|
|
productPriceTextView.setText(
|
|
|
|
|
PriceHelper.calculatePriceAfterCheckboxOptionValueChanged(
|
|
|
|
|
productCount, menuProductModel, optionValueList));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
recyclerView.setAdapter(productCheckboxOptionsRecyclerAdapter);
|
|
|
|
|
headerTextView.setVisibility(View.VISIBLE);
|
|
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setFields(){
|
|
|
|
|
@@ -237,20 +248,17 @@ public class ProductDetailsActivity extends BaseActivity {
|
|
|
|
|
productPriceTextView.setText(PriceHelper.getPriceWithCurreny(menuProductModel.getPrice()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillRadioAndCheckboxOptionLists(){
|
|
|
|
|
for(MenuProductOptionModel menuProductOptionModel : menuProductModel.getProductOptionList()){
|
|
|
|
|
setSelectedPriceShowingOptions(menuProductOptionModel);
|
|
|
|
|
|
|
|
|
|
if(menuProductOptionModel.getType().toLowerCase().equals("radio") ||
|
|
|
|
|
menuProductOptionModel.getType().toLowerCase().equals("select")){
|
|
|
|
|
radioRecyclerHeaderTextView.setText(menuProductOptionModel.getName());
|
|
|
|
|
productRadioOptionValueList.addAll(menuProductOptionModel.getOptionValueModelList());
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
checkboxRecyclerHeaderTextView.setText(menuProductOptionModel.getName());
|
|
|
|
|
productCheckboxOptionValueList.addAll(menuProductOptionModel.getOptionValueModelList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void fixRadioAndCheckbox(){
|
|
|
|
|
ArrayList<MenuProductOptionModel> sortedOptionList = menuProductModel.getProductOptionList();
|
|
|
|
|
Collections.sort(
|
|
|
|
|
sortedOptionList,
|
|
|
|
|
new Comparator<MenuProductOptionModel>() {
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(MenuProductOptionModel o1, MenuProductOptionModel o2) {
|
|
|
|
|
return o2.getType().compareTo(o1.getType());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
menuProductModel.setProductOptionList(sortedOptionList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setSelectedPriceShowingOptions(MenuProductOptionModel menuProductOptionModel){
|
|
|
|
|
@@ -388,21 +396,15 @@ public class ProductDetailsActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkFields(){
|
|
|
|
|
|
|
|
|
|
if(radioRecyclerView.getVisibility() == View.VISIBLE &&
|
|
|
|
|
!isSelectedAtLeastOne(productRadioOptionValueList)){
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity,
|
|
|
|
|
radioRecyclerHeaderTextView.getText().toString() + " " + noOptionsSelectedText);
|
|
|
|
|
return false;
|
|
|
|
|
for(int i = 0; i < menuProductModel.getProductOptionList().size(); i++){
|
|
|
|
|
MenuProductOptionModel menuProductOptionValueModel = menuProductModel.getProductOptionList().get(i);
|
|
|
|
|
boolean isRadio = menuProductOptionValueModel.getType().toLowerCase().equals("radio") || menuProductOptionValueModel.getType().toLowerCase().equals("select");
|
|
|
|
|
if(!isSelectedAtLeastOne(menuProductModel.getProductOptionList().get(i).getOptionValueModelList())){
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity,
|
|
|
|
|
menuProductModel.getProductOptionList().get(i).getName() + " " + noOptionsSelectedText);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(checkboxRecyclerView.getVisibility() == View.VISIBLE &&
|
|
|
|
|
!isSelectedAtLeastOne(productCheckboxOptionValueList)){
|
|
|
|
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity,
|
|
|
|
|
checkboxRecyclerHeaderTextView.getText().toString() + " " + noOptionsSelectedText);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|