mirror of
https://github.com/M66B/FairEmail.git
synced 2026-05-19 13:34:00 +02:00
Cache themed contexts
This commit is contained in:
@@ -36,6 +36,7 @@ import android.os.SystemClock;
|
||||
import android.os.strictmode.Violation;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Printer;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.webkit.CookieManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -65,6 +66,7 @@ public class ApplicationEx extends Application
|
||||
private Thread.UncaughtExceptionHandler prev = null;
|
||||
|
||||
private static final Object lock = new Object();
|
||||
private static final Map<Integer, Context> themeCache = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
@@ -120,6 +122,17 @@ public class ApplicationEx extends Application
|
||||
return context;
|
||||
}
|
||||
|
||||
static Context getThemedContext(Context context, int style) {
|
||||
synchronized (themeCache) {
|
||||
Context tcontext = themeCache.get(style);
|
||||
if (tcontext == null) {
|
||||
tcontext = new ContextThemeWrapper(context.getApplicationContext(), style);
|
||||
themeCache.put(style, tcontext);
|
||||
}
|
||||
return tcontext;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public androidx.work.Configuration getWorkManagerConfiguration() {
|
||||
return new androidx.work.Configuration.Builder()
|
||||
|
||||
@@ -71,7 +71,6 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||
private SharedPreferences prefs;
|
||||
private boolean dark;
|
||||
private int colorAccent;
|
||||
private ContextThemeWrapper ctx;
|
||||
private Tokenizer tokenizer;
|
||||
private Map<String, Integer> encryption = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -106,7 +105,6 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||
dark = Helper.isDarkTheme(context);
|
||||
colorAccent = Helper.resolveColor(context, androidx.appcompat.R.attr.colorAccent);
|
||||
colorAccent = ColorUtils.setAlphaComponent(colorAccent, 5 * 255 / 100);
|
||||
ctx = new ContextThemeWrapper(context.getApplicationContext(), dark ? R.style.ChipDark : R.style.ChipLight);
|
||||
|
||||
addTextChangedListener(new TextWatcher() {
|
||||
private Integer backspace = null;
|
||||
@@ -346,6 +344,7 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||
String text = (TextUtils.isEmpty(personal) ? email : personal);
|
||||
|
||||
// https://github.com/material-components/material-components-android/blob/master/docs/components/Chip.md
|
||||
Context ctx = ApplicationEx.getThemedContext(context, dark ? R.style.ChipDark : R.style.ChipLight);
|
||||
ChipDrawable cd = ChipDrawable.createFromResource(ctx, R.xml.chip);
|
||||
cd.setChipIcon(avatar);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
|
||||
@@ -19,14 +19,12 @@ package eu.faircode.email;
|
||||
Copyright 2018-2024 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.text.Spanned;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -68,9 +66,6 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
private Handler handler = null;
|
||||
|
||||
private static PowerManager.WakeLock wl = null;
|
||||
private static int themeId = -1;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static Context themedContext = null;
|
||||
private static final List<SimpleTask> tasks = new ArrayList<>();
|
||||
|
||||
private static final ExecutorService serialExecutor =
|
||||
@@ -215,11 +210,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
int themeId = ((ActivityBase) context).getThemeId();
|
||||
if (themeId == 0)
|
||||
themeId = context.getApplicationInfo().theme;
|
||||
if (SimpleTask.themedContext == null || SimpleTask.themeId != themeId) {
|
||||
SimpleTask.themeId = themeId;
|
||||
SimpleTask.themedContext = new ContextThemeWrapper(context.getApplicationContext(), themeId);
|
||||
}
|
||||
tcontext = SimpleTask.themedContext;
|
||||
tcontext = ApplicationEx.getThemedContext(context, themeId);
|
||||
} else
|
||||
tcontext = context.getApplicationContext();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user