Selaa lähdekoodia

[공통][Common] 카테고리 메인 스피너 선택시 appbarlayout 정렬되는 기능 함수로 분리

Hasemi 7 vuotta sitten
vanhempi
commit
af3937341a

+ 34 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/CategorySortScroller.java

@@ -0,0 +1,34 @@
+package kr.co.zumo.app.lifeplus.view.screen.category;
+
+import android.support.design.widget.AppBarLayout;
+import android.support.design.widget.CoordinatorLayout;
+
+/**
+ * CategorySortScroller
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-12-11]   [최초 작성]
+ * @since 2018-12-11
+ */
+public class CategorySortScroller {
+
+  private CoordinatorLayout coordinatorLayout;
+  private AppBarLayout appBarLayout;
+
+  public CategorySortScroller(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout) {
+    this.coordinatorLayout = coordinatorLayout;
+    this.appBarLayout = appBarLayout;
+  }
+
+  public void doAppBarLayoutInitialization() {
+    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
+    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
+    if (null != behavior) {
+      behavior.setTopAndBottomOffset(0);
+      behavior.onNestedPreScroll(coordinatorLayout, appBarLayout, null, 0, 1, new int[2], 0);
+    }
+  }
+}

+ 3 - 7
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type1/FirstCategoryMainFragment.java

@@ -28,6 +28,7 @@ import kr.co.zumo.app.lifeplus.view.custom.category.series.IMainSeriesContract;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesPresenter;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesView;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
+import kr.co.zumo.app.lifeplus.view.screen.category.CategorySortScroller;
 import kr.co.zumo.app.lifeplus.view.screen.category.FocusArrayAdapter;
 import kr.co.zumo.app.lifeplus.view.screen.category.GridItemDecoration;
 import kr.co.zumo.app.lifeplus.view.screen.category.IFirstCategoryMainView;
@@ -71,7 +72,6 @@ public class FirstCategoryMainFragment extends FragmentBase<FirstCategoryMainPre
     spinnerOrder = findViewById(R.id.spinner_select_contents);
     List<String> spinnerList = Arrays.asList(ResourceUtil.getStringArray("main_filter"));
     arrayAdapter = new FocusArrayAdapter(getActivity(), R.layout.custom_spinner, spinnerList);
-
     spinnerOrder.setAdapter(arrayAdapter);
   }
 
@@ -176,12 +176,8 @@ public class FirstCategoryMainFragment extends FragmentBase<FirstCategoryMainPre
     adapter.update(contentsBeans);
     recyclerViewFirstCategoryMain.scrollToPosition(0);
 
-    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
-    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
-    if (null != behavior) {
-      behavior.setTopAndBottomOffset(0);
-      behavior.onNestedPreScroll(layoutRoot, appBarLayout, null, 0, 1, new int[2], 0);
-    }
+    CategorySortScroller scroller = new CategorySortScroller(layoutRoot, appBarLayout);
+    scroller.doAppBarLayoutInitialization();
 
   }
 

+ 3 - 7
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type2/SecondCategoryMainFragment.java

@@ -29,6 +29,7 @@ import kr.co.zumo.app.lifeplus.view.custom.category.series.IMainSeriesContract;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesPresenter;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesView;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
+import kr.co.zumo.app.lifeplus.view.screen.category.CategorySortScroller;
 import kr.co.zumo.app.lifeplus.view.screen.category.FocusArrayAdapter;
 import kr.co.zumo.app.lifeplus.view.screen.category.ISecondCategoryMainView;
 
@@ -170,12 +171,7 @@ public class SecondCategoryMainFragment extends FragmentBase<SecondCategoryMainP
     adapter.update(contentsBeans);
     recyclerViewSecondCategoryMain.scrollToPosition(0);
 
-    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
-    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
-    if (null != behavior) {
-      behavior.setTopAndBottomOffset(0);
-      behavior.onNestedPreScroll(layoutRoot, appBarLayout, null, 0, 1, new int[2], 0);
-    }
-
+    CategorySortScroller scroller = new CategorySortScroller(layoutRoot, appBarLayout);
+    scroller.doAppBarLayoutInitialization();
   }
 }

+ 7 - 35
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type3/ThirdCategoryMainFragment.java

