Run tasks in themed context

This commit is contained in:
M66B 2022-04-25 07:56:02 +02:00
parent 130fdfcbae
commit cc088cbc85
2 changed files with 11 additions and 6 deletions

View File

@ -335,16 +335,16 @@ public class FragmentDialogTheme extends FragmentDialogBase {
.create(); .create();
} }
static int getTheme(ActivityBase activity) { static int getTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String theme = prefs.getString("theme", "blue_orange_system"); String theme = prefs.getString("theme", "blue_orange_system");
boolean composer_light = prefs.getBoolean("composer_light", false); boolean composer_light = prefs.getBoolean("composer_light", false);
boolean night = Helper.isNight(activity); boolean night = Helper.isNight(context);
boolean light = (composer_light && activity instanceof ActivityCompose); boolean light = (composer_light && context instanceof ActivityCompose);
if (light) if (light)
night = false; night = false;
EntityLog.log(activity, "Activity theme=" + theme + EntityLog.log(context, "Activity theme=" + theme +
"light = " + light + " night=" + night); "light = " + light + " night=" + night);
switch (theme) { switch (theme) {

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.view.ContextThemeWrapper;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -154,6 +155,10 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
} }
}; };
Context themedContext = new ContextThemeWrapper(
context.getApplicationContext(),
FragmentDialogTheme.getTheme(context));
future = getExecutor(context).submit(new Runnable() { future = getExecutor(context).submit(new Runnable() {
private Object data; private Object data;
private long elapsed; private long elapsed;
@ -168,7 +173,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
if (log) if (log)
Log.i("Executing task=" + name); Log.i("Executing task=" + name);
long start = new Date().getTime(); long start = new Date().getTime();
data = onExecute(context.getApplicationContext(), args); data = onExecute(themedContext, args);
elapsed = new Date().getTime() - start; elapsed = new Date().getTime() - start;
if (log) if (log)
Log.i("Executed task=" + name + " elapsed=" + elapsed + " ms"); Log.i("Executed task=" + name + " elapsed=" + elapsed + " ms");