Skip to content

Commit b29978b

Browse files
committed
Add support to detect post splash
1 parent 74d5103 commit b29978b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/splash/activity/DynamicSplashActivity.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Pranav Pandey
2+
* Copyright 2018-2024 Pranav Pandey
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import android.view.View;
2323

2424
import androidx.annotation.ColorInt;
25+
import androidx.annotation.NonNull;
2526
import androidx.annotation.Nullable;
2627
import androidx.annotation.StyleRes;
2728
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -56,6 +57,11 @@ public abstract class DynamicSplashActivity extends DynamicSystemActivity
5657
*/
5758
protected static final String ADS_STATE_SPLASH_FRAGMENT_TAG = "ads_state_splash_fragment_tag";
5859

60+
/**
61+
* Post splash key to maintain its state.
62+
*/
63+
protected static final String ADS_STATE_SPLASH_POST = "ads_state_splash_post";
64+
5965
/**
6066
* Boolean to save the fragment state.
6167
*/
@@ -66,6 +72,11 @@ public abstract class DynamicSplashActivity extends DynamicSystemActivity
6672
*/
6773
protected Intent mNextActivityIntent;
6874

75+
/**
76+
* {@code true} if {@link #onPostSplash()} has been called at least once.
77+
*/
78+
private boolean mPostSplash;
79+
6980
/**
7081
* Content fragment used by this activity.
7182
*/
@@ -117,6 +128,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
117128
protected void onNewIntent(@Nullable Intent intent, boolean newIntent) {
118129
super.onNewIntent(intent, newIntent);
119130

131+
if (newIntent) {
132+
mPostSplash = false;
133+
}
134+
120135
onUpdateIntent(intent, newIntent);
121136

122137
if (!(mContentFragment instanceof DynamicSplashFragment)) {
@@ -200,6 +215,13 @@ public void onPause() {
200215
super.onPause();
201216
}
202217

218+
@Override
219+
public void onSaveInstanceState(@NonNull Bundle outState) {
220+
super.onSaveInstanceState(outState);
221+
222+
outState.putBoolean(ADS_STATE_SPLASH_POST, mPostSplash);
223+
}
224+
203225
@Override
204226
protected void onSetFallbackActivityOptions() {
205227
super.onSetFallbackActivityOptions();
@@ -214,6 +236,11 @@ public void onPreSplash() {
214236
onUpdateIntent(getIntent(), false);
215237
}
216238

239+
@Override
240+
public void onPostSplash() {
241+
mPostSplash = true;
242+
}
243+
217244
/**
218245
* Returns the next activity intent.
219246
*
@@ -232,6 +259,15 @@ public void setNextActivityIntent(@Nullable Intent intent) {
232259
this.mNextActivityIntent = intent;
233260
}
234261

262+
/**
263+
* Returns whether the {@link #onPostSplash()} has been called at least once.
264+
*
265+
* @return {@code true} if the {@link #onPostSplash()} has been called at least once.
266+
*/
267+
public boolean isPostSplash() {
268+
return mPostSplash;
269+
}
270+
235271
/**
236272
* Start the activity intent with a fade animation.
237273
*

0 commit comments

Comments
 (0)