@@ -1,6 +1,5 @@
 package kr.co.zumo.app.lifeplus.view.screen.category.type3;
 
-import android.graphics.Typeface;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -8,14 +7,11 @@ import android.support.design.widget.AppBarLayout;
 import android.support.design.widget.CoordinatorLayout;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.RecyclerView;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
 import android.widget.Spinner;
-import android.widget.TextView;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,6 +28,8 @@ import kr.co.zumo.app.lifeplus.view.custom.category.series.IMainSeriesContract;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesPresenter;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesView;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
+import kr.co.zumo.app.lifeplus.view.screen.category.CategorySortScroller;
+import kr.co.zumo.app.lifeplus.view.screen.category.FocusArrayAdapter;
 import kr.co.zumo.app.lifeplus.view.screen.category.GridItemDecoration;
 import kr.co.zumo.app.lifeplus.view.screen.category.IThirdCategoryMainView;
 
@@ -53,7 +51,7 @@ public class ThirdCategoryMainFragment extends FragmentBase<ThirdCategoryMainPre
   private RecyclerView recyclerViewThirdCategoryMain;
   private IMainSeriesContract.Presenter seriesPresenter;
   private Spinner spinnerOrder;
-  private int selectedIndex = -1;
+  private FocusArrayAdapter arrayAdapter;
   private ThirdCategoryMainAdapter adapter;
 
 
@@ -73,26 +71,7 @@ public class ThirdCategoryMainFragment extends FragmentBase<ThirdCategoryMainPre
 
     spinnerOrder = findViewById(R.id.spinner_select_contents);
     List<String> spinnerList = Arrays.asList(ResourceUtil.getStringArray("main_filter"));
-    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.custom_spinner, spinnerList) {
-      @Override
-      public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
-        View view = super.getDropDownView(position, convertView, parent);
-        //초기값 설정
-        if (selectedIndex == -1) {
-          if (position == 0) {
-            view.setBackgroundColor(getResources().getColor(R.color.CE5E5E5));
-            ((TextView)view.findViewById(R.id.spinner_text)).setTypeface(null, Typeface.BOLD);
-          }
-        }
-        //select 된 값 지정
-        if (position == selectedIndex) {
-          view.setBackgroundColor(getResources().getColor(R.color.CE5E5E5));
-          ((TextView)view.findViewById(R.id.spinner_text)).setTypeface(null, Typeface.BOLD);
-        }
-        return view;
-      }
-    };
-
+    arrayAdapter = new FocusArrayAdapter(getActivity(), R.layout.custom_spinner, spinnerList);
     spinnerOrder.setAdapter(arrayAdapter);
   }
 
@@ -168,7 +147,6 @@ public class ThirdCategoryMainFragment extends FragmentBase<ThirdCategoryMainPre
     spinnerOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
       @Override
       public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
-        selectedIndex = position;
         presenter.onEvent(new Event.Builder(Event.ORDER).index(position).build());
       }
 
@@ -179,9 +157,7 @@ public class ThirdCategoryMainFragment extends FragmentBase<ThirdCategoryMainPre
   }
 
   @Override
