1package eu.siacs.conversations.ui;
 2
 3import android.util.Log;
 4
 5import androidx.appcompat.app.AppCompatActivity;
 6import androidx.appcompat.app.AppCompatDelegate;
 7
 8import eu.siacs.conversations.Conversations;
 9import eu.siacs.conversations.ui.util.SettingsUtils;
10
11public abstract class BaseActivity extends AppCompatActivity {
12    private Boolean isDynamicColors;
13
14    @Override
15    public void onStart() {
16        super.onStart();
17        final int desiredNightMode = Conversations.getDesiredNightMode(this);
18        if (setDesiredNightMode(desiredNightMode)) {
19            return;
20        }
21        final boolean isDynamicColors = Conversations.isDynamicColorsDesired(this);
22        setDynamicColors(isDynamicColors);
23    }
24
25    @Override
26    protected void onResume(){
27        super.onResume();
28        SettingsUtils.applyScreenshotSetting(this);
29    }
30
31    public void setDynamicColors(final boolean isDynamicColors) {
32        if (this.isDynamicColors == null) {
33            this.isDynamicColors = isDynamicColors;
34        } else {
35            if (this.isDynamicColors != isDynamicColors) {
36                Log.i(
37                        "Recreating {} because dynamic color setting has changed",
38                        getClass().getSimpleName());
39                recreate();
40            }
41        }
42    }
43
44    public boolean setDesiredNightMode(final int desiredNightMode) {
45        if (desiredNightMode == AppCompatDelegate.getDefaultNightMode()) {
46            return false;
47        }
48        AppCompatDelegate.setDefaultNightMode(desiredNightMode);
49        Log.i("Recreating {} because desired night mode has changed", getClass().getSimpleName());
50        recreate();
51        return true;
52    }
53}