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

Commit 990a5b5a authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

feat(theming): Resolve change requests



* Only add the needed module rather than the entire lib
* Use ColorRole where possible in favor of querying the wanted color from the Scheme directly
* Use util for theming SwipeRefreshLayout

Signed-off-by: default avatarStefan Niedermann <info@niedermann.it>
parent dacbc79f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'

    // Nextcloud SSO
    implementation 'com.github.nextcloud:android-common:0.4.0'
    implementation 'com.github.nextcloud.android-common:ui:0.6.0'
    implementation 'com.github.nextcloud:Android-SingleSignOn:0.6.1'
    implementation 'com.github.stefan-niedermann:android-commons:0.2.9'
    implementation 'com.github.stefan-niedermann.nextcloud-commons:sso-glide:1.6.4'
+5 −2
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceViewHolder;

import com.nextcloud.android.common.ui.theme.utils.ColorRole;

public class BrandedPreferenceCategory extends PreferenceCategory {

    public BrandedPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -33,8 +35,9 @@ public class BrandedPreferenceCategory extends PreferenceCategory {
        final var view = holder.itemView.findViewById(android.R.id.title);
        @Nullable final var context = getContext();
        if (view instanceof TextView) {
            final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context);;
            ((TextView) view).setTextColor(util.notes.getOnPrimaryContainer(context));
            final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context);

            util.platform.colorTextView((TextView) view, ColorRole.ON_PRIMARY_CONTAINER);
        }
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.nextcloud.android.common.ui.theme.MaterialSchemes;
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;

import it.niedermann.android.util.ColorUtil;
@@ -35,13 +36,15 @@ import scheme.Scheme;
public class NotesViewThemeUtils extends ViewThemeUtilsBase {

    private static final String TAG = NotesViewThemeUtils.class.getSimpleName();
    private final MaterialSchemes schemes;

    public NotesViewThemeUtils(@NonNull MaterialSchemes schemes) {
        super(schemes);
        this.schemes = schemes;
    }

    /**
     * Use {@link ColorRole#ON_PRIMARY_CONTAINER}
     */
    @Deprecated(forRemoval = true)
    @ColorInt
    public int getOnPrimaryContainer(@NonNull Context context) {
        return withScheme(context, Scheme::getOnPrimaryContainer);
+3 −4
Original line number Diff line number Diff line
@@ -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.theme.utils.ColorRole;
import com.nextcloud.android.common.ui.util.PlatformThemeUtil;
import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
@@ -597,7 +598,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
    public void applyBrand(int color) {
        final var util = BrandingUtil.of(color, this);
        util.material.themeFAB(activityBinding.fabCreate);
        util.platform.colorCircularProgressBar(activityBinding.progressCircular);
        util.androidx.themeSwipeRefreshLayout(activityBinding.swiperefreshlayout);
        util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY);
        util.platform.colorNavigationView(binding.navigationView);
        util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent);

@@ -606,9 +608,6 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
        binding.appName.setTextColor(headerTextColor);
        DrawableCompat.setTint(binding.logo.getDrawable(), headerTextColor);

        // TODO We assume, that the background of the spinner is always white
        activityBinding.swiperefreshlayout.setColorSchemeColors(contrastRatioIsSufficient(Color.WHITE, color) ? color : Color.BLACK);

        adapter.applyBrand(color);
        adapterCategories.applyBrand(color);
        if (menuAdapter != null) {
+4 −2
Original line number Diff line number Diff line
@@ -53,10 +53,12 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
        itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view));
    }

    protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int mainColor) {
    protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int color) {
        noteStatus.setVisibility(DBStatus.VOID.equals(status) ? INVISIBLE : VISIBLE);

        final var context = noteStatus.getContext();
        DrawableCompat.setTint(noteStatus.getDrawable(), BrandingUtil.of(mainColor, context).notes.getOnPrimaryContainer(context));
        final var util = BrandingUtil.of(color, context);
        util.platform.tintDrawable(context, noteStatus.getDrawable(), ColorRole.ON_PRIMARY_CONTAINER);
    }

    protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int color) {