-  public void drawRecommend(ArrayList<CategoryRecommendBean> beans) {
-    Log.i("APP# ThirdCategoryMainFragment | drawRecommend", "| 1" + beans);
-    Log.i("APP# ThirdCategoryMainFragment | drawRecommend", "| 2" + mainSeriesView);
+  public void drawRecommend(ArrayList<CategoryRecommendBean> beans) { ;
     mainSeriesView.init(getActivity(), beans, beans.size());
     seriesPresenter = new MainSeriesPresenter(mainSeriesView, index -> {
       presenter.onEvent(new Event.Builder(Event.RECOMMEND).index(index).build());
@@ -193,11 +169,7 @@ public class ThirdCategoryMainFragment extends FragmentBase<ThirdCategoryMainPre
     adapter.update(contentsBeans);
     recyclerViewThirdCategoryMain.scrollToPosition(0);
 
-    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
-    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
-    if (null != behavior) {
-      behavior.setTopAndBottomOffset(0);
-      behavior.onNestedPreScroll(layoutRoot, appBarLayout, null, 0, 1, new int[2], 0);
-    }
+    CategorySortScroller scroller = new CategorySortScroller(layoutRoot, appBarLayout);
+    scroller.doAppBarLayoutInitialization();
   }
 }

+ 6 - 31
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/category/type4/FourthCategoryMainFragment.java

@@ -1,7 +1,6 @@
 package kr.co.zumo.app.lifeplus.view.screen.category.type4;
 
 import android.graphics.Rect;
-import android.graphics.Typeface;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -13,9 +12,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
 import android.widget.Spinner;
-import android.widget.TextView;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,6 +29,8 @@ import kr.co.zumo.app.lifeplus.view.custom.category.series.IMainSeriesContract;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesPresenter;
 import kr.co.zumo.app.lifeplus.view.custom.category.series.MainSeriesView;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
+import kr.co.zumo.app.lifeplus.view.screen.category.CategorySortScroller;
+import kr.co.zumo.app.lifeplus.view.screen.category.FocusArrayAdapter;
 import kr.co.zumo.app.lifeplus.view.screen.category.IFourthCategoryMainView;
 
 /**
@@ -52,7 +51,7 @@ public class FourthCategoryMainFragment extends FragmentBase<FourthCategoryMainP
   private RecyclerView recyclerViewFourthCategoryMain;
   private IMainSeriesContract.Presenter seriesPresenter;
   private Spinner spinnerOrder;
-  private int selectedIndex = -1;
+  private FocusArrayAdapter arrayAdapter;
   private FourthCategoryMainAdapter adapter;
 
   @Override
@@ -77,26 +76,7 @@ public class FourthCategoryMainFragment extends FragmentBase<FourthCategoryMainP
 
     spinnerOrder = findViewById(R.id.spinner_select_contents);
     List<String> spinnerList = Arrays.asList(ResourceUtil.getStringArray("main_filter"));
-    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.custom_spinner, spinnerList) {
-      @Override
-      public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
-        View view = super.getDropDownView(position, convertView, parent);
-        //초기값 설정
-        if (selectedIndex == -1) {
-          if (position == 0) {
-            view.setBackgroundColor(getResources().getColor(R.color.CE5E5E5));
-            ((TextView) view.findViewById(R.id.spinner_text)).setTypeface(null, Typeface.BOLD);
-          }
-        }
-        //select 된 값 지정
-        if (position == selectedIndex) {
-          view.setBackgroundColor(getResources().getColor(R.color.CE5E5E5));
-          ((TextView) view.findViewById(R.id.spinner_text)).setTypeface(null, Typeface.BOLD);
-        }
-        return view;
-      }
-    };
-
+    arrayAdapter = new FocusArrayAdapter(getActivity(), R.layout.custom_spinner, spinnerList);
     spinnerOrder.setAdapter(arrayAdapter);
   }
 
@@ -156,7 +136,6 @@ public class FourthCategoryMainFragment extends FragmentBase<FourthCategoryMainP
     spinnerOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
       @Override
       public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
-        selectedIndex = position;
         presenter.onEvent(new Event.Builder(Event.ORDER).index(position).build());
       }
 
@@ -178,12 +157,8 @@ public class FourthCategoryMainFragment extends FragmentBase<FourthCategoryMainP
     adapter.update(contentsBeans);
     recyclerViewFourthCategoryMain.scrollToPosition(0);
 
-    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
-    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
-    if (null != behavior) {
-      behavior.setTopAndBottomOffset(0);
-      behavior.onNestedPreScroll(layoutRoot, appBarLayout, null, 0, 1, new int[2], 0);
-    }
+    CategorySortScroller scroller = new CategorySortScroller(layoutRoot, appBarLayout);
+    scroller.doAppBarLayoutInitialization();
 
   }
 }

+ 1 - 0
app/src/main/res/layout/fragment_my_coin_detail.xml

@@ -5,6 +5,7 @@
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
+  android:background="@color/CFFFFFF"
   android:orientation="vertical">
 
   <android.support.design.widget.AppBarLayout

+ 0 - 1
app/src/main/res/layout/fragment_my_coin_extinction.xml

@@ -3,7 +3,6 @@
   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"
-  android:layout_marginTop="@dimen/action_bar_height"
   android:layout_width="match_parent"
   android:layout_height="match_parent">