mirror of https://github.com/M66B/FairEmail.git
Optimize getting theme ID
This commit is contained in:
parent
5909df693c
commit
debf05db0f
|
@ -71,6 +71,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private int themeId;
|
||||
private Context originalContext;
|
||||
private boolean visible;
|
||||
private boolean contacts;
|
||||
|
@ -107,7 +108,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
||||
|
||||
if (!this.getClass().equals(ActivityMain.class)) {
|
||||
setTheme(FragmentDialogTheme.getTheme(this));
|
||||
themeId = FragmentDialogTheme.getTheme(this);
|
||||
setTheme(themeId);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
boolean dark = Helper.isDarkTheme(this);
|
||||
|
@ -379,6 +381,10 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
}
|
||||
}
|
||||
|
||||
public int getThemeId() {
|
||||
return this.themeId;
|
||||
}
|
||||
|
||||
public String getRequestKey() {
|
||||
return this.getClass().getName() + ":activity";
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ public class FragmentDialogTheme extends FragmentDialogBase {
|
|||
boolean light = (composer_light && context instanceof ActivityCompose);
|
||||
if (light)
|
||||
night = false;
|
||||
Log.i("Activity theme=" + theme + " light=" + light + " night=" + night);
|
||||
EntityLog.log(context, "Activity theme=" + theme + " light=" + light + " night=" + night);
|
||||
|
||||
switch (theme) {
|
||||
// Light
|
||||
|
|
|
@ -159,11 +159,18 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
}
|
||||
};
|
||||
|
||||
int themeId = FragmentDialogTheme.getTheme(context);
|
||||
if (themedContext == null || SimpleTask.themeId != themeId) {
|
||||
SimpleTask.themeId = themeId;
|
||||
themedContext = new ContextThemeWrapper(context.getApplicationContext(), themeId);
|
||||
}
|
||||
Context tcontext;
|
||||
if (context instanceof ActivityBase) {
|
||||
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;
|
||||
} else
|
||||
tcontext = context.getApplicationContext();
|
||||
|
||||
future = getExecutor(context).submit(new Runnable() {
|
||||
private Object data;
|
||||
|
@ -179,7 +186,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
|||
if (log)
|
||||
Log.i("Executing task=" + name);
|
||||
long start = new Date().getTime();
|
||||
data = onExecute(themedContext, args);
|
||||
data = onExecute(tcontext, args);
|
||||
elapsed = new Date().getTime() - start;
|
||||
if (log)
|
||||
Log.i("Executed task=" + name + " elapsed=" + elapsed + " ms");
|
||||
|
|
Loading…
Reference in New Issue