StoriesProgressView

repository·master·Indexed 21 days ago

https://github.com/shts/storiesprogressview

An Android library that provides a horizontal progress bar UI similar to Instagram stories for visualizing the progress of multiple content segments. It includes features for controlling story progression via skip, reverse, pause, and resume methods, and provides a StoriesListener interface to handle onNext, onPrev, and onComplete events.

Tokens
1.2K
Snippets
5
Records
6
Agent score
25%

What's inside StoriesProgressView

  1. Add StoriesProgressView to XML layouts

    master

    Include the StoriesProgressView in your XML layout files. It is typically used at the top of the screen with a small height (e.g., 3dp).

    <jp.shts.android.storiesprogressview.StoriesProgressView
        android:id="@+id/stories"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_gravity="top"
        android:layout_marginTop="8dp" />
  2. Install StoriesProgressView via JitPack

    master

    To use StoriesProgressView in your Android project, add the JitPack repository to your root build.gradle file and then add the dependency to your module-level build.gradle file.

    // In your root build.gradle
    allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }
    
    // In your app/module build.gradle
    dependencies {
        implementation 'com.github.shts:StoriesProgressView:3.0.0'
    }
  3. Use StoriesProgressView in an Activity

    master

    To implement the progress view, implement the StoriesProgressView.StoriesListener interface in your Activity. You must initialize the view with the number of stories and the duration per story, then call startStories().

    Important: You must call storiesProgressView.destroy() in onDestroy() to prevent memory leaks.

    public class YourActivity extends AppCompatActivity implements StoriesProgressView.StoriesListener {
        private StoriesProgressView storiesProgressView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            storiesProgressView = (StoriesProgressView) findViewById(R.id.stories);
            storiesProgressView.setStoriesCount(PROGRESS_COUNT); // set number of stories
            storiesProgressView.setStoryDuration(1200L); // set duration in milliseconds
            storiesProgressView.setStoriesListener(this);
            storiesProgressView.startStories();
        }
    
        @Override
        public void onNext() {
            // Called when moving to the next story
        }
    
        @Override
        public void onPrev() {
            // Called when finished reverse animation
        }
    
        @Override
        public void onComplete() {
            // Called when all stories are finished
        }
    
        @Override
        protected void onDestroy() {
            // Very important!
            storiesProgressView.destroy();
            super.onDestroy();
        }
    }
  4. StoriesProgressView.StoriesListener interface

    master

    Implement this interface to respond to story progression events.

    MethodDescription
    onNext()Triggered when the view moves to the next story.
    onPrev()Triggered when the reverse animation is completed.
    onComplete()Triggered when all stories have been viewed.