|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|