Skip to content

Commit 990a5b5

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: Stefan Niedermann <info@niedermann.it>
1 parent dacbc79 commit 990a5b5

5 files changed

Lines changed: 18 additions & 11 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dependencies {
7676
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
7777

7878
// Nextcloud SSO
79-
implementation 'com.github.nextcloud:android-common:0.4.0'
79+
implementation 'com.github.nextcloud.android-common:ui:0.6.0'
8080
implementation 'com.github.nextcloud:Android-SingleSignOn:0.6.1'
8181
implementation 'com.github.stefan-niedermann:android-commons:0.2.9'
8282
implementation 'com.github.stefan-niedermann.nextcloud-commons:sso-glide:1.6.4'

app/src/main/java/it/niedermann/owncloud/notes/branding/BrandedPreferenceCategory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import androidx.preference.PreferenceCategory;
99
import androidx.preference.PreferenceViewHolder;
1010

11+
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
12+
1113
public class BrandedPreferenceCategory extends PreferenceCategory {
1214

1315
public BrandedPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -33,8 +35,9 @@ public void onBindViewHolder(PreferenceViewHolder holder) {
3335
final var view = holder.itemView.findViewById(android.R.id.title);
3436
@Nullable final var context = getContext();
3537
if (view instanceof TextView) {
36-
final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context);;
37-
((TextView) view).setTextColor(util.notes.getOnPrimaryContainer(context));
38+
final var util = BrandingUtil.of(BrandingUtil.readBrandMainColor(context), context);
39+
40+
util.platform.colorTextView((TextView) view, ColorRole.ON_PRIMARY_CONTAINER);
3841
}
3942
}
4043
}

app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.android.material.appbar.MaterialToolbar;
2424
import com.nextcloud.android.common.ui.theme.MaterialSchemes;
2525
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
26+
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
2627
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;
2728

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

3738
private static final String TAG = NotesViewThemeUtils.class.getSimpleName();
38-
private final MaterialSchemes schemes;
3939

4040
public NotesViewThemeUtils(@NonNull MaterialSchemes schemes) {
4141
super(schemes);
42-
this.schemes = schemes;
4342
}
4443

44+
/**
45+
* Use {@link ColorRole#ON_PRIMARY_CONTAINER}
46+
*/
47+
@Deprecated(forRemoval = true)
4548
@ColorInt
4649
public int getOnPrimaryContainer(@NonNull Context context) {
4750
return withScheme(context, Scheme::getOnPrimaryContainer);

app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
5050
import com.google.android.material.floatingactionbutton.FloatingActionButton;
5151
import com.google.android.material.snackbar.Snackbar;
52+
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
5253
import com.nextcloud.android.common.ui.util.PlatformThemeUtil;
5354
import com.nextcloud.android.sso.AccountImporter;
5455
import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
@@ -597,7 +598,8 @@ public void onIconClick(NavigationItem item) {
597598
public void applyBrand(int color) {
598599
final var util = BrandingUtil.of(color, this);
599600
util.material.themeFAB(activityBinding.fabCreate);
600-
util.platform.colorCircularProgressBar(activityBinding.progressCircular);
601+
util.androidx.themeSwipeRefreshLayout(activityBinding.swiperefreshlayout);
602+
util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY);
601603
util.platform.colorNavigationView(binding.navigationView);
602604
util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent);
603605

@@ -606,9 +608,6 @@ public void applyBrand(int color) {
606608
binding.appName.setTextColor(headerTextColor);
607609
DrawableCompat.setTint(binding.logo.getDrawable(), headerTextColor);
608610

609-
// TODO We assume, that the background of the spinner is always white
610-
activityBinding.swiperefreshlayout.setColorSchemeColors(contrastRatioIsSufficient(Color.WHITE, color) ? color : Color.BLACK);
611-
612611
adapter.applyBrand(color);
613612
adapterCategories.applyBrand(color);
614613
if (menuAdapter != null) {

app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @
5353
itemView.setOnClickListener((view) -> noteClickListener.onNoteClick(getLayoutPosition(), view));
5454
}
5555

56-
protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int mainColor) {
56+
protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int color) {
5757
noteStatus.setVisibility(DBStatus.VOID.equals(status) ? INVISIBLE : VISIBLE);
58+
5859
final var context = noteStatus.getContext();
59-
DrawableCompat.setTint(noteStatus.getDrawable(), BrandingUtil.of(mainColor, context).notes.getOnPrimaryContainer(context));
60+
final var util = BrandingUtil.of(color, context);
61+
util.platform.tintDrawable(context, noteStatus.getDrawable(), ColorRole.ON_PRIMARY_CONTAINER);
6062
}
6163

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

0 commit comments

Comments
 (0)