radio and checkbox recyclerview changed to dynamic type
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;
|
||||||
@@ -49,10 +51,10 @@ public class ProductDetailsActivity 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;
|
||||||
@@ -63,11 +65,6 @@ public class ProductDetailsActivity extends BaseActivity {
|
|||||||
|
|
||||||
private MenuProductModel menuProductModel;
|
private MenuProductModel menuProductModel;
|
||||||
|
|
||||||
private ArrayList<MenuProductOptionValueModel> productRadioOptionValueList = new ArrayList<>();
|
|
||||||
private ArrayList<MenuProductOptionValueModel> productCheckboxOptionValueList = new ArrayList<>();
|
|
||||||
private ProductRadioOptionsRecyclerAdapter productRadioOptionsRecyclerAdapter;
|
|
||||||
private ProductCheckboxOptionsRecyclerAdapter productCheckboxOptionsRecyclerAdapter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -159,74 +156,88 @@ public class ProductDetailsActivity extends BaseActivity {
|
|||||||
|
|
||||||
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(){
|
||||||
@@ -237,20 +248,17 @@ public class ProductDetailsActivity 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){
|
||||||
@@ -388,21 +396,15 @@ public class ProductDetailsActivity 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ public class ProductCheckboxOptionsRecyclerAdapter extends RecyclerView.Adapter<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductCheckboxOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList, RecyclerItemClickListener recyclerItemClickListener){
|
public ProductCheckboxOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList){
|
||||||
|
this.productOptionValueList = productOptionValueList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductCheckboxOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList,
|
||||||
|
RecyclerItemClickListener recyclerItemClickListener){
|
||||||
this.productOptionValueList = productOptionValueList;
|
this.productOptionValueList = productOptionValueList;
|
||||||
this.recyclerItemClickListener = recyclerItemClickListener;
|
this.recyclerItemClickListener = recyclerItemClickListener;
|
||||||
}
|
}
|
||||||
@@ -67,4 +72,8 @@ public class ProductCheckboxOptionsRecyclerAdapter extends RecyclerView.Adapter<
|
|||||||
return productOptionValueList.size();
|
return productOptionValueList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRecyclerItemClickListener(RecyclerItemClickListener recyclerItemClickListener){
|
||||||
|
this.recyclerItemClickListener = recyclerItemClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,12 @@ public class ProductRadioOptionsRecyclerAdapter extends RecyclerView.Adapter<Pro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProductRadioOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList, RecyclerItemClickListener recyclerItemClickListener){
|
public ProductRadioOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList){
|
||||||
|
this.productOptionValueList = productOptionValueList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductRadioOptionsRecyclerAdapter(ArrayList<MenuProductOptionValueModel> productOptionValueList,
|
||||||
|
RecyclerItemClickListener recyclerItemClickListener){
|
||||||
this.productOptionValueList = productOptionValueList;
|
this.productOptionValueList = productOptionValueList;
|
||||||
this.recyclerItemClickListener = recyclerItemClickListener;
|
this.recyclerItemClickListener = recyclerItemClickListener;
|
||||||
}
|
}
|
||||||
@@ -68,4 +73,8 @@ public class ProductRadioOptionsRecyclerAdapter extends RecyclerView.Adapter<Pro
|
|||||||
return productOptionValueList.size();
|
return productOptionValueList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRecyclerItemClickListener(RecyclerItemClickListener recyclerItemClickListener){
|
||||||
|
this.recyclerItemClickListener = recyclerItemClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,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"
|
||||||
@@ -218,7 +218,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"/>
|
||||||
@@ -233,7 +233,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"
|
||||||
@@ -243,7 +243,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