Browse Source

[FAQ][Common] FAQ 리싸이클러뷰 애니메이션 추가

Hasemi 7 years ago
parent
commit
4f5512bd81

+ 1 - 0
app/build.gradle

@@ -123,6 +123,7 @@ dependencies {
     implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
     implementation "android.arch.lifecycle:extensions:1.1.1"
     implementation "android.arch.lifecycle:viewmodel:1.1.1"
+    implementation 'com.github.aakira:expandable-layout:1.6.0@aar'
 
     /*********************************
      * UNIT TEST

+ 9 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/bean/api/FAQBean.java

@@ -44,6 +44,8 @@ public class FAQBean extends JsonBeanBase {
   @SerializedName("reg_dt")
   private String date;  // "yyyy-mm-dd"
 
+  private boolean isExpanded;
+
   public FAQBean() {
   }
 
@@ -95,4 +97,11 @@ public class FAQBean extends JsonBeanBase {
     this.date = date;
   }
 
+  public boolean isExpanded() {
+    return isExpanded;
+  }
+
+  public void setExpanded(boolean expanded) {
+    isExpanded = expanded;
+  }
 }

+ 12 - 9
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/faq/FAQExpandableListViewAdapter.java

@@ -2,13 +2,15 @@ package kr.co.zumo.app.lifeplus.view.fragment.faq;
 
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
+import android.util.SparseBooleanArray;
 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 com.github.aakira.expandablelayout.ExpandableRelativeLayout;
+
 import java.util.List;
 
 import kr.co.zumo.app.R;
@@ -27,6 +29,7 @@ import kr.co.zumo.app.lifeplus.bean.api.FAQBean;
 public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
 
   private List<FAQBean> data;
+  private SparseBooleanArray expandState = new SparseBooleanArray();
 
 
   public FAQExpandableListViewAdapter(List<FAQBean> data) {
@@ -47,15 +50,15 @@ public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerV
 
     FAQBean bean = data.get(position);
     ((FAQExpandableViewHolder) holder).bind(bean);
+    ((FAQExpandableViewHolder) holder).layoutAnswer.collapse();
     ((FAQExpandableViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View view) {
-
-        ((FAQExpandableViewHolder) holder).changed();
+        boolean isExpanded = bean.isExpanded();
+        bean.setExpanded(!isExpanded);
+        ((FAQExpandableViewHolder) holder).changed(bean.isExpanded());
       }
     });
-
-
   }
 
   @Override
@@ -68,7 +71,7 @@ public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerV
     private TextView textViewCategory;
     private TextView textViewQuestion;
     private ImageView buttonArrow;
-    private LinearLayout layoutAnswer;
+    private ExpandableRelativeLayout layoutAnswer;
     private TextView textViewAnswer;
 
     public FAQExpandableViewHolder(View itemView) {
@@ -88,9 +91,9 @@ public class FAQExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerV
 
     }
 
-    private void changed() {
-      layoutAnswer.setVisibility(layoutAnswer.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
-      buttonArrow.setImageResource(layoutAnswer.getVisibility() == View.VISIBLE ? R.drawable.icon_closearrow : R.drawable.icon_openarrow);
+    private void changed(boolean isExpanded) {
+      layoutAnswer.toggle();
+      buttonArrow.setImageResource(isExpanded ? R.drawable.icon_closearrow : R.drawable.icon_openarrow);
     }
   }
 }

+ 46 - 46
app/src/main/res/layout/faq_question_list.xml

@@ -1,68 +1,68 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
-  xmlns:tools="http://schemas.android.com/tools"
   xmlns:app="http://schemas.android.com/apk/res-auto"
+  xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@drawable/faq_answer_border"
   android:orientation="vertical">
 
-<RelativeLayout
-  android:layout_width="match_parent"
-  android:layout_height="wrap_content">
-  <TextView
-    android:id="@+id/faq_category"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:layout_alignParentStart="true"
-    android:layout_alignParentTop="true"
-    android:layout_marginStart="22dp"
-    android:layout_marginTop="22dp"
-    android:lineSpacingExtra="4sp"
-    android:textColor="@color/C999999"
-    android:textSize="10sp"
-    tools:text="회원"/>
+  <RelativeLayout
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
 
-  <TextView
-    android:id="@+id/faq_question"
-    android:layout_width="317dp"
-    android:layout_height="wrap_content"
-    android:layout_alignParentStart="true"
-    android:layout_alignParentTop="true"
-    android:layout_marginBottom="22dp"
+    <TextView
+      android:id="@+id/faq_category"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:layout_alignParentStart="true"
+      android:layout_alignParentTop="true"
+      android:layout_marginStart="22dp"
+      android:layout_marginTop="22dp"
+      android:lineSpacingExtra="4sp"
+      android:textColor="@color/C999999"
+      android:textSize="10sp"
+      tools:text="회원"/>
+
+    <TextView
+      android:id="@+id/faq_question"
+      android:layout_width="317dp"
+      android:layout_height="wrap_content"
+      android:layout_alignParentStart="true"
+      android:layout_alignParentTop="true"
+      android:layout_marginBottom="22dp"
 
-    android:layout_marginStart="22dp"
-    android:layout_marginTop="44dp"
-    android:lineSpacingExtra="5sp"
-    android:maxLines="3"
-    android:textColor="@color/C333333"
-    android:textSize="14sp"
-    android:layout_marginEnd="50dp"
-    tools:text="@string/sign_up_from_zumo_description"/>
+      android:layout_marginEnd="50dp"
+      android:layout_marginStart="22dp"
+      android:layout_marginTop="44dp"
+      android:lineSpacingExtra="5sp"
+      android:maxLines="3"
+      android:textColor="@color/C333333"
+      android:textSize="14sp"
+      tools:text="@string/sign_up_from_zumo_description"/>
 
-  <ImageView
-    android:id="@+id/button_open_arrow"
-    android:layout_width="21dp"
-    android:layout_height="wrap_content"
-    android:layout_alignParentEnd="true"
-    android:layout_centerVertical="true"
-    android:layout_marginEnd="20dp"
-    android:padding="5dp"
-    android:scaleType="center"
-    app:srcCompat="@drawable/icon_openarrow"/>
+    <ImageView
+      android:id="@+id/button_open_arrow"
+      android:layout_width="21dp"
+      android:layout_height="wrap_content"
+      android:layout_alignParentEnd="true"
+      android:layout_centerVertical="true"
+      android:layout_marginEnd="20dp"
+      android:padding="5dp"
+      android:scaleType="center"
+      app:srcCompat="@drawable/icon_openarrow"/>
 
 
-</RelativeLayout>
+  </RelativeLayout>
 
-  <LinearLayout
+  <com.github.aakira.expandablelayout.ExpandableRelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/layout_answer"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
-    android:visibility="gone"
-    tools:visibility="visible"
+    app:ael_expanded="false"
     >
 
     <LinearLayout
@@ -92,6 +92,6 @@
         />
 
     </LinearLayout>
-  </LinearLayout>
+  </com.github.aakira.expandablelayout.ExpandableRelativeLayout>
 
 </LinearLayout>

+ 4 - 4
app/src/main/res/layout/fragment_faq.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout
+<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
@@ -12,14 +12,14 @@
     android:id="@+id/expandable_list_view_faq"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:layout_marginBottom="10dp"
     android:layout_marginLeft="25dp"
-    android:layout_marginTop="25dp"
     android:layout_marginRight="25dp"
-    android:layout_marginBottom="10dp"
+    android:layout_marginTop="25dp"
     android:divider="@color/CFFFFFF"
     android:dividerHeight="50dp">
 
   </android.support.v7.widget.RecyclerView>
 
 
-</LinearLayout>
+</RelativeLayout>