/* * Copyright 2014 trinea.cn All right reserved. This software is the confidential and proprietary information of * trinea.cn ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with trinea.cn. */ package com.gh.gamecenter.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.view.View; import android.view.ViewGroup; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.common.util.DataLogUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DirectUtils; import com.gh.common.util.ImageUtils; import com.gh.common.util.StringUtils; import com.gh.gamecenter.R; import com.gh.gamecenter.entity.LinkEntity; import java.util.List; /** * ImagePagerAdapter * * @author Trinea 2014-2-23 */ public class ImagePagerAdapter extends RecyclingPagerAdapter { private Context mContext; // private List imageIdList; private List mSlideEntityList; private int mSize; private boolean mIsInfiniteLoop; private String mSource; // private ImageIndicator indicator; public ImagePagerAdapter(Context context, List slideEntityList, boolean isInfiniteLoop, String source) { mContext = context; mSlideEntityList = slideEntityList; mSize = getSize(slideEntityList); mIsInfiniteLoop = isInfiniteLoop; mSource = source; } public int getSize(List sourceList) { return sourceList == null ? 0 : sourceList.size(); } @Override public int getCount() { // Infinite loop return mIsInfiniteLoop ? Integer.MAX_VALUE : getSize(mSlideEntityList); } @Override public View getView(final int position, View view, ViewGroup container) { if (view == null) { view = new SimpleDraweeView(mContext); } int index = getPosition(position); if (index >= mSlideEntityList.size()) return view; final LinkEntity slideEntity = mSlideEntityList.get(index); ImageUtils.display(mContext.getResources(), (SimpleDraweeView) view, slideEntity.getImage(), R.drawable.preload); // indicator.setPosition(mSlideEntityList.mSize(), getPosition(position)); view.setOnClickListener(v -> { int size = mSlideEntityList.size(); if (size == 0) return; // 首页轮播图数据统计 DataLogUtils.uploadLunbotuLog(mContext, slideEntity.getType(), slideEntity.getText(), String.valueOf(getPosition(position) % size + 1)); String entrance = StringUtils.buildString("(游戏-专题:滚动图[" , slideEntity.getText() , "=", slideEntity.getType() , "=", String.valueOf(size + 1) , "])"); DataUtils.onMtaEvent(mContext, "轮播图", mSource, String.valueOf(getPosition(position) % size + 1)); DirectUtils.directToLinkPage(mContext, slideEntity, entrance, "首页游戏"); }); return view; } /** * get really position * * @param position * @return */ private int getPosition(int position) { return mIsInfiniteLoop ? position % mSize : position; } public int getDataSize() { return mSlideEntityList == null ? 0 : mSlideEntityList.size(); } @Override public int getItemPosition(@NonNull Object object) { return POSITION_NONE; } /** * @return the mIsInfiniteLoop */ public boolean isInfiniteLoop() { return mIsInfiniteLoop; } /** * @param isInfiniteLoop the mIsInfiniteLoop to set */ public ImagePagerAdapter setInfiniteLoop(boolean isInfiniteLoop) { this.mIsInfiniteLoop = isInfiniteLoop; return this; } public void checkResetData(List list) { if (mSlideEntityList != list) { mSlideEntityList = list; mSize = getSize(list); } notifyDataSetChanged(); } }