Ver código fonte

[알림][New] view 로 전환 중

hyodong.min 6 anos atrás
pai
commit
3ec6139841

+ 1 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiFragment.java

@@ -55,18 +55,16 @@ public class NotiFragment extends FragmentBase<NotiPresenter> implements INotiVi
     tabLayoutAlarm.setupWithViewPager(viewPagerAlarm, true);
     tabBarLayoutAlarm.setupWithViewPager(viewPagerAlarm, true);
 
-    viewPagerAlarm.setOffscreenPageLimit(10);
+//    viewPagerAlarm.setOffscreenPageLimit(10);
 
     viewPagerAlarm.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
       @Override
       public void onPageSelected(int position) {
         presenter.onPageChanged(position);
         notiPagerAdapter.setFocusPage(position);
-
       }
     });
 
-
   }
 
   @Override

+ 1 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiListFragment.java

@@ -29,6 +29,7 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
  * @history 하세미   [2018-10-24]   [최초 작성]
  * @since 2018-10-24
  */
+@Deprecated
 public class NotiListFragment extends Fragment {
 
   private static final String PARAM_INDEX = "index";

+ 1 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiPagerAdapter.java

@@ -25,6 +25,7 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
  * @history 하세미   [2018-10-24]   [최초 작성]
  * @since 2018-10-24
  */
+@Deprecated
 public class NotiPagerAdapter extends FragmentStatePagerAdapter implements NotiListFragment.INotiListFragmentDelegate {
 
   private static final int PAGE_COUNT = 3;

+ 101 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiView.java

@@ -0,0 +1,101 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.screen.notification;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.widget.TextView;
+
+import java.util.List;
+
+import kr.co.zumo.app.R;
+import kr.co.zumo.app.lifeplus.bean.api.NoticeBean;
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
+import kr.co.zumo.app.lifeplus.view.IEventListener;
+
+/**
+ * NotiView
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019-04-08]   [최초 작성]
+ * @since 2019-04-08
+ */
+public class NotiView {
+  private IEventListener listener;
+  private Context context;
+  private NotiListAdapter notiListAdapter;
+  private RecyclerView recyclerView;
+  private int index;
+
+  public NotiView(Context context, View view, int position, List<NoticeBean> dataList, IEventListener listener) {
+    this.context = context;
+    this.listener = listener;
+    this.index = position;
+    setLayoutNothingText(view, position);
+    init(view, dataList, this.listener);
+  }
+
+  private void setLayoutNothingText(View view, int position) {
+    TextView textViewNotiNothingText = view.findViewById(R.id.text_view_noti_nothing_text);
+    if (position == 2) {
+      textViewNotiNothingText.setText(R.string.notice_nothing);
+    }
+    else {
+      textViewNotiNothingText.setText(R.string.notice_news_nothing);
+    }
+  }
+
+  /**
+   * 초기화
+   *
+   * @param view
+   * @param beans
+   * @param listener
+   */
+  public void init(View view, List<NoticeBean> beans, IEventListener listener) {
+    recyclerView = view.findViewById(R.id.recycler_view_alarm_list);
+    View layoutNothing = view.findViewById(R.id.layout_nothing);
+    recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
+    recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
+      @Override
+      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+        super.getItemOffsets(outRect, view, parent, state);
+        outRect.bottom = ResourceUtil.dpToPx(12);
+      }
+    });
+
+    if (null == beans || beans.size() == 0) {
+      layoutNothing.setVisibility(View.VISIBLE);
+    }
+    else {
+      layoutNothing.setVisibility(View.GONE);
+      notiListAdapter = new NotiListAdapter(beans, listener);
+      recyclerView.setAdapter(notiListAdapter);
+    }
+  }
+
+  public void setFocusPage(int position) {
+    if (this.index == position) {
+      if (NoticeBean.CATEGORY_NOTICE.equals(NoticeBean.getCategoryName(this.index))) {
+        // 공지 탭 보여질 때 첫 번째 아이템 확장
+        notiListAdapter.expand(0, true);
+      }
+      else if (NoticeBean.CATEGORY_ALL.equals(NoticeBean.getCategoryName(this.index))) {
+        // 전체 탭 모든 아이탬 축소
+        notiListAdapter.collapseDataAll();
+      }
+    }
+    else {
+      if (null != recyclerView) {
+        recyclerView.scrollToPosition(0);
+      }
+    }
+  }
+}

+ 21 - 97
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/notification/NotiViewPagerAdapter.java

@@ -1,25 +1,20 @@
 package kr.co.zumo.app.lifeplus.view.screen.notification;
 
 import android.content.Context;
