Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dacbc79f authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

feat(theming): Get rid of custom theme checking...



... and rely on PlatformThemeUtil.isDarkMode in stead.

Signed-off-by: default avatarStefan Niedermann <info@niedermann.it>
parent a40704a7
Loading
Loading
Loading
Loading
+2 −18
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes;

import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.util.Log;

import androidx.appcompat.app.AppCompatDelegate;
@@ -11,10 +11,6 @@ import androidx.preference.PreferenceManager;

import it.niedermann.owncloud.notes.preferences.DarkModeSetting;

import static androidx.preference.PreferenceManager.getDefaultSharedPreferences;

import com.nextcloud.android.common.ui.util.PlatformThemeUtil;

public class NotesApplication extends Application {
    private static final String TAG = NotesApplication.class.getSimpleName();

@@ -59,18 +55,6 @@ public class NotesApplication extends Application {
        return DarkModeSetting.valueOf(mode);
    }

    public static boolean isDarkThemeActive(Context context, DarkModeSetting setting) {
        if (setting == DarkModeSetting.SYSTEM_DEFAULT) {
            return isDarkThemeActive(context);
        } else {
            return setting == DarkModeSetting.DARK;
        }
    }

    public static boolean isDarkThemeActive(Context context) {
        return PlatformThemeUtil.isDarkMode(context);
    }

    public static void setLockedPreference(boolean lockedPreference) {
        Log.i(TAG, "New locked preference: " + lockedPreference);
        NotesApplication.lockedPreference = lockedPreference;
+2 −3
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.branding;

import static com.nextcloud.android.common.ui.util.ColorStateListUtilsKt.buildColorStateList;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode;

import android.content.Context;
import android.graphics.Color;
@@ -21,7 +21,6 @@ import androidx.core.graphics.drawable.DrawableCompat;

import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.navigation.NavigationView;
import com.nextcloud.android.common.ui.theme.MaterialSchemes;
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;
@@ -125,7 +124,7 @@ public class NotesViewThemeUtils extends ViewThemeUtilsBase {

    @ColorInt
    public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt int mainColor, @ColorInt int colorPrimary, @ColorInt int colorAccent) {
        if (isDarkThemeActive(context)) { // Dark background
        if (isDarkMode(context)) { // Dark background
            if (ColorUtil.INSTANCE.isColorDark(mainColor)) { // Dark brand color
                if (NotesColorUtil.contrastRatioIsSufficient(mainColor, colorPrimary)) { // But also dark text
                    return mainColor;
+3 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.O;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode;
import static it.niedermann.owncloud.notes.NotesApplication.isGridViewEnabled;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
@@ -49,6 +49,7 @@ import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.nextcloud.android.common.ui.util.PlatformThemeUtil;
import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
@@ -159,7 +160,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A

        gridView = isGridViewEnabled();

        if (!gridView || isDarkThemeActive(this)) {
        if (!gridView || isDarkMode(this)) {
            activityBinding.activityNotesListView.setBackgroundColor(ContextCompat.getColor(this, R.color.primary));
        }

+18 −40
Original line number Diff line number Diff line
@@ -2,11 +2,10 @@ package it.niedermann.owncloud.notes.main.items;

import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;

import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.BackgroundColorSpan;
@@ -26,12 +25,12 @@ import androidx.recyclerview.selection.ItemDetailsLookup;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.chip.Chip;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.android.common.ui.util.PlatformThemeUtil;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import it.niedermann.android.util.ColorUtil;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.persistence.entity.Note;
@@ -60,47 +59,26 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
        DrawableCompat.setTint(noteStatus.getDrawable(), BrandingUtil.of(mainColor, context).notes.getOnPrimaryContainer(context));
    }

    protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int mainColor) {
        final boolean isDarkThemeActive = NotesApplication.isDarkThemeActive(context);
        noteCategory.setVisibility(showCategory && !category.isEmpty() ? View.VISIBLE : View.GONE);
    protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int color) {
        if (!showCategory || category.isEmpty()) {
            noteCategory.setVisibility(View.GONE);
        } else {
            noteCategory.setText(category);

        @ColorInt final int categoryForeground;
        @ColorInt final int categoryBackground;
            final var util = BrandingUtil.of(color, context);

        if (isDarkThemeActive) {
            if (ColorUtil.INSTANCE.isColorDark(mainColor)) {
                if (contrastRatioIsSufficient(mainColor, Color.BLACK)) {
                    categoryBackground = mainColor;
                    categoryForeground = Color.WHITE;
                } else {
                    categoryBackground = Color.WHITE;
                    categoryForeground = mainColor;
                }
            } else {
                categoryBackground = mainColor;
                categoryForeground = Color.BLACK;
            }
            if (noteCategory instanceof Chip) {
                util.material.colorChipBackground((Chip) noteCategory);
            } else {
            categoryForeground = Color.BLACK;
            if (ColorUtil.INSTANCE.isColorDark(mainColor) || contrastRatioIsSufficient(mainColor, Color.WHITE)) {
                categoryBackground = mainColor;
                util.platform.tintDrawable(context, noteCategory.getBackground(), ColorRole.PRIMARY);
                if (isDarkMode(context)) {
                    util.platform.colorTextView(noteCategory, ColorRole.ON_PRIMARY);
                } else {
                categoryBackground = Color.BLACK;
                    util.platform.colorTextView(noteCategory, ColorRole.ON_SECONDARY_CONTAINER);
                }
            }

        noteCategory.setTextColor(categoryForeground);
        if (noteCategory instanceof Chip) {
            final Chip chip = (Chip) noteCategory;
            chip.setChipStrokeColor(ColorStateList.valueOf(categoryBackground));
            if(isDarkThemeActive) {
                chip.setChipBackgroundColor(ColorStateList.valueOf(categoryBackground));
            } else {
                chip.setChipBackgroundColorResource(R.color.grid_item_background_selector);
            }
        } else {
            DrawableCompat.setTint(noteCategory.getBackground(), categoryBackground);
            noteCategory.setVisibility(View.VISIBLE);
        }
    }