|
|
@@ -1,16 +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.BaseExpandableListAdapter;
|
|
|
+import android.widget.ImageView;
|
|
|
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
|
|
|
@@ -22,75 +24,144 @@ import kr.co.zumo.app.lifeplus.bean.api.FAQBean;
|
|
|
* @history 하세미 [2018-10-01] [최초 작성]
|
|
|
* @since 2018-10-01
|
|
|
*/
|
|
|
-public class FAQExpandableListViewAdapter extends BaseExpandableListAdapter {
|
|
|
+public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
|
- private Context context;
|
|
|
- private ArrayList<FAQBean> faqList;
|
|
|
- private LayoutInflater inflater = null;
|
|
|
+ public static final int QUESTION = 1;
|
|
|
+ public static final int ANSWER = 2;
|
|
|
+ private List<Item> faqList;
|
|
|
+ private LayoutInflater inflater;
|
|
|
|
|
|
- public FAQExpandableListViewAdapter(Context context, ArrayList<FAQBean> faqList) {
|
|
|
- this.context = context;
|
|
|
+
|
|
|
+ public FAQExpandableListViewAdapter(List<Item> faqList) {
|
|
|
this.faqList = faqList;
|
|
|
- this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
}
|
|
|
|
|
|
+ @NonNull
|
|
|
@Override
|
|
|
- public int getGroupCount() {
|
|
|
- return faqList.size();
|
|
|
- }
|
|
|
+ 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;
|
|
|
|
|
|
- @Override
|
|
|
- public int getChildrenCount(int i) {
|
|
|
- return faqList.size();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object getGroup(int i) {
|
|
|
- return faqList.get(i);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Object getChild(int i, int i1) {
|
|
|
- return faqList.get(i);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
- public long getGroupId(int i) {
|
|
|
- return i;
|
|
|
+ public int getItemViewType(int position) {
|
|
|
+ return faqList.get(position).type;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public long getChildId(int i, int i1) {
|
|
|
- return i1;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean hasStableIds() {
|
|
|
- return true;
|
|
|
+ public int getItemCount() {
|
|
|
+ return faqList.size();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup parent) {
|
|
|
- if (view == null) {
|
|
|
- view = inflater.inflate(R.layout.faq_question_list, parent, false);
|
|
|
+ private static class FAQExpandableListViewViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ public TextView textViewCategory;
|
|
|
+ public TextView textViewQuestion;
|
|
|
+ public TextView textViewAnswer;
|
|
|
+ public ImageView buttonOpenArrow;
|
|
|
+ public Item refferalItem;
|
|
|
+
|
|
|
+ public FAQExpandableListViewViewHolder(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);
|
|
|
}
|
|
|
- TextView textViewQuestion = (TextView) view.findViewById(R.id.faq_question);
|
|
|
- textViewQuestion.setText(faqList.get(groupPosition).getTitle());
|
|
|
- return view;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public View getChildView(int groupPosition, int childPosition, boolean isExpanded, View view, ViewGroup parent) {
|
|
|
- if (view == null) {
|
|
|
- view = inflater.inflate(R.layout.faq_answer_list, parent, false);
|
|
|
+ public static class Item {
|
|
|
+ public int type;
|
|
|
+ public String category;
|
|
|
+ public String contents;
|
|
|
+ public List<Item> invisibleChildren;
|
|
|
+
|
|
|
+ public Item() {
|
|
|
}
|
|
|
- TextView textViewAnswer = (TextView) view.findViewById(R.id.faq_answer);
|
|
|
- textViewAnswer.setText(faqList.get(0).getContents());
|
|
|
- return view;
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public boolean isChildSelectable(int i, int i1) {
|
|
|
- return false;
|
|
|
+ public Item(int type, String category, String contents) {
|
|
|
+ this.type = type;
|
|
|
+ this.category = category;
|
|
|
+ this.contents = contents;
|
|
|
+ }
|
|
|
}
|
|
|
}
|