Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle progressview with viewpager? #33

Open
Bajranghudda1 opened this issue Sep 24, 2019 · 1 comment
Open

How to handle progressview with viewpager? #33

Bajranghudda1 opened this issue Sep 24, 2019 · 1 comment

Comments

@Bajranghudda1
Copy link

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 👍

@PranavBhatt25
Copy link

PranavBhatt25 commented Jan 21, 2021

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();
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants