Skip to content

Commit

Permalink
Merge pull request #4 from the-reach-trust/master
Browse files Browse the repository at this point in the history
Fix steps on lost context
  • Loading branch information
dimorinny authored Sep 18, 2018
2 parents 64d2c7f + 7ef4582 commit 98c03d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
Expand All @@ -31,5 +31,5 @@ repositories {

dependencies {
implementation project(':showcasecard')
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:appcompat-v7:26.0.2'
}
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
buildscript {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
classpath 'com.android.tools.build:gradle:3.0.0-beta5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
}
Expand Down
2 changes: 1 addition & 1 deletion showcasecard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
}

dependencies {
api 'com.android.support:appcompat-v7:26.0.1'
api 'com.android.support:appcompat-v7:26.0.2'
}
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void dismiss() {
*/
private void tryShowNextTip() {

if (!isContextActive()) {
return;
}

if (currentlyDisplayedTipIndex >= items.size() - 1) {

// end of tips reached.
Expand Down Expand Up @@ -133,6 +137,10 @@ private void displayTip(ShowCaseStep item) {

private void doDisplayTip(ShowCaseStep item) {

if (!isContextActive()) {
return;
}

if (showCaseView != null) {
// completely remove old view now:
showCaseView.hide();
Expand Down Expand Up @@ -184,6 +192,18 @@ public void setSteps(List<ShowCaseStep> items) {
this.items = items;
}

/**
* Returns true if the attached Context is still active / not shutting down.
*/
private boolean isContextActive() {
if (fragment != null) {
return fragment.isAdded();
} else if (activity != null) {
return !activity.isFinishing();
}
return true;
}

public static class Builder {

@Nullable
Expand Down

0 comments on commit 98c03d1

Please sign in to comment.