|
@@ -0,0 +1,377 @@
|
|
|
|
|
+package com.sheep.gamegroup.view.fragment;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.support.design.widget.TabLayout;
|
|
|
|
|
+import android.support.v4.view.ViewPager;
|
|
|
|
|
+import android.support.v4.widget.NestedScrollView;
|
|
|
|
|
+import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
+import android.widget.LinearLayout;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
|
|
+import com.bumptech.glide.request.RequestOptions;
|
|
|
|
|
+import com.kfzs.duanduan.mine.GiftpackListAdapter;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.FindTag;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.PlayGameEntity;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.SlideshowEty;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.Welfare;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewHolder;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
|
|
+import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.youth.banner.Banner;
|
|
|
|
|
+import com.youth.banner.BannerConfig;
|
|
|
|
|
+import com.youth.banner.listener.OnBannerListener;
|
|
|
|
|
+import com.youth.banner.loader.ImageLoader;
|
|
|
|
|
+
|
|
|
|
|
+import org.afinal.simplecache.ApiKey;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import butterknife.BindView;
|
|
|
|
|
+import butterknife.ButterKnife;
|
|
|
|
|
+import butterknife.OnClick;
|
|
|
|
|
+import butterknife.Unbinder;
|
|
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
+
|
|
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.FIND_TAG;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Created by ljy on 2018/9/3.
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+public class FgtPlayGame extends BaseFragment {
|
|
|
|
|
+ @BindView(R.id.banner)
|
|
|
|
|
+ Banner banner;
|
|
|
|
|
+ @BindView(R.id.every_day_more_tv)
|
|
|
|
|
+ TextView everyDayMoreTv;
|
|
|
|
|
+ @BindView(R.id.every_day_play_list)
|
|
|
|
|
+ RecyclerView everyDayPlayList;
|
|
|
|
|
+ @BindView(R.id.recent_hot_more_tv)
|
|
|
|
|
+ TextView recentHotMoreTv;
|
|
|
|
|
+ @BindView(R.id.recent_hoe_list)
|
|
|
|
|
+ RecyclerView recentHoeList;
|
|
|
|
|
+ @BindView(R.id.tabLayout)
|
|
|
|
|
+ TabLayout indicator;
|
|
|
|
|
+ @BindView(R.id.viewpager_act_game_details)
|
|
|
|
|
+ ViewPager pager;
|
|
|
|
|
+ @BindView(R.id.bottom_line_text)
|
|
|
|
|
+ TextView bottomLineText;
|
|
|
|
|
+ @BindView(R.id.bottom_line)
|
|
|
|
|
+ LinearLayout bottomLine;
|
|
|
|
|
+ @BindView(R.id.refresh)
|
|
|
|
|
+ SwipeRefreshLayout refresh;
|
|
|
|
|
+ @BindView(R.id.scrollView)
|
|
|
|
|
+ NestedScrollView scrollView;
|
|
|
|
|
+ Unbinder unbinder;
|
|
|
|
|
+
|
|
|
|
|
+ private Activity activity;
|
|
|
|
|
+ private List<PlayGameEntity> everyDayPlayListData = new ArrayList<>();
|
|
|
|
|
+ private List<PlayGameEntity> hotListData = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ private List<SlideshowEty> slideshowEtyLists = new ArrayList<>();
|
|
|
|
|
+ private List<String> slideshowTitleList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ private List<FindTag> list = ListUtil.emptyList();
|
|
|
|
|
+ private GiftpackListAdapter mAdapter;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getLayoutId() {
|
|
|
|
|
+ return R.layout.fgt_play_game;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onViewCreated() {
|
|
|
|
|
+ activity = getActivity();
|
|
|
|
|
+
|
|
|
|
|
+ //banner
|
|
|
|
|
+ LinearLayout.LayoutParams bannerLayoutParams = (LinearLayout.LayoutParams) banner.getLayoutParams();
|
|
|
|
|
+ bannerLayoutParams.height = G.WIDTH * 25 / 72;
|
|
|
|
|
+ banner.setLayoutParams(bannerLayoutParams);
|
|
|
|
|
+
|
|
|
|
|
+ //每日必玩、近期最热
|
|
|
|
|
+ LinearLayoutManager playHotManager = new LinearLayoutManager(SheepApp.getInstance(), LinearLayoutManager.HORIZONTAL, false);
|
|
|
|
|
+ //每日必玩
|
|
|
|
|
+ everyDayPlayList.setHasFixedSize(true);
|
|
|
|
|
+ everyDayPlayList.setNestedScrollingEnabled(false);
|
|
|
|
|
+ everyDayPlayList.setLayoutManager(playHotManager);
|
|
|
|
|
+ everyDayPlayList.setAdapter(new AdbCommonRecycler<PlayGameEntity>(SheepApp.getInstance(), everyDayPlayListData) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getViewIdByType(int type) {
|
|
|
|
|
+ return R.layout.item_hot_welfare;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void convert(ViewHolder holder, PlayGameEntity welfareCenter) {
|
|
|
|
|
+ ImageView item_hot_welfare_iv = holder.getView(R.id.item_hot_welfare_iv);
|
|
|
|
|
+ TextView item_hot_welfare_tv = holder.getView(R.id.item_hot_welfare_tv);
|
|
|
|
|
+ if(welfareCenter == null){
|
|
|
|
|
+ ViewUtil.setDefaultText(item_hot_welfare_tv);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //TODO 加载数据
|
|
|
|
|
+ ViewUtil.setText(item_hot_welfare_tv, welfareCenter.getName());
|
|
|
|
|
+ GlideImageLoader.setImage(item_hot_welfare_iv, welfareCenter.getIcon());
|
|
|
|
|
+ onClickToPlayGameDetail(holder.itemView, welfareCenter);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ //近期最热
|
|
|
|
|
+ LinearLayoutManager hotManager = new LinearLayoutManager(SheepApp.getInstance(), LinearLayoutManager.HORIZONTAL, false);
|
|
|
|
|
+ recentHoeList.setHasFixedSize(true);
|
|
|
|
|
+ recentHoeList.setNestedScrollingEnabled(false);
|
|
|
|
|
+ recentHoeList.setLayoutManager(hotManager);
|
|
|
|
|
+ everyDayPlayList.setAdapter(new AdbCommonRecycler<PlayGameEntity>(SheepApp.getInstance(), hotListData) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getViewIdByType(int type) {
|
|
|
|
|
+ return R.layout.item_hot_welfare;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void convert(ViewHolder holder, PlayGameEntity welfareCenter) {
|
|
|
|
|
+ ImageView item_hot_welfare_iv = holder.getView(R.id.item_hot_welfare_iv);
|
|
|
|
|
+ TextView item_hot_welfare_tv = holder.getView(R.id.item_hot_welfare_tv);
|
|
|
|
|
+ if(welfareCenter == null){
|
|
|
|
|
+ ViewUtil.setDefaultText(item_hot_welfare_tv);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //TODO 加载数据
|
|
|
|
|
+ ViewUtil.setText(item_hot_welfare_tv, welfareCenter.getName());
|
|
|
|
|
+ GlideImageLoader.setImage(item_hot_welfare_iv, welfareCenter.getIcon());
|
|
|
|
|
+ onClickToPlayGameDetail(holder.itemView, welfareCenter);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRefresh() {
|
|
|
|
|
+ initData();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ mAdapter = new GiftpackListAdapter(getFragmentManager(), SheepApp.getInstance());
|
|
|
|
|
+
|
|
|
|
|
+ //tab
|
|
|
|
|
+ initTab();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void onClickToPlayGameDetail(View view, PlayGameEntity playGameEntity){
|
|
|
|
|
+ view.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+// Jump2View.getInstance().goFindInformation(activity, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
+ // TODO: inflate a fragment view
|
|
|
|
|
+ View rootView = super.onCreateView(inflater, container, savedInstanceState);
|
|
|
|
|
+ unbinder = ButterKnife.bind(this, rootView);
|
|
|
|
|
+ return rootView;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDestroyView() {
|
|
|
|
|
+ super.onDestroyView();
|
|
|
|
|
+ unbinder.unbind();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onStart() {
|
|
|
|
|
+ super.onStart();
|
|
|
|
|
+ //结束轮播
|
|
|
|
|
+ banner.startAutoPlay();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onStop() {
|
|
|
|
|
+ super.onStop();
|
|
|
|
|
+ //结束轮播
|
|
|
|
|
+ banner.stopAutoPlay();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onResume() {
|
|
|
|
|
+ super.onResume();
|
|
|
|
|
+ initData();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void bindBanner() {
|
|
|
|
|
+ //结束轮播
|
|
|
|
|
+ banner.stopAutoPlay();
|
|
|
|
|
+ banner.setVisibility(View.VISIBLE);
|
|
|
|
|
+ //设置图片加载器
|
|
|
|
|
+ banner.setImageLoader(new ImageLoader() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void displayImage(Context context, Object o, ImageView imageView) {
|
|
|
|
|
+ if (o instanceof SlideshowEty)
|
|
|
|
|
+ Glide.with(context).load(((SlideshowEty) o).getUrl()).apply(new RequestOptions().dontAnimate()).into(imageView);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .setDelayTime(4000)
|
|
|
|
|
+ .setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE)
|
|
|
|
|
+ //设置图片集合
|
|
|
|
|
+ .setImages(slideshowEtyLists).setBannerTitles(slideshowTitleList)
|
|
|
|
|
+ .setOnBannerListener(new OnBannerListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void OnBannerClick(int i) {
|
|
|
|
|
+ CommonUtil.getInstance().clickBanner(activity,i, slideshowEtyLists);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //banner设置方法全部调用完毕时最后调用
|
|
|
|
|
+ banner.start();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initData(){
|
|
|
|
|
+
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().slideshow(1)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ boolean isNewData = DataUtil.getInstance().isNewData(ApiKey.slideshow);
|
|
|
|
|
+ if (isNewData) {
|
|
|
|
|
+ List<SlideshowEty> slideshowEtyList = baseMessage.getDataList(SlideshowEty.class);
|
|
|
|
|
+ if (ListUtil.isEmpty(slideshowEtyList)) {
|
|
|
|
|
+ banner.setVisibility(View.GONE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ slideshowEtyLists.clear();
|
|
|
|
|
+ slideshowTitleList.clear();
|
|
|
|
|
+ for (SlideshowEty slideshowEty : slideshowEtyList) {
|
|
|
|
|
+ slideshowEty.setObjects(CommonUtil.getInstance().getValue(slideshowEty.getExt()));
|
|
|
|
|
+ slideshowEtyLists.add(slideshowEty);
|
|
|
|
|
+ slideshowTitleList.add(slideshowEty.getTitle());
|
|
|
|
|
+ }
|
|
|
|
|
+ bindBanner();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //每日必玩
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().playgameDailyOrHotOrTypePlay(1, 10, 0,1,0)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ List<PlayGameEntity> newList = baseMessage.getDatas(PlayGameEntity.class);
|
|
|
|
|
+ if(everyDayPlayListData.isEmpty() && !ListUtil.isEmpty(newList)) {//有缓存时不会加载,没有缓存时获取到数据会加载
|
|
|
|
|
+ everyDayPlayList.getAdapter().notifyDataSetChanged();
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //近期最热
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().playgameDailyOrHotOrTypePlay(1, 10, 0,1,0)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ List<PlayGameEntity> newList = baseMessage.getDatas(PlayGameEntity.class);
|
|
|
|
|
+ if(hotListData.isEmpty() && !ListUtil.isEmpty(newList)) {//有缓存时不会加载,没有缓存时获取到数据会加载
|
|
|
|
|
+ recentHoeList.getAdapter().notifyDataSetChanged();
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ private void notifyDataSetChanged() {
|
|
|
|
|
+ refresh.setRefreshing(false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * tab
|
|
|
|
|
+ * @param
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initTab(){
|
|
|
|
|
+ List<FindTag> newList = new ArrayList<>();
|
|
|
|
|
+ newList.add(new FindTag(1002, "平台游戏"));
|
|
|
|
|
+ newList.add(new FindTag(1003, "小米游戏"));
|
|
|
|
|
+ newList.add(new FindTag(1004, "腾讯游戏"));
|
|
|
|
|
+ newList.add(new FindTag(1099, "其他"));
|
|
|
|
|
+ if (!ListUtil.isEmpty(newList)) {
|
|
|
|
|
+ list.clear();
|
|
|
|
|
+ ListUtil.addAll(list, newList);
|
|
|
|
|
+ for(FindTag findTag:list){
|
|
|
|
|
+ mAdapter.add(FgtPlayGameSon.newInstance(findTag.getId()), findTag.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ pager.setAdapter(mAdapter);
|
|
|
|
|
+ indicator.setupWithViewPager(pager);
|
|
|
|
|
+ pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPageScrolled(int i, float v, int i1) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPageSelected(int i) {
|
|
|
|
|
+ FIND_TAG.onEvent("find_tag_name", ListUtil.hasIndex(list, i - 1) );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPageScrollStateChanged(int i) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ CommonUtil.getInstance().reflex(indicator, activity);
|
|
|
|
|
+// pager.setOffscreenPageLimit(mAdapter.getCount());
|
|
|
|
|
+ notifyDataSetChanged();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @OnClick({R.id.every_day_more_tv, R.id.recent_hot_more_tv, R.id.bottom_line})
|
|
|
|
|
+ public void onViewClicked(View view) {
|
|
|
|
|
+ switch (view.getId()) {
|
|
|
|
|
+ case R.id.every_day_more_tv:
|
|
|
|
|
+ Jump2View.getInstance().goEverydayOrCurrentHotGame(activity, 0);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.recent_hot_more_tv:
|
|
|
|
|
+ Jump2View.getInstance().goEverydayOrCurrentHotGame(activity, 1);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.bottom_line://我是有底线的,双击我回到顶部
|
|
|
|
|
+ scrollView.fullScroll(NestedScrollView.FOCUS_UP);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|