Devlight / InfiniteCycleViewPager

Infinite cycle ViewPager with two-way orientation and interactive effect.
Apache License 2.0
5.75k stars 831 forks source link

Takes too long to reload fragment #10

Closed MrThiago closed 8 years ago

MrThiago commented 8 years ago

I have used your adapter in my fragment (A). Once you click on a card I will load Activity (B), or the back press or on close of Activity (B). Fragment (A), takes too long to load. only show a full back screen and the App becomes unresponsive.

My code:

@BindView(R.id.hicvp) HorizontalInfiniteCycleViewPager hicvp;

hicvp.setAdapter(new HorizontalPagerAdapter(getActivity(), false, newContent, imgLoader));
            hicvp.setScrollDuration(500);
            hicvp.setInterpolator(AnimationUtils.loadInterpolator(getActivity(), android.R.anim.decelerate_interpolator));
            hicvp.setMediumScaled(false);
            hicvp.setMaxPageScale(0.95F);
            hicvp.setMinPageScale(0.82F);
            hicvp.setCenterPageScaleOffset(30.0F);
            hicvp.setMinPageScaleOffset(1.0F);

public class HorizontalPagerAdapter extends PagerAdapter {
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private boolean mIsTwoWay;
    private ArrayList<ContentList> newContent;
    private ImageLoader imgLoader;

    public HorizontalPagerAdapter(final Context context, final boolean isTwoWay, ArrayList<ContentList> newContent, ImageLoader imgLoader) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
        mIsTwoWay = isTwoWay;
        this.newContent = newContent;
        this.imgLoader = imgLoader;
    }

    @Override
    public int getCount() {
        return newContent.size();
    }

    @Override
    public int getItemPosition(final Object object) {
        return POSITION_NONE;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        final View view = mLayoutInflater.inflate(R.layout.movie_detail, container, false);
        container.addView(view);
        //------
        //VIEWs
        CardView cardView = (CardView) view.findViewById(R.id.movie_card_wrapper);
        cardView.setCardBackgroundColor(ContextCompat.getColor(mContext, R.color.white));

        //TITLES
        final ImageView movie_poster = (ImageView) view.findViewById(R.id.movie_poster);
        final TextView movie_title = (TextView) view.findViewById(R.id.movie_title);
        final TextView movie_title_year = (TextView) view.findViewById(R.id.movie_title_year);

        //DATA
        final ContentList data = newContent.get(position);

        //poster image
        String imgUri = data.getImages();
        imgLoader.displayImage(imgUri, R.drawable.img_loading, movie_poster);

        //titles
        movie_title.setText(data.getTitle());
        movie_title_year.setText(data.getYear());

        //PlayMovie
        movie_poster.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnalyticSingleton.getInstance().addData(Screen.VIDEO_CONTENT, String.valueOf(data.getCategory()), data.getTitle(), data.getId());
                showVideo(mContext, data, false);

                Toast.makeText(mContext, "movie_poster CLICK - ", Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }

    @Override
    public boolean isViewFromObject(final View view, final Object object) {
        return view.equals(object);
    }

    @Override
    public void destroyItem(final ViewGroup container, final int position, final Object object) {
        container.removeView((View) object);
    }
}
GIGAMOLE commented 8 years ago

Hello. Thanks for issue. Is that the problem of ICVP? Maybe there another problem.

MrThiago commented 8 years ago

I believe it is. When I change to another library it works fine.

Does it has anything to do with restoring state ? Thanks

On Tuesday, 30 August 2016, GIGAMOLE notifications@github.com wrote:

Hello. Thanks for issue. Is that the problem of ICVP? Maybe there another problem.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DevLight-Mobile-Agency/InfiniteCycleViewPager/issues/10#issuecomment-243405718, or mute the thread https://github.com/notifications/unsubscribe-auth/AHF_znvFBrjT33rkABYh8ln_u1HVmK7Jks5qlA48gaJpZM4JwWZN .

GIGAMOLE commented 8 years ago

What you mean about new library? Restoring state of what? PagerAdapter provide this.

MrThiago commented 8 years ago

I try using this other library https://github.com/rubensousa/ViewPagerCards. This works. But I like your library style

MrThiago commented 8 years ago

Hi again. I discovered the problem. I am called the API and set the adapter on onResume.

Because My app is Fragments, whenever you go back to that section i will call the API again. Here is where is freezes.