BaseActivity.java

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