radio and checkbox recyclerview changed to dynamic type for campaign product details
This commit is contained in:
@@ -9,6 +9,8 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import butterknife.BindString;
|
import butterknife.BindString;
|
||||||
@@ -50,10 +52,10 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
|||||||
@BindView(R.id.productPriceTextView) TextView productPriceTextView;
|
@BindView(R.id.productPriceTextView) TextView productPriceTextView;
|
||||||
@BindView(R.id.productDescriptionTextView) TextView productDescriptionTextView;
|
@BindView(R.id.productDescriptionTextView) TextView productDescriptionTextView;
|
||||||
@BindView(R.id.addToCartButton) Button addToCartButton;
|
@BindView(R.id.addToCartButton) Button addToCartButton;
|
||||||
@BindView(R.id.radioRecyclerHeaderTextView) TextView radioRecyclerHeaderTextView;
|
@BindView(R.id.recycler1HeaderTextView) TextView recycler1HeaderTextView;
|
||||||
@BindView(R.id.radioRecyclerView) RecyclerView radioRecyclerView;
|
@BindView(R.id.recyclerView1) RecyclerView recyclerView1;
|
||||||
@BindView(R.id.checkboxRecyclerHeaderTextView) TextView checkboxRecyclerHeaderTextView;
|
@BindView(R.id.recycler2HeaderTextView) TextView recycler2HeaderTextView;
|
||||||
@BindView(R.id.checkboxRecyclerView) RecyclerView checkboxRecyclerView;
|
@BindView(R.id.recyclerView2) RecyclerView recyclerView2;
|
||||||
@BindView(R.id.increaseProductCountImageView) ImageView increaseProductCountImageView;
|
@BindView(R.id.increaseProductCountImageView) ImageView increaseProductCountImageView;
|
||||||
@BindView(R.id.deccreaseProductCountImageView) ImageView deccreaseProductCountImageView;
|
@BindView(R.id.deccreaseProductCountImageView) ImageView deccreaseProductCountImageView;
|
||||||
@BindView(R.id.productCountTextView) TextView productCountTextView;
|
@BindView(R.id.productCountTextView) TextView productCountTextView;
|
||||||
@@ -64,11 +66,6 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
|||||||
private int productCount = 1;
|
private int productCount = 1;
|
||||||
|
|
||||||
private MenuProductModel menuProductModel;
|
private MenuProductModel menuProductModel;
|
||||||
|
|
||||||
private ArrayList<MenuProductOptionValueModel> productRadioOptionValueList = new ArrayList<>();
|
|
||||||
private ArrayList<MenuProductOptionValueModel> productCheckboxOptionValueList = new ArrayList<>();
|
|
||||||
private ProductRadioOptionsRecyclerAdapter productRadioOptionsRecyclerAdapter;
|
|
||||||
private ProductCheckboxOptionsRecyclerAdapter productCheckboxOptionsRecyclerAdapter;
|
|
||||||
private CampaignModel campaignModel;
|
private CampaignModel campaignModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -155,76 +152,91 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
|||||||
menuProductModel = (MenuProductModel) getIntent().getSerializableExtra("menuProductModel");
|
menuProductModel = (MenuProductModel) getIntent().getSerializableExtra("menuProductModel");
|
||||||
campaignModel = (CampaignModel) getIntent().getSerializableExtra("campaignModel");
|
campaignModel = (CampaignModel) getIntent().getSerializableExtra("campaignModel");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initViews(){
|
private void initViews(){
|
||||||
setFields();
|
setFields();
|
||||||
fillRadioAndCheckboxOptionLists();
|
initRecyclerViews();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMenuProductModel(MenuProductModel menuProductModel){
|
public void setMenuProductModel(MenuProductModel menuProductModel){
|
||||||
this.menuProductModel = menuProductModel;
|
this.menuProductModel = menuProductModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initRadioRecyclerView(){
|
private void initRecyclerViews(){
|
||||||
radioRecyclerView.setNestedScrollingEnabled(false);
|
fixRadioAndCheckbox();
|
||||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
|
for(int i = 0; i < menuProductModel.getProductOptionList().size(); i++){
|
||||||
radioRecyclerView.setLayoutManager(gridLayoutManager);
|
MenuProductOptionModel menuProductOptionModel = menuProductModel.getProductOptionList().get(i);
|
||||||
productRadioOptionsRecyclerAdapter = new ProductRadioOptionsRecyclerAdapter(productRadioOptionValueList, new RecyclerItemClickListener() {
|
setSelectedPriceShowingOptions(menuProductOptionModel);
|
||||||
@Override
|
switch (i){
|
||||||
public void onItemClick(View view, int position) {
|
case 0:
|
||||||
if(!productRadioOptionValueList.get(position).isSelected()){
|
initRecyclerView(
|
||||||
for(MenuProductOptionValueModel menuProductOptionValueModel : productRadioOptionValueList){
|
recycler1HeaderTextView,
|
||||||
menuProductOptionValueModel.setSelected(false);
|
recyclerView1,
|
||||||
}
|
menuProductOptionModel);
|
||||||
productRadioOptionValueList.get(position).setSelected(true);
|
break;
|
||||||
productRadioOptionsRecyclerAdapter.notifyDataSetChanged();
|
case 1:
|
||||||
productPriceTextView.setText(PriceHelper.calculatePriceAfterRadioOptionValueChanged(
|
initRecyclerView(
|
||||||
productCount, menuProductModel, productRadioOptionValueList.get(position)));
|
recycler2HeaderTextView,
|
||||||
}
|
recyclerView2,
|
||||||
|
menuProductOptionModel);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
radioRecyclerView.setAdapter(productRadioOptionsRecyclerAdapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCheckboxRecyclerView(){
|
private void initRecyclerView(TextView headerTextView,
|
||||||
checkboxRecyclerView.setNestedScrollingEnabled(false);
|
RecyclerView recyclerView,
|
||||||
|
final MenuProductOptionModel menuProductOptionModel){
|
||||||
|
headerTextView.setText(menuProductOptionModel.getName());
|
||||||
|
recyclerView.setNestedScrollingEnabled(false);
|
||||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
|
GridLayoutManager gridLayoutManager = new GridLayoutManager(BaseActivity.currentActivity, 1);
|
||||||
checkboxRecyclerView.setLayoutManager(gridLayoutManager);
|
recyclerView.setLayoutManager(gridLayoutManager);
|
||||||
productCheckboxOptionsRecyclerAdapter = new ProductCheckboxOptionsRecyclerAdapter(productCheckboxOptionValueList, new RecyclerItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(View view, int position) {
|
if(menuProductOptionModel.getType().toLowerCase().equals("radio") ||
|
||||||
productCheckboxOptionValueList.get(position).setSelected(
|
menuProductOptionModel.getType().toLowerCase().equals("select")){
|
||||||
!productCheckboxOptionValueList.get(position).isSelected());
|
|
||||||
productCheckboxOptionsRecyclerAdapter.notifyItemChanged(position);
|
final ProductRadioOptionsRecyclerAdapter productRadioOptionsRecyclerAdapter =
|
||||||
productPriceTextView.setText(
|
new ProductRadioOptionsRecyclerAdapter(menuProductOptionModel.getOptionValueModelList());
|
||||||
PriceHelper.calculatePriceAfterCheckboxOptionValueChanged(
|
productRadioOptionsRecyclerAdapter.setRecyclerItemClickListener(new RecyclerItemClickListener() {
|
||||||
productCount, menuProductModel, productCheckboxOptionValueList));
|
@Override
|
||||||
}
|
public void onItemClick(View view, int position) {
|
||||||
});
|
ArrayList<MenuProductOptionValueModel> optionValueList = menuProductOptionModel.getOptionValueModelList();
|
||||||
checkboxRecyclerView.setAdapter(productCheckboxOptionsRecyclerAdapter);
|
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(){
|
private void setFields(){
|
||||||
@@ -235,20 +247,17 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
|||||||
productPriceTextView.setText(PriceHelper.getPriceWithCurreny(menuProductModel.getPrice()));
|
productPriceTextView.setText(PriceHelper.getPriceWithCurreny(menuProductModel.getPrice()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillRadioAndCheckboxOptionLists(){
|
private void fixRadioAndCheckbox(){
|
||||||
for(MenuProductOptionModel menuProductOptionModel : menuProductModel.getProductOptionList()){
|
ArrayList<MenuProductOptionModel> sortedOptionList = menuProductModel.getProductOptionList();
|
||||||
setSelectedPriceShowingOptions(menuProductOptionModel);
|
Collections.sort(
|
||||||
|
sortedOptionList,
|
||||||
if(menuProductOptionModel.getType().toLowerCase().equals("radio") ||
|
new Comparator<MenuProductOptionModel>() {
|
||||||
menuProductOptionModel.getType().toLowerCase().equals("select")){
|
@Override
|
||||||
radioRecyclerHeaderTextView.setText(menuProductOptionModel.getName());
|
public int compare(MenuProductOptionModel o1, MenuProductOptionModel o2) {
|
||||||
productRadioOptionValueList.addAll(menuProductOptionModel.getOptionValueModelList());
|
return o2.getType().compareTo(o1.getType());
|
||||||
}
|
}
|
||||||
else{
|
});
|
||||||
checkboxRecyclerHeaderTextView.setText(menuProductOptionModel.getName());
|
menuProductModel.setProductOptionList(sortedOptionList);
|
||||||
productCheckboxOptionValueList.addAll(menuProductOptionModel.getOptionValueModelList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSelectedPriceShowingOptions(MenuProductOptionModel menuProductOptionModel){
|
private void setSelectedPriceShowingOptions(MenuProductOptionModel menuProductOptionModel){
|
||||||
@@ -391,21 +400,15 @@ public class CampaignProductDetailsActivity extends BaseActivity {
|
|||||||
|
|
||||||
|
|
||||||
private boolean checkFields(){
|
private boolean checkFields(){
|
||||||
|
for(int i = 0; i < menuProductModel.getProductOptionList().size(); i++){
|
||||||
if(radioRecyclerView.getVisibility() == View.VISIBLE &&
|
MenuProductOptionModel menuProductOptionValueModel = menuProductModel.getProductOptionList().get(i);
|
||||||
!isSelectedAtLeastOne(productRadioOptionValueList)){
|
boolean isRadio = menuProductOptionValueModel.getType().toLowerCase().equals("radio") || menuProductOptionValueModel.getType().toLowerCase().equals("select");
|
||||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity,
|
if(!isSelectedAtLeastOne(menuProductModel.getProductOptionList().get(i).getOptionValueModelList())){
|
||||||
radioRecyclerHeaderTextView.getText().toString() + " " + noOptionsSelectedText);
|
DialogHelper.showAlertDialog(BaseActivity.currentActivity,
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import ch.pizzamaxx.android.helper.SharedPrefsHelper;
|
|||||||
import ch.pizzamaxx.android.helper.TextHelper;
|
import ch.pizzamaxx.android.helper.TextHelper;
|
||||||
import ch.pizzamaxx.android.interfaces.RecyclerItemClickListener;
|
import ch.pizzamaxx.android.interfaces.RecyclerItemClickListener;
|
||||||
import ch.pizzamaxx.android.model.AddProductToBasketResponseModel;
|
import ch.pizzamaxx.android.model.AddProductToBasketResponseModel;
|
||||||
|
import ch.pizzamaxx.android.model.CampaignModel;
|
||||||
import ch.pizzamaxx.android.model.cart.CartInfoModel;
|
import ch.pizzamaxx.android.model.cart.CartInfoModel;
|
||||||
import ch.pizzamaxx.android.model.menu.MenuProductModel;
|
import ch.pizzamaxx.android.model.menu.MenuProductModel;
|
||||||
import ch.pizzamaxx.android.model.menu.MenuProductOptionModel;
|
import ch.pizzamaxx.android.model.menu.MenuProductOptionModel;
|
||||||
@@ -64,6 +65,7 @@ public class ProductDetailsActivity extends BaseActivity {
|
|||||||
private int productCount = 1;
|
private int productCount = 1;
|
||||||
|
|
||||||
private MenuProductModel menuProductModel;
|
private MenuProductModel menuProductModel;
|
||||||
|
private CampaignModel campaignModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -210,7 +210,7 @@
|
|||||||
android:layout_marginEnd="12dp"/>
|
android:layout_marginEnd="12dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/radioRecyclerHeaderTextView"
|
android:id="@+id/recycler1HeaderTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
fontPath="fonts/Quicksand-Bold.ttf"
|
fontPath="fonts/Quicksand-Bold.ttf"
|
||||||
@@ -221,7 +221,7 @@
|
|||||||
android:textColor="@color/black"/>
|
android:textColor="@color/black"/>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/radioRecyclerView"
|
android:id="@+id/recyclerView1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
android:layout_marginEnd="12dp"/>
|
android:layout_marginEnd="12dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/checkboxRecyclerHeaderTextView"
|
android:id="@+id/recycler2HeaderTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
fontPath="fonts/Quicksand-Bold.ttf"
|
fontPath="fonts/Quicksand-Bold.ttf"
|
||||||
@@ -246,7 +246,7 @@
|
|||||||
android:textColor="@color/black"/>
|
android:textColor="@color/black"/>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/checkboxRecyclerView"
|
android:id="@+id/recyclerView2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user