package org.wikipedia;

import android.app.Activity;
import android.app.Application;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import org.jetbrains.annotations.NotNull;
import org.wikipedia.main.MainActivity;
import org.wikipedia.settings.Prefs;
import org.wikipedia.theme.Theme;

public class ActivityLifecycleHandler implements Application.ActivityLifecycleCallbacks {
    private boolean haveMainActivity;
    private boolean anyActivityResumed;

    public boolean haveMainActivity() {
        return haveMainActivity;
    }

    public boolean isAnyActivityResumed() {
        return anyActivityResumed;
    }

    @Override
    public void onActivityCreated(@NotNull Activity activity, Bundle savedInstanceState) {
        WikipediaApp app = WikipediaApp.getInstance();
        if (activity instanceof MainActivity) {
            haveMainActivity = true;
        }
        if (Prefs.shouldMatchSystemTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            Theme currentTheme = app.getCurrentTheme();
            switch (app.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
                case Configuration.UI_MODE_NIGHT_YES:
                    if (!app.getCurrentTheme().isDark()) {
                        app.setCurrentTheme(!app.unmarshalTheme(Prefs.getPreviousThemeId()).isDark() ? Theme.BLACK : app.unmarshalTheme(Prefs.getPreviousThemeId()));
                        Prefs.setPreviousThemeId(currentTheme.getMarshallingId());
                    }
                    break;
                case Configuration.UI_MODE_NIGHT_NO:
                    if (app.getCurrentTheme().isDark()) {
                        app.setCurrentTheme(app.unmarshalTheme(Prefs.getPreviousThemeId()).isDark() ? Theme.LIGHT : app.unmarshalTheme(Prefs.getPreviousThemeId()));
                        Prefs.setPreviousThemeId(currentTheme.getMarshallingId());
                    }
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void onActivityStarted(@NotNull Activity activity) {
    }

    @Override
    public void onActivityResumed(@NotNull Activity activity) {
        anyActivityResumed = true;
    }

    @Override
    public void onActivityPaused(@NotNull Activity activity) {
        anyActivityResumed = false;
    }

    @Override
    public void onActivityStopped(@NotNull Activity activity) {
    }

    @Override
    public void onActivitySaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
    }

    @Override
    public void onActivityDestroyed(@NotNull Activity activity) {
        if (activity instanceof MainActivity) {
            haveMainActivity = false;
        }
    }
}

@@ -183,21 +183,16 @@
 ort 
-org.jetbrains
+androidx
 .ann
@@ -202,19 +202,19 @@
 tion
-s
 .No
-t
+n
 Null;%0A
+%0A
 impo
@@ -490,31 +490,24 @@
 sumed;%0A%0A    
-public 
 boolean have
@@ -567,23 +567,16 @@
  %7D%0A%0A    
-public 
 boolean 
@@ -689,25 +689,25 @@
 yCreated(@No
-t
+n
 Null Activit
@@ -2101,25 +2101,25 @@
 yStarted(@No
-t
+n
 Null Activit
@@ -2186,25 +2186,25 @@
 yResumed(@No
-t
+n
 Null Activit
@@ -2305,25 +2305,25 @@
 tyPaused(@No
-t
+n
 Null Activit
@@ -2426,25 +2426,25 @@
 yStopped(@No
-t
+n
 Null Activit
@@ -2521,25 +2521,25 @@
 nceState(@No
-t
+n
 Null Activit
@@ -2553,17 +2553,17 @@
 ity, @No
-t
+n
 Null Bun
@@ -2638,17 +2638,17 @@
 oyed(@No
-t
+n
 Null Act

Change NotNull to NonNull