Skip to content

Commit

Permalink
Add support to detect post splash
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavpandey committed Jul 24, 2024
1 parent 74d5103 commit b29978b
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 Pranav Pandey
* Copyright 2018-2024 Pranav Pandey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Expand Down Expand Up @@ -56,6 +57,11 @@ public abstract class DynamicSplashActivity extends DynamicSystemActivity
*/
protected static final String ADS_STATE_SPLASH_FRAGMENT_TAG = "ads_state_splash_fragment_tag";

/**
* Post splash key to maintain its state.
*/
protected static final String ADS_STATE_SPLASH_POST = "ads_state_splash_post";

/**
* Boolean to save the fragment state.
*/
Expand All @@ -66,6 +72,11 @@ public abstract class DynamicSplashActivity extends DynamicSystemActivity
*/
protected Intent mNextActivityIntent;

/**
* {@code true} if {@link #onPostSplash()} has been called at least once.
*/
private boolean mPostSplash;

/**
* Content fragment used by this activity.
*/
Expand Down Expand Up @@ -117,6 +128,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
protected void onNewIntent(@Nullable Intent intent, boolean newIntent) {
super.onNewIntent(intent, newIntent);

if (newIntent) {
mPostSplash = false;
}

onUpdateIntent(intent, newIntent);

if (!(mContentFragment instanceof DynamicSplashFragment)) {
Expand Down Expand Up @@ -200,6 +215,13 @@ public void onPause() {
super.onPause();
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);

outState.putBoolean(ADS_STATE_SPLASH_POST, mPostSplash);
}

@Override
protected void onSetFallbackActivityOptions() {
super.onSetFallbackActivityOptions();
Expand All @@ -214,6 +236,11 @@ public void onPreSplash() {
onUpdateIntent(getIntent(), false);
}

@Override
public void onPostSplash() {
mPostSplash = true;
}

/**
* Returns the next activity intent.
*
Expand All @@ -232,6 +259,15 @@ public void setNextActivityIntent(@Nullable Intent intent) {
this.mNextActivityIntent = intent;
}

/**
* Returns whether the {@link #onPostSplash()} has been called at least once.
*
* @return {@code true} if the {@link #onPostSplash()} has been called at least once.
*/
public boolean isPostSplash() {
return mPostSplash;
}

/**
* Start the activity intent with a fade animation.
*
Expand Down

0 comments on commit b29978b

Please sign in to comment.