|
|
@@ -1,18 +1,18 @@
|
|
|
package kr.co.zumo.app.lifeplus.view.fragment.faq;
|
|
|
|
|
|
-import android.content.Context;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import kr.co.zumo.app.R;
|
|
|
+import kr.co.zumo.app.lifeplus.bean.api.FAQBean;
|
|
|
|
|
|
/**
|
|
|
* FaqExpandableListViewAdapter
|
|
|
@@ -26,142 +26,65 @@ import kr.co.zumo.app.R;
|
|
|
*/
|
|
|
public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
|
- public static final int QUESTION = 1;
|
|
|
- public static final int ANSWER = 2;
|
|
|
- private List<Item> faqList;
|
|
|
- private LayoutInflater inflater;
|
|
|
+ private List<FAQBean> data;
|
|
|
+ private TextView textViewCategory;
|
|
|
+ private TextView textViewQuestion;
|
|
|
+ private ImageView buttonArrow;
|
|
|
+ private LinearLayout layoutAnswer;
|
|
|
+ private TextView textViewAnswer;
|
|
|
|
|
|
-
|
|
|
- public FAQExpandableListViewAdapter(List<Item> faqList) {
|
|
|
- this.faqList = faqList;
|
|
|
+ public FAQExpandableListViewAdapter(List<FAQBean> data) {
|
|
|
+ this.data = data;
|
|
|
}
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
- View view = null;
|
|
|
- Context context = parent.getContext();
|
|
|
-
|
|
|
- float dp = context.getResources().getDisplayMetrics().density;
|
|
|
- int subItemPaddingLeft = (int) (18 * dp);
|
|
|
- int subItemPaddingTopAndBottom = (int) (5 * dp);
|
|
|
-
|
|
|
- switch (viewType) {
|
|
|
- //카테고리 들어오면 question layout 부터 세팅
|
|
|
- case QUESTION:
|
|
|
- inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
- view = inflater.inflate(R.layout.faq_question_list, parent, false);
|
|
|
- FAQExpandableListViewViewHolder questionViewHolder = new FAQExpandableListViewViewHolder(view);
|
|
|
- return questionViewHolder;
|
|
|
- case ANSWER:
|
|
|
- TextView textViewAnswer = new TextView(context);
|
|
|
- textViewAnswer.setPadding(subItemPaddingLeft, subItemPaddingTopAndBottom, 0, subItemPaddingTopAndBottom);
|
|
|
- textViewAnswer.setTextColor(0x88000000);
|
|
|
- textViewAnswer.setLayoutParams(
|
|
|
- new ViewGroup.LayoutParams(
|
|
|
- ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
- ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
- return new RecyclerView.ViewHolder(textViewAnswer) {};
|
|
|
- default:
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
- return null;
|
|
|
+ View view = LayoutInflater
|
|
|
+ .from(parent.getContext())
|
|
|
+ .inflate(R.layout.faq_question_list, parent, false);
|
|
|
+ return new FAQExpandableViewHolder(view);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
|
|
- final Item item = faqList.get(position);
|
|
|
- switch (item.type) {
|
|
|
- case QUESTION:
|
|
|
- final FAQExpandableListViewViewHolder viewHolder = (FAQExpandableListViewViewHolder) holder;
|
|
|
- viewHolder.refferalItem = item;
|
|
|
- viewHolder.textViewCategory.setText(item.category);
|
|
|
- viewHolder.textViewQuestion.setText(item.contents);
|
|
|
- if (item.invisibleChildren == null) {
|
|
|
- viewHolder.buttonOpenArrow.setImageResource(R.drawable.icon_openarrow);
|
|
|
- }
|
|
|
- else {
|
|
|
- viewHolder.buttonOpenArrow.setImageResource(R.drawable.icon_closearrow);
|
|
|
- }
|
|
|
- viewHolder.buttonOpenArrow.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- if (item.invisibleChildren == null) {
|
|
|
- item.invisibleChildren = new ArrayList<Item>();
|
|
|
- int count = 0;
|
|
|
- int pos = faqList.indexOf(viewHolder.refferalItem);
|
|
|
- while (faqList.size() > pos + 1 && faqList.get(pos + 1).type == ANSWER) {
|
|
|
- item.invisibleChildren.add(faqList.remove(pos + 1));
|
|
|
- count++;
|
|
|
- }
|
|
|
- notifyItemRangeRemoved(pos + 1, count);
|
|
|
- viewHolder.buttonOpenArrow.setImageResource(R.drawable.icon_openarrow);
|
|
|
- }
|
|
|
- else {
|
|
|
- int pos = faqList.indexOf(viewHolder.refferalItem);
|
|
|
- int index = pos + 1;
|
|
|
- for (Item i : item.invisibleChildren) {
|
|
|
- faqList.add(index, i);
|
|
|
- index++;
|
|
|
- }
|
|
|
- notifyItemRangeInserted(pos + 1, index - pos - 1);
|
|
|
- viewHolder.buttonOpenArrow.setImageResource(R.drawable.icon_closearrow);
|
|
|
- item.invisibleChildren = null;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- break;
|
|
|
- case ANSWER:
|
|
|
- TextView textViewAnswer = (TextView) holder.itemView;
|
|
|
- textViewAnswer.setText(faqList.get(position).contents);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ FAQBean bean = data.get(position);
|
|
|
+ ((FAQExpandableViewHolder)holder).bind(bean);
|
|
|
+ ((FAQExpandableViewHolder)holder).itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ boolean isExpand = bean.isExpanded();
|
|
|
+ bean.setExpanded(!isExpand);
|
|
|
+ notifyItemChanged(position);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
- public int getItemViewType(int position) {
|
|
|
- return faqList.get(position).type;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getItemCount() {
|
|
|
- return faqList.size();
|
|
|
+ return data.size();
|
|
|
}
|
|
|
|
|
|
- private static class FAQExpandableListViewViewHolder extends RecyclerView.ViewHolder {
|
|
|
- public TextView textViewCategory;
|
|
|
- public TextView textViewQuestion;
|
|
|
- public TextView textViewAnswer;
|
|
|
- public ImageView buttonOpenArrow;
|
|
|
- public Item refferalItem;
|
|
|
+ private class FAQExpandableViewHolder extends RecyclerView.ViewHolder {
|
|
|
+
|
|
|
|
|
|
- public FAQExpandableListViewViewHolder(View itemView) {
|
|
|
+ public FAQExpandableViewHolder(View itemView) {
|
|
|
super(itemView);
|
|
|
textViewCategory = itemView.findViewById(R.id.faq_category);
|
|
|
textViewQuestion = itemView.findViewById(R.id.faq_question);
|
|
|
- textViewAnswer = itemView.findViewById(R.id.faq_answer);
|
|
|
- buttonOpenArrow = itemView.findViewById(R.id.button_open_arrow);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class Item {
|
|
|
- public int type;
|
|
|
- public String category;
|
|
|
- public String contents;
|
|
|
- public List<Item> invisibleChildren;
|
|
|
+ buttonArrow =itemView.findViewById(R.id.button_open_arrow);
|
|
|
+ layoutAnswer = itemView.findViewById(R.id.layout_answer);
|
|
|
+ textViewAnswer =itemView.findViewById(R.id.faq_answer);
|
|
|
|
|
|
- public Item() {
|
|
|
}
|
|
|
|
|
|
- public Item(int type, String category, String contents) {
|
|
|
- this.type = type;
|
|
|
- this.category = category;
|
|
|
- this.contents = contents;
|
|
|
+ private void bind(FAQBean faqBean) {
|
|
|
+ boolean expanded = faqBean.isExpanded();
|
|
|
+ layoutAnswer.setVisibility(expanded ? View.VISIBLE : View.GONE);
|
|
|
+ buttonArrow.setImageResource(expanded ? R.drawable.icon_closearrow : R.drawable.icon_openarrow);
|
|
|
+ textViewAnswer.setText(faqBean.getContents());
|
|
|
}
|
|
|
}
|
|
|
}
|