Skip to content

Commit

Permalink
adding new feature to sequence showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
leocabral committed Sep 15, 2015
1 parent 5577fbd commit 38a2f7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MaterialShowcaseSequence implements IDetachedListener {
Activity mActivity;
private ShowcaseConfig mConfig;
private int mSequencePosition = 0;
private String singleUseShowcaseID;

public MaterialShowcaseSequence(Activity activity) {
mActivity = activity;
Expand All @@ -29,11 +30,16 @@ public MaterialShowcaseSequence(Activity activity, String sequenceID) {
}

public MaterialShowcaseSequence addSequenceItem(View targetView, String content, String dismissText) {
return addSequenceItem(targetView, content, dismissText, null);
}

public MaterialShowcaseSequence addSequenceItem(View targetView, String content, String dismissText, String showcaseID) {

MaterialShowcaseView sequenceItem = new MaterialShowcaseView.Builder(mActivity)
.setTarget(targetView)
.setDismissText(dismissText)
.setContentText(content)
.showUntil(showcaseID)
.build();

if (mConfig != null) {
Expand All @@ -51,13 +57,14 @@ public MaterialShowcaseSequence addSequenceItem(MaterialShowcaseView sequenceIte

public MaterialShowcaseSequence singleUse(String sequenceID) {
mSingleUse = true;
mPrefsManager = new PrefsManager(mActivity, sequenceID);
mPrefsManager = new PrefsManager(mActivity);
singleUseShowcaseID = sequenceID;
return this;
}

public boolean hasFired() {

if (mPrefsManager.getSequenceStatus() == PrefsManager.SEQUENCE_FINISHED) {
if (mPrefsManager.getSequenceStatus(singleUseShowcaseID) == PrefsManager.SEQUENCE_FINISHED) {
return true;
}

Expand All @@ -78,7 +85,7 @@ public void start() {
* See if we have started this sequence before, if so then skip to the point we reached before
* instead of showing the user everything from the start
*/
mSequencePosition = mPrefsManager.getSequenceStatus();
mSequencePosition = mPrefsManager.getSequenceStatus(singleUseShowcaseID);

if (mSequencePosition > 0) {
for (int i = 0; i < mSequencePosition; i++) {
Expand All @@ -104,7 +111,7 @@ private void showNextItem() {
* We've reached the end of the sequence, save the fired state
*/
if (mSingleUse) {
mPrefsManager.setFired();
mPrefsManager.setFired(singleUseShowcaseID);
}
}
}
Expand All @@ -125,7 +132,7 @@ public void onShowcaseDetached(MaterialShowcaseView showcaseView, boolean wasDis
*/
if (mPrefsManager != null) {
mSequencePosition++;
mPrefsManager.setSequenceStatus(mSequencePosition);
mPrefsManager.setSequenceStatus(mSequencePosition, singleUseShowcaseID);
}

showNextItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ public Builder setContentText(CharSequence text) {
* so the user can tell if he wants to be warned every time.
*/
public Builder showUntil(String showAgainShowcaseID) {
showcaseView.showUntil(showAgainShowcaseID);
if (showAgainShowcaseID != null) {
showcaseView.showUntil(showAgainShowcaseID);
}
return this;
}

Expand Down Expand Up @@ -626,6 +628,11 @@ public boolean show(final Activity activity) {
}

if (mPrefsManager.hasFired(showAgainShowcaseID)) {

if (mDetachedListener != null) {
mDetachedListener.onShowcaseDetached(this, true);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ private void presentShowcaseSequence() {
ShowcaseConfig config = new ShowcaseConfig();
config.setDelay(500); // half second between each showcase view

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, SHOWCASE_ID);
MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this);

sequence.setConfig(config);

sequence.addSequenceItem(mButtonOne,
"This is button one", "GOT IT");
"This is button one", "GOT IT", "asd");

sequence.addSequenceItem(mButtonTwo,
"This is button two", "GOT IT");
"This is button two", "GOT IT", "asdd");

sequence.addSequenceItem(mButtonThree,
"This is button three", "GOT IT");
"This is button three", "GOT IT", "asddd");

sequence.start();

Expand Down

0 comments on commit 38a2f7c

Please sign in to comment.