Parcourir la source

[검색][New] 로직 보강
- 필터 취소 시 데이터가 반영되는 버그 수정

hyodong.min il y a 6 ans
Parent
commit
2053120322

+ 18 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/SearchFilterDetailDialog.java

@@ -4,6 +4,7 @@ import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.constraint.ConstraintLayout;
+import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -67,11 +68,13 @@ public class SearchFilterDetailDialog extends DialogBase<ISearchFilterListener<S
    */
   public void setFilterDetail(List<FilterTagBean> tagBeans, List<SearchFilterBean> selectedList, String title, boolean isMultiSelection, String filterType, String filterNo) {
     this.tagBeans = tagBeans;
-    this.isMultiSelection = isMultiSelection;
+    if(null != selectedList) {
+      this.selectedList = new ArrayList<>(selectedList);  // 데이터를 복제해서 사용, 내부에서 배열을 변형(추가/삭제)한다. 외부로 전달은 배열 자체를 한다.
+    }
     this.title = title;
+    this.isMultiSelection = isMultiSelection;
     this.filterType = filterType;
     this.filterNo = filterNo;
-    this.selectedList = selectedList;
   }
 
   @Nullable
@@ -197,7 +200,8 @@ public class SearchFilterDetailDialog extends DialogBase<ISearchFilterListener<S
       // filterNo 로 부모를 구분한다.
       // filterType 으로 적용할 데이터를 선택
       // 핫플레이스는 filter name, 지역은 tagNo 를 api 에 이용한다.
