shts / StoriesProgressView

show horizontal progress like instagram stories.
Apache License 2.0
885 stars 203 forks source link

How to handle progressview with viewpager? #33

Open Bajranghudda1 opened 5 years ago

Bajranghudda1 commented 5 years ago

I am using view pager for sliding effect for more than one user's stories, is it possible to handle touch event with viewpager?

I am facing problem when sliding one user's story to another user's story, when sliding current story paused, and right now there is no event to resume back.

Please suggest me a better way if there is any :+1:

PranavBhatt25 commented 3 years ago

Looking for the same. It's working with viewpager when auto slider based on StoriesProgressView's setStoryDuration so at that time i'm change viewpager's setCurrentItem and working fine but i want to do reverse process like user swipe view pager and StoriesProgressView progerss bar's position set based on viewpager's current postion.

Looking forward for solution!

public class MainActivityNew extends AppCompatActivity {

    Context context;
    WrapContentHeightViewPager mPager;
    ProgressBar slider_progress;
    RelativeLayout main_drawer;
    StoriesProgressView storiesProgressView;

    final int NUM_PAGES = 6;
    private int currentPage2 = 0;
    private final int[] resources = new int[]{
            R.drawable.sample1,
            R.drawable.sample2,
            R.drawable.sample3,
            R.drawable.sample4,
            R.drawable.sample5,
            R.drawable.sample6,
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main_new);
        context = this;

        mPager = findViewById(R.id.pager);
        storiesProgressView = (StoriesProgressView) findViewById(R.id.story_progress_view);
        slider_progress = findViewById(R.id.slider_progress);
        main_drawer = findViewById(R.id.main_drawer);

        try {
            storiesProgressView.setStoriesCount(NUM_PAGES);
            storiesProgressView.setStoryDuration(3000L);
            storiesProgressView.startStories();
            storiesProgressView.setStoriesListener(new StoriesProgressView.StoriesListener() {

                @Override
                public void onNext() {
                    if (NUM_PAGES == 1) {
                        currentPage2 = 0;
                        storiesProgressView.setStoriesCount(NUM_PAGES);
                        storiesProgressView.setStoryDuration(3000L);
                        storiesProgressView.startStories();
                        if (mPager != null) {
                            mPager.setCurrentItem(0);
                        }
                    } else {
                        currentPage2 = currentPage2 + 1;
                        mPager.setCurrentItem(currentPage2, true);
                    }
                }

                @Override
                public void onPrev() {
                    currentPage2 = currentPage2 - 1;
                    mPager.setCurrentItem(currentPage2--, true);
                }

                @Override
                public void onComplete() {
                    storiesProgressView.destroy();
                    currentPage2 = currentPage2 + 1;
                    if (currentPage2 == NUM_PAGES) {
                        currentPage2 = 0;
                        storiesProgressView.setStoriesCount(NUM_PAGES);
                        storiesProgressView.setStoryDuration(3000L);
                        storiesProgressView.startStories();
                        if (mPager != null) {
                            mPager.setCurrentItem(0);
                        }
                    }
                }
            });

            SlidingImage_Adapter2 adapter = new SlidingImage_Adapter2(context, resources);
            mPager.setAdapter(adapter);

        } catch (
                Exception e) {
            e.getStackTrace();
        }
    }
}