Add static BrandingUtil instance

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-07-22 14:47:02 +02:00 committed by Alper Öztürk
parent e76eb7212b
commit b8a34d7fcd
2 changed files with 15 additions and 0 deletions

View file

@ -20,6 +20,7 @@ import android.webkit.WebView;
import androidx.appcompat.app.AppCompatDelegate;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.preferences.DarkModeSetting;
public class NotesApplication extends Application {
@ -31,6 +32,7 @@ public class NotesApplication extends Application {
private static long lastInteraction = 0;
private static String PREF_KEY_THEME;
private static boolean isGridViewEnabled = false;
private static BrandingUtil brandingUtil;
@Override
public void onCreate() {
@ -40,11 +42,16 @@ public class NotesApplication extends Application {
lockedPreference = prefs.getBoolean(getString(R.string.pref_key_lock), false);
isGridViewEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_gridview), false);
super.onCreate();
brandingUtil = BrandingUtil.getInstance(this);
if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
}
}
public static BrandingUtil brandingUtil() {
return brandingUtil;
}
public static void setAppTheme(DarkModeSetting setting) {
AppCompatDelegate.setDefaultNightMode(setting.getModeId());
}

View file

@ -54,6 +54,14 @@ public class BrandingUtil extends ViewThemeUtilsBase {
this.notes = new NotesViewThemeUtils(schemes);
}
public static BrandingUtil getInstance(@NonNull Context context) {
int color = BrandingUtil.readBrandMainColor(context);
return new BrandingUtil(
MaterialSchemes.Companion.fromColor(color),
new com.nextcloud.android.common.ui.color.ColorUtil(context)
);
}
public static BrandingUtil of(@ColorInt int color, @NonNull Context context) {
return CACHE.computeIfAbsent(color, c -> new BrandingUtil(
MaterialSchemes.Companion.fromColor(c),