-import android.graphics.Rect;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.view.PagerAdapter;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-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.NoticeBean;
-import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.view.IEventListener;
 
 /**
@@ -33,15 +28,6 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
  * @since 2019-04-05
  */
 public class NotiViewPagerAdapter extends PagerAdapter {
-
-
-  private static final String CATEGORY_ALL = ResourceUtil.getString(R.string.notice_category_all);
-  private static final String CATEGORY_NEWS = ResourceUtil.getString(R.string.notice_category_news);
-  private static final String CATEGORY_NOTICE = ResourceUtil.getString(R.string.notice_category_notice);
-
-  public static final int CATEGORY_KEY_ALL = 0;
-  public static final int CATEGORY_KEY_MEMBER = 1;
-  public static final int CATEGORY_KEY_BENEFIT = 2;
   private Context context;
   private static final int PAGE_COUNT = 3;
   private String[] tabs;
@@ -49,10 +35,8 @@ public class NotiViewPagerAdapter extends PagerAdapter {
   private IEventListener listener;
   private SparseArray<List<NoticeBean>> categoryMap;
   private LayoutInflater inflater;
-  private TextView textViewNotiNothingText;
-  private NotiListAdapter notiListAdapter;
-  private RecyclerView recyclerView;
-  private View layoutNothing;
+
+  private List<NotiView> notiViews;
 
   public NotiViewPagerAdapter(Context context, String[] tabs, List<NoticeBean> noticeBeans, IEventListener listener) {
     this.tabs = tabs.clone();
@@ -77,22 +61,15 @@ public class NotiViewPagerAdapter extends PagerAdapter {
   public Object instantiateItem(@NonNull ViewGroup container, int position) {
     Log.e("APP#  NotiViewPagerAdapter | instantiateItem, 77", "position |" + position);
 
+    if(null == notiViews) {
+      notiViews = new ArrayList<>();
+    }
+
     View view = inflater.inflate(R.layout.fragment_noti_list, container, false);
-    recyclerView = view.findViewById(R.id.recycler_view_alarm_list);
-    layoutNothing = view.findViewById(R.id.layout_nothing);
-    textViewNotiNothingText = view.findViewById(R.id.text_view_noti_nothing_text);
-    recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
-    recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
-      @Override
-      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
-        super.getItemOffsets(outRect, view, parent, state);
-        outRect.bottom = ResourceUtil.dpToPx(12);
-      }
-    });
+    NotiView notiView = new NotiView(context, view, position, getDataList(position), listener);
 
-    setLayoutNothingText(position);
-    onInit(position);
     container.addView(view);
+    notiViews.add(notiView);
     return view;
   }
 
@@ -103,40 +80,16 @@ public class NotiViewPagerAdapter extends PagerAdapter {
     notifyDataSetChanged();
   }
 
-  @Nullable
-  @Override
-  public CharSequence getPageTitle(int position) {
-    return tabs[position];
-  }
-
-  private void setLayoutNothingText(int position) {
-    if (position == 2) {
-      textViewNotiNothingText.setText(R.string.notice_nothing);
-    }
-    else {
-      textViewNotiNothingText.setText(R.string.notice_news_nothing);
-    }
-  }
-
-  private void onInit(int category) {
-    if (category == 2) {
-      textViewNotiNothingText.setText(R.string.notice_nothing);
-    }
-    else {
-      textViewNotiNothingText.setText(R.string.notice_news_nothing);
-    }
-
-
+  private List<NoticeBean> getDataList(int category) {
     /**
      * 카테고리 별로 데이터를 구분해서 전달한다.
      */
-
     if (null == categoryMap) {
       categoryMap = new SparseArray<>();
     }
 
     List<NoticeBean> beans;
-    if (category == CATEGORY_KEY_ALL) {
+    if (category == NotiFragment.CATEGORY_KEY_ALL) {
       beans = this.noticeBeans;
     }
     else {
@@ -157,52 +110,23 @@ public class NotiViewPagerAdapter extends PagerAdapter {
       }
     }
 
-    init(beans, listener);
-  }
-
-  /**
-   * 초기화
-   *
-   * @param beans
-   */
-  public void init(List<NoticeBean> beans, IEventListener listener) {
-    List<NoticeBean> noticeBeans = beans;
-    IEventListener eventListener = listener;
-
-    if (null == noticeBeans || noticeBeans.size() == 0) {
-      layoutNothing.setVisibility(View.VISIBLE);
-    }
-    else {
-      layoutNothing.setVisibility(View.GONE);
-      notiListAdapter = new NotiListAdapter(noticeBeans, eventListener);
-      recyclerView.setAdapter(notiListAdapter);
-
-    }
+    return beans;
   }
 
-  public void setFocusPage(int position) {
-    Log.e("APP#  NotiViewPagerAdapter | setFocusPage, 185", "position |" + position);
-    Log.e("APP#  NotiViewPagerAdapter | setFocusPage, 186", "type |" + NoticeBean.getCategoryName(position));
-    if (null != notiListAdapter) {
-      if (NoticeBean.CATEGORY_NOTICE.equals(NoticeBean.getCategoryName(position))) {
-        // 공지 탭 보여질 때 첫 번째 아이템 확장
-        notiListAdapter.expand(0, true);
-      }
-      else if (NoticeBean.CATEGORY_ALL.equals(NoticeBean.getCategoryName(position))) {
-        // 전체 탭 모든 아이탬 축소
-        notiListAdapter.collapseDataAll();
-      }
-    }
-    else {
-      if (null != recyclerView) {
-        recyclerView.scrollToPosition(0);
-      }
-    }
-
+  @Nullable
+  @Override
+  public CharSequence getPageTitle(int position) {
+    return tabs[position];
   }
 
   @Override
   public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
     container.removeView((View) object);
   }
+
+  public void setFocusPage(int position) {
+    for (NotiView notiView : notiViews) {
+      notiView.setFocusPage(position);
+    }
+  }
 }