Skip to content

Commit

Permalink
Merge pull request #14 from shts/release/3.0.0
Browse files Browse the repository at this point in the history
Release/3.0.0
  • Loading branch information
shts committed Aug 21, 2018
2 parents b0927b1 + 6f177df commit 8973640
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
13 changes: 1 addition & 12 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -62,7 +62,9 @@ protected void onCreate(Bundle savedInstanceState) {
// or
// storiesProgressView.setStoriesCountWithDurations(durations);
storiesProgressView.setStoriesListener(this);
storiesProgressView.startStories();
// storiesProgressView.startStories();
counter = 2;
storiesProgressView.startStories(counter);

image = (ImageView) findViewById(R.id.image);
image.setImageResource(resources[counter]);
Expand Down
Expand Up @@ -73,6 +73,16 @@ void setMinWithoutCallback() {
}
}

void setMaxWithoutCallback() {
maxProgressView.setBackgroundResource(R.color.progress_max_active);

maxProgressView.setVisibility(VISIBLE);
if (animation != null) {
animation.setAnimationListener(null);
animation.cancel();
}
}

private void finishProgress(boolean isMax) {
if (isMax) maxProgressView.setBackgroundResource(R.color.progress_max_active);
maxProgressView.setVisibility(isMax ? VISIBLE : GONE);
Expand Down
Expand Up @@ -15,6 +15,8 @@

public class StoriesProgressView extends LinearLayout {

private static final String TAG = StoriesProgressView.class.getSimpleName();

private final LayoutParams PROGRESS_BAR_LAYOUT_PARAM = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
private final LayoutParams SPACE_LAYOUT_PARAM = new LayoutParams(5, LayoutParams.WRAP_CONTENT);

Expand All @@ -24,17 +26,19 @@ public class StoriesProgressView extends LinearLayout {
/**
* pointer of running animation
*/
private int current = 0;
private int current = -1;
private StoriesListener storiesListener;
boolean isReverse;
boolean isComplete;

private boolean isSkipStart;
private boolean isReverseStart;

public interface StoriesListener {
public void onNext();
void onNext();

public void onPrev();
void onPrev();

public void onComplete();
void onComplete();
}

public StoriesProgressView(Context context) {
Expand Down Expand Up @@ -114,18 +118,23 @@ public void setStoriesListener(StoriesListener storiesListener) {
* Skip current story
*/
public void skip() {
if (isSkipStart || isReverseStart) return;
if (isComplete) return;
if (current < 0) return;
PausableProgressBar p = progressBars.get(current);
isSkipStart = true;
p.setMax();
}

/**
* Reverse current story
*/
public void reverse() {
if (isSkipStart || isReverseStart) return;
if (isComplete) return;
isReverse = true;
if (current < 0) return;
PausableProgressBar p = progressBars.get(current);
isReverseStart = true;
p.setMin();
}

Expand Down Expand Up @@ -164,8 +173,7 @@ public void onStartProgress() {

@Override
public void onFinishProgress() {
if (isReverse) {
isReverse = false;
if (isReverseStart) {
if (storiesListener != null) storiesListener.onPrev();
if (0 <= (current - 1)) {
PausableProgressBar p = progressBars.get(current - 1);
Expand All @@ -174,6 +182,7 @@ public void onFinishProgress() {
} else {
progressBars.get(current).startProgress();
}
isReverseStart = false;
return;
}
int next = current + 1;
Expand All @@ -184,6 +193,7 @@ public void onFinishProgress() {
isComplete = true;
if (storiesListener != null) storiesListener.onComplete();
}
isSkipStart = false;
}
};
}
Expand All @@ -195,6 +205,16 @@ public void startStories() {
progressBars.get(0).startProgress();
}

/**
* Start progress animation from specific progress
*/
public void startStories(int from) {
for (int i = 0; i < from; i++) {
progressBars.get(i).setMaxWithoutCallback();
}
progressBars.get(from).startProgress();
}

/**
* Need to call when Activity or Fragment destroy
*/
Expand All @@ -208,13 +228,15 @@ public void destroy() {
* Pause story
*/
public void pause() {
if (current < 0) return;
progressBars.get(current).pauseProgress();
}

/**
* Resume story
*/
public void resume() {
if (current < 0) return;
progressBars.get(current).resumeProgress();
}
}
6 changes: 3 additions & 3 deletions library/src/main/res/layout/pausable_progress.xml
Expand Up @@ -7,21 +7,21 @@
<View
android:id="@+id/back_progress"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_height="@dimen/progress_bar_height"
android:background="@color/progress_secondary" />

<View
android:id="@+id/front_progress"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_height="@dimen/progress_bar_height"
android:background="@color/progress_primary"
android:visibility="invisible"
tools:visibility="visible"/>

<View
android:id="@+id/max_progress"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_height="@dimen/progress_bar_height"
android:background="#fff"
android:visibility="gone" />
</FrameLayout>
4 changes: 4 additions & 0 deletions library/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="progress_bar_height">2dp</dimen>
</resources>

0 comments on commit 8973640

Please sign in to comment.