-      filterMap.put(checkBox, new SearchFilterBean(tagName, filterType, filterNo, SearchFilterBean.FILTER_LEVEL_DETAIL, tagNo));
+      SearchFilterBean bean = new SearchFilterBean(tagName, filterType, filterNo, SearchFilterBean.FILTER_LEVEL_DETAIL, tagNo);
+      filterMap.put(checkBox, bean);
 
       if (isMultiSelection) {
         checkBoxAllDriver.addChildBox(checkBox);
@@ -230,7 +234,7 @@ public class SearchFilterDetailDialog extends DialogBase<ISearchFilterListener<S
 
       // 선택 표시
       for (SearchFilterBean filterBean : selectedList) {
-        if (tagName.equals(filterBean.getFilterName()) && tagNo.equals(filterBean.getTagNo())) {
+        if (equals(bean, filterBean)) {
           checkBox.setChecked(true);
           break;
         }
@@ -242,6 +246,15 @@ public class SearchFilterDetailDialog extends DialogBase<ISearchFilterListener<S
     }
   }
 
+  private boolean equals(SearchFilterBean bean1, SearchFilterBean bean2) {
+    try {
+      return bean1.getFilterName().equals(bean2.getFilterName()) && bean1.getTagNo().equals(bean2.getTagNo());
+    } catch (Exception e) {
+      Log.e("APP#  SearchFilterDetailDialog | equals", "|" + e.getLocalizedMessage());
+      return false;
+    }
+  }
+
   private void selectAll(boolean isSelectedAll) {
     selectedList = new ArrayList<>();
     if (isSelectedAll) {
@@ -259,7 +272,7 @@ public class SearchFilterDetailDialog extends DialogBase<ISearchFilterListener<S
       }
       else {
         for (SearchFilterBean bean : selectedList) {
-          if (filterBean.getFilterName().equals(bean.getFilterName()) && filterBean.getTagNo().equals(bean.getTagNo())) {
+          if (equals(bean, filterBean)) {
             selectedList.remove(bean);
             break;
           }

+ 23 - 20
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/SearchFilterDialog.java

@@ -1,6 +1,5 @@
 package kr.co.zumo.app.lifeplus.view.dialog;
 
-import android.content.Context;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -24,6 +23,7 @@ import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.bean.SearchFilterSectionBean;
 import kr.co.zumo.app.lifeplus.bean.api.LifeplusData;
 import kr.co.zumo.app.lifeplus.bean.api.SearchFilterBean;
+import kr.co.zumo.app.lifeplus.helper.NavigationBar;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.util.StringUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
@@ -66,7 +66,9 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
    */
   public void setFilter(List<SearchFilterSectionBean> filterList, List<SearchFilterBean> selectedList, int filteredContentsCount) {
     filterDataSectionBeans = filterList;
-    this.selectedList = selectedList;
+    if(null != selectedList) {
+      this.selectedList = new ArrayList<>(selectedList);  // 데이터를 복제해서 사용, 내부에서 배열을 변형한다. 외부로 전달할 때도 각 데이터들을 취합해서 전달해주므로 원형을 유지할 필요가 없음.
+    }
     this.filteredContentsCount = filteredContentsCount;
   }
 
@@ -96,8 +98,21 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
     buttonLoadingView = getView().findViewById(R.id.button_loading_view);
     buttonLoadingView.draw(getView().getContext());
 
-    applyAnimation();
+    // navigation var setting
+    ((ViewGroup) getView().findViewById(R.id.container_navigation_bar))
+      .addView(
+        new NavigationBar.Builder(getContext())
+          .title(R.string.filter)
+          .close(navigationBar -> {
+            if (null != getCustomListener()) {
+              getCustomListener().onDialogCanceled(SearchFilterDialog.this);
+            }
+          })
+          .build()
+          .getView()
+      );
 
+    applyAnimation();
     applyFullScreen();
 
     if (null == selectedList) {
@@ -110,12 +125,6 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
 
     getView().setPadding(0, ResourceUtil.getStatusBarHeight(), 0, ResourceUtil.getNavBarHeight());
 
-    getView().findViewById(R.id.image_view_cancel_main).setOnClickListener(view -> {
-      if (null != getCustomListener()) {
-        getCustomListener().onDialogCanceled(SearchFilterDialog.this);
-      }
-    });
-
     getView().findViewById(R.id.text_view_reset).setOnClickListener(view -> {
       reset();
       applyContentsNumber();
@@ -130,13 +139,14 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
 
   /**
    * 외부에서 전달되는 selectedList 에는 세부 (지역/핫플레이스 등)이 포함되므로 이를 제외하고 속성만 사용한다.
+   * - 디테일 속성은 map 에 저정
    * - 디테일인지 여부는 level = FILTER_LEVEL_DETAIL
    */
   private void parseSelectedList() {
     Log.w("APP# SearchFilterDialog | parseSelectedList", "| before: " + selectedList.size());
     for (Iterator<SearchFilterBean> it = selectedList.iterator(); it.hasNext(); ) {
       SearchFilterBean value = it.next();
-      if (value.getFilterLevel().equals(SearchFilterBean.FILTER_LEVEL_DETAIL)) {
+      if (SearchFilterBean.FILTER_LEVEL_DETAIL.equals(value.getFilterLevel())) {
         List<SearchFilterBean> list = selectedDetailTagMap.get(value.getFilterNo());
         if (null == list) {
           selectedDetailTagMap.put(value.getFilterNo(), new ArrayList<>());
@@ -157,18 +167,13 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
    * @return
    */
   private List<SearchFilterBean> getSelectedList() {
-    List<SearchFilterBean> mergedList = new ArrayList<>();
 
-//    Log.w("APP# SearchFilterDialog | getSelectedList", "|" + "selectedList.size() : " + selectedList.size());
-    mergedList.addAll(selectedList);
+    List<SearchFilterBean> mergedList = new ArrayList<>(selectedList);
 
     for (List<SearchFilterBean> searchFilterBeans : selectedDetailTagMap.values()) {
-//      Log.i("APP# SearchFilterDialog | getSelectedList", "|" + "searchFilterBeans.size() : " + searchFilterBeans.size());
       mergedList.addAll(searchFilterBeans);
     }
 
-//    Log.w("APP# SearchFilterDialog | getSelectedList", "|" + "mergedList.size() : " + mergedList.size());
-
     return mergedList;
   }
 
@@ -183,7 +188,7 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
 
     parseSelectedList();
 
-    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+    LayoutInflater inflater =  LayoutInflater.from(getContext());
 
     ViewGroup container = getView().findViewById(R.id.layout_container);
 
@@ -223,7 +228,6 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
             CustomSquareArrowCheckBox arrowCheckBox = new CustomSquareArrowCheckBox(getContext());
             filterMap.put(arrowCheckBox, filterBean);
 
-//            arrowCheckBox.setCheckBoxEnabled(false);
             arrowCheckBox.setText(filterBean.getFilterName());
             // touch event
             arrowCheckBox.setOnClickListener(v -> {
@@ -335,9 +339,8 @@ public class SearchFilterDialog extends DialogBase<ISearchFilterListener<SearchF
         else {
           title = ResourceUtil.getString(R.string.search_filter_detail_title, searchFilterBean.getFilterName());
         }
-        List<SearchFilterBean> list = selectedDetailTagMap.get(searchFilterBean.getFilterNo());
         dialog.setFilterDetail(searchFilterBean.getTagBeans(),
-          list,
+          selectedDetailTagMap.get(searchFilterBean.getFilterNo()),
           title,
           LifeplusData.isTrue(searchFilterBean.getMultiSelection()),
           searchFilterBean.getFilterType(),

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/search/SearchResultFragment.java

@@ -72,7 +72,7 @@ public class SearchResultFragment extends FragmentBase<SearchResultPresenter> im
       }
     });
 
-    containerCategory = findViewById(R.id.container_category);
+    containerCategory = findViewById(R.id.collapsing_tool_bar);
     recyclerViewCategory = findViewById(R.id.recycler_view_category);
     recyclerViewCategory.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
     recyclerViewCategory.addItemDecoration(new RecyclerView.ItemDecoration() {

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/search/SearchResultModel.java

@@ -682,7 +682,7 @@ public class SearchResultModel extends Model {
       return 0;
     }
 
-    return getResultContentsBeans().size();
+    return listCount;
 
   }
 }

+ 2 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/search/SearchResultPresenter.java

@@ -212,9 +212,9 @@ public class SearchResultPresenter extends Presenter<SearchResultModel, ISearchR
           }
 
           @Override
-          public void onFilterChanged(SearchFilterDialog dialog, List<SearchFilterBean> filterIds) {
+          public void onFilterChanged(SearchFilterDialog dialog, List<SearchFilterBean> selectedList) {
             // 변경 된 필터를 적용한 컨텐츠의 수를 다이얼로그로 전달한다.
-            model.setFilter(filterIds);
+            model.setFilter(selectedList);
             model.loadFilteringContents(filterDialog, event -> {
               if (event.getEventId() == Event.SUCCESS) {
                 filterDialog.setContentsCount(event.getInteger());

+ 6 - 34
app/src/main/res/layout/dialog_category_filter.xml

@@ -5,49 +5,21 @@
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
-  android:descendantFocusability="blocksDescendants"
-  android:background="@color/CFFFFFF">
+  android:background="@color/CFFFFFF"
+  android:descendantFocusability="blocksDescendants">
 
   <android.support.constraint.ConstraintLayout
-    android:id="@+id/layout_header_main"
+    android:id="@+id/container_navigation_bar"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    app:layout_constraintTop_toTopOf="parent">
-
-    <TextView
-      android:id="@+id/text_view_filter_main"
-      android:layout_width="wrap_content"
-      android:layout_height="wrap_content"
-      android:layout_marginTop="16dp"
-      android:gravity="center_horizontal"
-      android:lineSpacingExtra="6sp"
-      android:text="@string/filter"
-      android:textColor="@color/C000000"
-      android:textSize="16sp"
-      app:layout_constraintEnd_toEndOf="parent"
-      app:layout_constraintStart_toStartOf="parent"
-      app:layout_constraintTop_toTopOf="parent"
-      />
-
-    <ImageView
-      android:id="@+id/image_view_cancel_main"
-      android:layout_width="wrap_content"
-      android:layout_height="wrap_content"
-      android:layout_marginEnd="8dp"
-      android:padding="10dp"
-      app:layout_constraintBottom_toBottomOf="@+id/text_view_filter_main"
-      app:layout_constraintEnd_toEndOf="parent"
-      app:layout_constraintTop_toTopOf="@+id/text_view_filter_main"
-      app:srcCompat="@drawable/icon_category_filter_close"
-      />
-  </android.support.constraint.ConstraintLayout>
+    android:layout_height="@dimen/action_bar_height"
+    app:layout_constraintTop_toTopOf="parent"/>
 
   <android.support.v4.widget.NestedScrollView
     android:id="@+id/scroll_view"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     app:layout_constraintBottom_toTopOf="@+id/layout_buttons"
-    app:layout_constraintTop_toBottomOf="@+id/layout_header_main">
+    app:layout_constraintTop_toBottomOf="@+id/container_navigation_bar">
 
     <LinearLayout
       android:id="@+id/layout_container"

+ 3 - 1
app/src/main/res/layout/dialog_category_filter_detail.xml

@@ -66,10 +66,12 @@
 
     <TextView
       android:id="@+id/text_view_apply"
-      android:layout_width="wrap_content"
+      android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:gravity="center_horizontal"
       android:lineSpacingExtra="6sp"
+      android:layout_marginStart="25dp"
+      android:layout_marginEnd="25dp"
       android:padding="10dp"
       android:text="@string/apply"
       android:textColor="@color/CFFFFFF"

+ 2 - 2
app/src/main/res/layout/fragment_search_result.xml

@@ -63,7 +63,7 @@
           app:layout_scrollFlags="scroll"
           />
 
-        <LinearLayout
+        <android.support.constraint.ConstraintLayout
           android:id="@+id/container_category"
           android:layout_width="match_parent"
           android:layout_height="35dp"
@@ -110,7 +110,7 @@
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toEndOf="@+id/image_filter"/>
-        </LinearLayout>
+        </android.support.constraint.ConstraintLayout>
       </android.support.design.widget.CollapsingToolbarLayout>
     </android.support.design.widget.AppBarLayout>