| | |
| | | package com.mugua.mgvideo.ui.recommend; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import androidx.viewpager.widget.PagerAdapter; |
| | | import android.view.View; |
| | | import android.view.View.OnClickListener; |
| | | import android.view.ViewGroup; |
| | |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.mugua.mgvideo.MGVideoApplication; |
| | | import com.mugua.mgvideo.entity.HomeAd; |
| | | import com.nostra13.universalimageloader.core.DisplayImageOptions; |
| | | import com.nostra13.universalimageloader.core.ImageLoader; |
| | | import com.nostra13.universalimageloader.core.assist.ImageScaleType; |
| | | import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; |
| | | import com.mugua.mgvideo.entity.HomeAd; |
| | | import com.yeshi.base.utils.JumpActivityUtil; |
| | | import com.yeshi.video.ui.VideoDetailActivity; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import androidx.viewpager.widget.PagerAdapter; |
| | | |
| | | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade; |
| | | |
| | | public class RecommendTopAdapter extends PagerAdapter { |
| | | |
| | | private ImageLoader imageLoader = ImageLoader.getInstance(); |
| | | private ImageLoader imageLoader = ImageLoader.getInstance(); |
| | | |
| | | private DisplayImageOptions options; |
| | | private DisplayImageOptions options; |
| | | |
| | | private List<HomeAd> mHomeAds; |
| | | private List<HomeAd> mHomeAds; |
| | | |
| | | private Context context; |
| | | private Context context; |
| | | |
| | | public RecommendTopAdapter(List<HomeAd> homeAds, Context context) { |
| | | super(); |
| | | this.context = context; |
| | | this.mHomeAds = homeAds; |
| | | this.options = new DisplayImageOptions.Builder() |
| | | .resetViewBeforeLoading(true).cacheInMemory(true) |
| | | .cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY) |
| | | .considerExifParams(true) |
| | | .displayer(new FadeInBitmapDisplayer(300)).build(); |
| | | } |
| | | public RecommendTopAdapter(List<HomeAd> homeAds, Context context) { |
| | | super(); |
| | | this.context = context; |
| | | this.mHomeAds = homeAds; |
| | | this.options = new DisplayImageOptions.Builder() |
| | | .resetViewBeforeLoading(true).cacheInMemory(true) |
| | | .cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY) |
| | | .considerExifParams(true) |
| | | .displayer(new FadeInBitmapDisplayer(300)).build(); |
| | | } |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mHomeAds == null ? 0 : mHomeAds.size(); |
| | | } |
| | | @Override |
| | | public int getCount() { |
| | | return mHomeAds == null ? 0 : mHomeAds.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object instantiateItem(ViewGroup container, final int position) { |
| | | ImageView view = new ImageView(container.getContext()); |
| | | view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, |
| | | LayoutParams.MATCH_PARENT)); |
| | | view.setScaleType(ScaleType.FIT_XY); |
| | | view.setOnClickListener(new OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = null; |
| | | if (mHomeAds.get(position).getLinkType() == 1) { |
| | | intent = new Intent(v.getContext(), |
| | | VideoDetailActivity.class); |
| | | intent.putExtra("video_info", mHomeAds.get(position) |
| | | .getVideo()); |
| | | } else { |
| | | try { |
| | | intent = new Intent(v.getContext(), Class |
| | | .forName(mHomeAds.get(position).getClazz())); |
| | | if (mHomeAds.get(position).getParams() != null) { |
| | | JSONObject object = new JSONObject(mHomeAds |
| | | .get(position).getParams() |
| | | .replace("\\", "")); |
| | | @SuppressWarnings("unchecked") |
| | | Iterator<String> its = object.keys(); |
| | | while (its.hasNext()) { |
| | | String key = its.next(); |
| | | String value = object.optString(key); |
| | | intent.putExtra(key, value); |
| | | intent.putExtra("isPush", true); |
| | | } |
| | | } |
| | | @Override |
| | | public Object instantiateItem(ViewGroup container, final int position) { |
| | | ImageView view = new ImageView(container.getContext()); |
| | | view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, |
| | | LayoutParams.MATCH_PARENT)); |
| | | view.setScaleType(ScaleType.FIT_XY); |
| | | view.setOnClickListener(new OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = null; |
| | | if (mHomeAds.get(position).getLinkType() == 1) { |
| | | intent = new Intent(v.getContext(), |
| | | VideoDetailActivity.class); |
| | | intent.putExtra("video_info", mHomeAds.get(position) |
| | | .getVideo()); |
| | | } else { |
| | | try { |
| | | intent = new Intent(v.getContext(), Class |
| | | .forName(JumpActivityUtil.filterActivityName(mHomeAds.get(position).getClazz()))); |
| | | if (mHomeAds.get(position).getParams() != null) { |
| | | JSONObject object = new JSONObject(mHomeAds |
| | | .get(position).getParams() |
| | | .replace("\\", "")); |
| | | @SuppressWarnings("unchecked") |
| | | Iterator<String> its = object.keys(); |
| | | while (its.hasNext()) { |
| | | String key = its.next(); |
| | | String value = object.optString(key); |
| | | intent.putExtra(key, value); |
| | | intent.putExtra("isPush", true); |
| | | } |
| | | } |
| | | |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | MGVideoApplication.application.startActivity(intent); |
| | | } |
| | | }); |
| | | Glide.with(context).load(mHomeAds.get(position).getPicture()) |
| | | .transition(withCrossFade()).into(view); |
| | | // imageLoader.displayImage(mHomeAds.get(position).getPicture(), view, |
| | | // options); |
| | | container.addView(view); |
| | | return view; |
| | | } |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | MGVideoApplication.application.startActivity(intent); |
| | | } |
| | | }); |
| | | Glide.with(context).load(mHomeAds.get(position).getPicture()) |
| | | .transition(withCrossFade()).into(view); |
| | | // imageLoader.displayImage(mHomeAds.get(position).getPicture(), view, |
| | | // options); |
| | | container.addView(view); |
| | | return view; |
| | | } |
| | | |
| | | @Override |
| | | public void destroyItem(ViewGroup container, int position, Object object) { |
| | | container.removeView((View) object); |
| | | } |
| | | @Override |
| | | public void destroyItem(ViewGroup container, int position, Object object) { |
| | | container.removeView((View) object); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isViewFromObject(View view, Object object) { |
| | | return view == object; |
| | | } |
| | | @Override |
| | | public boolean isViewFromObject(View view, Object object) { |
| | | return view == object; |
| | | } |
| | | |
| | | @Override |
| | | public CharSequence getPageTitle(int position) { |
| | | return mHomeAds.get(position).getTitle(); |
| | | } |
| | | @Override |
| | | public CharSequence getPageTitle(int position) { |
| | | return mHomeAds.get(position).getTitle(); |
| | | } |
| | | } |