|
|
@@ -0,0 +1,195 @@
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * NotiViewPagerAdapter
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 하세미
|
|
|
+ * @version 1.0
|
|
|
+ * @history 하세미 [2019-04-05] [최초 작성]
|
|
|
+ * @since 2019-04-05
|
|
|
+ */
|
|
|
+public class NotiViewPagerAdapter extends PagerAdapter implements NotiListFragment.INotiListFragmentDelegate {
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ private List<NoticeBean> noticeBeans;
|
|
|
+ private IEventListener listener;
|
|
|
+ private SparseArray<List<NoticeBean>> categoryMap;
|
|
|
+ private LayoutInflater inflater;
|
|
|
+ private TextView textViewNotiNothingText;
|
|
|
+ private NotiListAdapter notiListAdapter;
|
|
|
+
|
|
|
+ public NotiViewPagerAdapter(Context context, String[] tabs, List<NoticeBean> noticeBeans, IEventListener listener) {
|
|
|
+ this.tabs = tabs.clone();
|
|
|
+ this.noticeBeans = noticeBeans;
|
|
|
+ this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ this.listener = listener;
|
|
|
+ this.context = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return PAGE_COUNT;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
|
|
+ return view.equals(object);
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
|
|
+ View view = inflater.inflate(R.layout.fragment_noti_list, container, false);
|
|
|
+ NoticeBean bean = noticeBeans.get(position);
|
|
|
+ RecyclerView recyclerView = view.findViewById(R.id.recycler_view_alarm_list);
|
|
|
+ View layoutNothing = view.findViewById(R.id.layout_nothing);
|
|
|
+ textViewNotiNothingText = view.findViewById(R.id.text_view_noti_nothing_text);
|
|
|
+ onInit(position);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ onInit(position);
|
|
|
+ setLayoutNothingText(position);
|
|
|
+
|
|
|
+ if (null == noticeBeans || noticeBeans.size() == 0) {
|
|
|
+ layoutNothing.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ layoutNothing.setVisibility(View.GONE);
|
|
|
+ recyclerView.setAdapter(notiListAdapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ container.addView(view);
|
|
|
+
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInit(NotiListFragment notiListFragment, int category) {
|
|
|
+ /**
|
|
|
+ * 카테고리 별로 데이터를 구분해서 전달한다.
|
|
|
+ */
|
|
|
+
|
|
|
+ if (null == categoryMap) {
|
|
|
+ categoryMap = new SparseArray<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<NoticeBean> beans;
|
|
|
+ if (category == NotiFragment.CATEGORY_KEY_ALL) {
|
|
|
+ beans = this.noticeBeans;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ beans = categoryMap.get(category);
|
|
|
+ if (null == beans) {
|
|
|
+ beans = new ArrayList<>();
|
|
|
+ String categoryName = NoticeBean.getCategoryName(category);
|
|
|
+
|
|
|
+ int len = this.noticeBeans.size();
|
|
|
+ NoticeBean bean;
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ bean = noticeBeans.get(i);
|
|
|
+ if (bean.getCategory().equals(categoryName)) {
|
|
|
+ beans.add(bean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ categoryMap.put(category, beans);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.w("APP# NotiViewPagerAdapter | onInit", "|" + "cate: " + category + ", size: " + beans.size());
|
|
|
+
|
|
|
+ notiListFragment.init(beans, listener);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void update(List<NoticeBean> noticeBeans) {
|
|
|
+ this.noticeBeans = noticeBeans;
|
|
|
+ categoryMap = null;
|
|
|
+
|
|
|
+ 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 (null == categoryMap) {
|
|
|
+ categoryMap = new SparseArray<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<NoticeBean> beans;
|
|
|
+ if (category == CATEGORY_KEY_ALL) {
|
|
|
+ beans = this.noticeBeans;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ beans = categoryMap.get(category);
|
|
|
+ if (null == beans) {
|
|
|
+ beans = new ArrayList<>();
|
|
|
+ String categoryName = NoticeBean.getCategoryName(category);
|
|
|
+
|
|
|
+ int len = this.noticeBeans.size();
|
|
|
+ NoticeBean bean;
|
|
|
+ for (int i = 0; i < len; ++i) {
|
|
|
+ bean = noticeBeans.get(i);
|
|
|
+ if (bean.getCategory().equals(categoryName)) {
|
|
|
+ beans.add(bean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ categoryMap.put(category, beans);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.w("APP# NotiPagerAdapter | onInit", "|" + "cate: " + category + ", size: " + beans.size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|