Skip to content

Commit 01fc67a

Browse files
Merge pull request #1752 from nextcloud/align-theming-to-files-app
feat(theming): Align theming closer to files app
2 parents 6b336e4 + 5cab30b commit 01fc67a

20 files changed

+120
-112
lines changed

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.3'
7777

7878
// Nextcloud SSO
79-
implementation 'com.github.nextcloud.android-common:ui:0.7.0'
79+
implementation 'com.github.nextcloud.android-common:ui:0.8.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/FormattingHelpActivity.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.niedermann.owncloud.notes;
22

3-
import android.content.SharedPreferences;
3+
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences;
4+
45
import android.graphics.Typeface;
56
import android.os.Bundle;
67
import android.text.method.LinkMovementMethod;
@@ -10,13 +11,10 @@
1011
import androidx.annotation.Nullable;
1112
import androidx.preference.PreferenceManager;
1213

13-
import it.niedermann.owncloud.notes.R;
1414
import it.niedermann.owncloud.notes.branding.BrandedActivity;
1515
import it.niedermann.owncloud.notes.branding.BrandingUtil;
1616
import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding;
1717

18-
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences;
19-
2018
public class FormattingHelpActivity extends BrandedActivity {
2119

2220
private ActivityFormattingHelpBinding binding;
@@ -225,6 +223,7 @@ private String buildFormattingHelp() {
225223
@Override
226224
public void applyBrand(int color) {
227225
final var util = BrandingUtil.of(color, this);
228-
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
226+
util.platform.themeStatusBar(this);
227+
util.material.themeToolbar(binding.toolbar);
229228
}
230229
}

app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ protected void onCreate(Bundle savedInstanceState) {
5252
@Override
5353
public void applyBrand(int color) {
5454
final var util = BrandingUtil.of(color, this);
55-
util.material.themeTabLayout(binding.tabs);
56-
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
55+
util.platform.themeStatusBar(this);
56+
util.material.themeToolbar(binding.toolbar);
57+
util.material.themeTabLayoutOnSurface(binding.tabs);
5758
}
5859

5960
private static class TabsStateAdapter extends FragmentStateAdapter {

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

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode;
55

66
import android.content.Context;
7+
import android.content.res.ColorStateList;
78
import android.graphics.Color;
89
import android.graphics.PorterDuff;
910
import android.graphics.drawable.LayerDrawable;
@@ -15,23 +16,23 @@
1516
import androidx.annotation.ColorInt;
1617
import androidx.annotation.IdRes;
1718
import androidx.annotation.NonNull;
19+
import androidx.appcompat.widget.SearchView;
1820
import androidx.appcompat.widget.Toolbar;
1921
import androidx.core.content.ContextCompat;
2022
import androidx.core.graphics.drawable.DrawableCompat;
2123

2224
import com.google.android.material.appbar.AppBarLayout;
2325
import com.google.android.material.appbar.MaterialToolbar;
26+
import com.google.android.material.card.MaterialCardView;
2427
import com.nextcloud.android.common.ui.theme.MaterialSchemes;
2528
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase;
26-
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
2729
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils;
2830

2931
import it.niedermann.android.util.ColorUtil;
3032
import it.niedermann.owncloud.notes.R;
3133
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
3234
import it.niedermann.owncloud.notes.shared.util.NotesColorUtil;
3335
import kotlin.Pair;
34-
import scheme.Scheme;
3536

3637
public class NotesViewThemeUtils extends ViewThemeUtilsBase {
3738

@@ -87,7 +88,9 @@ public void colorNavigationViewItemText(@NonNull TextView view) {
8788
* @deprecated should be replaced by {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)}.
8889
*/
8990
@Deprecated(forRemoval = true)
90-
public void applyBrandToPrimaryToolbar(@NonNull AppBarLayout appBarLayout, @NonNull Toolbar toolbar, @ColorInt int color) {
91+
public void applyBrandToPrimaryToolbar(@NonNull AppBarLayout appBarLayout,
92+
@NonNull Toolbar toolbar,
93+
@ColorInt int color) {
9194
// FIXME Workaround for https://github.com/nextcloud/notes-android/issues/889
9295
appBarLayout.setBackgroundColor(ContextCompat.getColor(appBarLayout.getContext(), R.color.primary));
9396

@@ -117,7 +120,10 @@ public void colorLayerDrawable(@NonNull LayerDrawable check, @IdRes int areaToCo
117120
}
118121

119122
@ColorInt
120-
public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt int mainColor, @ColorInt int colorPrimary, @ColorInt int colorAccent) {
123+
public int getTextHighlightBackgroundColor(@NonNull Context context,
124+
@ColorInt int mainColor,
125+
@ColorInt int colorPrimary,
126+
@ColorInt int colorAccent) {
121127
if (isDarkMode(context)) { // Dark background
122128
if (ColorUtil.INSTANCE.isColorDark(mainColor)) { // Dark brand color
123129
if (NotesColorUtil.contrastRatioIsSufficient(mainColor, colorPrimary)) { // But also dark text
@@ -148,4 +154,49 @@ public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt i
148154
}
149155
}
150156
}
157+
158+
/**
159+
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} component.
160+
*/
161+
@Deprecated
162+
public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) {
163+
withScheme(searchBarWrapper, scheme -> {
164+
searchBarWrapper.setBackgroundTintList(ColorStateList.valueOf(scheme.getSurface()));
165+
return searchBarWrapper;
166+
});
167+
}
168+
169+
/**
170+
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} or
171+
* {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)}
172+
*/
173+
@Deprecated
174+
public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) {
175+
withScheme(toolbar, scheme -> {
176+
toolbar.setNavigationIconTint(scheme.getOnSurface());
177+
toolbar.setTitleTextColor(scheme.getOnSurface());
178+
return toolbar;
179+
});
180+
}
181+
182+
/**
183+
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchView}
184+
* @see com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils#themeToolbarSearchView(SearchView)
185+
*/
186+
@Deprecated
187+
public void themeToolbarSearchView(@NonNull SearchView searchView) {
188+
withScheme(searchView, scheme -> {
189+
// hacky as no default way is provided
190+
final var editText = (SearchView.SearchAutoComplete) searchView
191+
.findViewById(androidx.appcompat.R.id.search_src_text);
192+
final var closeButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
193+
final var searchButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_button);
194+
editText.setHintTextColor(scheme.getOnSurfaceVariant());
195+
editText.setHighlightColor(scheme.getInverseOnSurface());
196+
editText.setTextColor(scheme.getOnSurface());
197+
closeButton.setColorFilter(scheme.getOnSurface());
198+
searchButton.setColorFilter(scheme.getOnSurface());
199+
return searchView;
200+
});
201+
}
151202
}

app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ public void onAccountPicked(@NonNull Account account) {
420420
@Override
421421
public void applyBrand(int color) {
422422
final var util = BrandingUtil.of(color, this);
423-
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
423+
util.platform.themeStatusBar(this);
424+
util.material.themeToolbar(binding.toolbar);
424425
}
425426
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,13 @@ public void onIconClick(NavigationItem item) {
594594
@Override
595595
public void applyBrand(int color) {
596596
final var util = BrandingUtil.of(color, this);
597-
util.material.themeFAB(activityBinding.fabCreate);
598597
util.androidx.themeSwipeRefreshLayout(activityBinding.swiperefreshlayout);
599598
util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY);
600599
util.platform.colorNavigationView(binding.navigationView);
601-
util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent);
600+
util.material.themeFAB(activityBinding.fabCreate);
601+
util.notes.themeSearchCardView(binding.activityNotesListView.searchBarWrapper);
602+
util.notes.themeSearchToolbar(binding.activityNotesListView.searchToolbar);
603+
util.notes.themeToolbarSearchView(binding.activityNotesListView.searchView);
602604

603605
binding.headerView.setBackgroundColor(color);
604606
@ColorInt final int headerTextColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(color);

app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public void onFailure(@NonNull Call<NotesSettings> call, @NonNull Throwable t) {
210210
@Override
211211
public void applyBrand(int color) {
212212
final var util = BrandingUtil.of(color, this);
213-
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
213+
util.platform.themeStatusBar(this);
214+
util.material.themeToolbar(binding.toolbar);
214215
}
215216
}

app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3434
@Override
3535
public void applyBrand(int color) {
3636
final var util = BrandingUtil.of(color, this);
37-
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
37+
util.platform.themeStatusBar(this);
38+
util.material.themeToolbar(binding.toolbar);
3839
}
3940
}

app/src/main/res/layout/activity_about.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,31 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:background="?attr/colorPrimary"
87
android:orientation="vertical">
98

109
<com.google.android.material.appbar.AppBarLayout
1110
android:id="@+id/appBar"
1211
android:layout_width="match_parent"
1312
android:layout_height="wrap_content">
1413

15-
<androidx.appcompat.widget.Toolbar
14+
<com.google.android.material.appbar.MaterialToolbar
1615
android:id="@+id/toolbar"
1716
android:layout_width="match_parent"
18-
android:layout_height="?attr/actionBarSize"
19-
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
20-
app:contentInsetStartWithNavigation="0dp"
17+
android:layout_height="wrap_content"
2118
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
22-
app:titleMarginStart="0dp"
2319
tools:title="@string/simple_about" />
2420

2521
<com.google.android.material.tabs.TabLayout
2622
android:id="@+id/tabs"
2723
android:layout_width="match_parent"
2824
android:layout_height="wrap_content"
29-
android:background="?attr/colorPrimary"
3025
app:tabMode="fixed" />
3126
</com.google.android.material.appbar.AppBarLayout>
3227

3328
<androidx.viewpager2.widget.ViewPager2
3429
android:id="@+id/pager"
3530
android:layout_width="match_parent"
3631
android:layout_height="wrap_content"
37-
android:background="?attr/colorPrimary"
3832
android:paddingHorizontal="@dimen/spacer_1x" />
3933

4034
</LinearLayout>

app/src/main/res/layout/activity_edit.xml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,16 @@
66
android:layout_height="match_parent"
77
android:orientation="vertical">
88

9-
<com.google.android.material.appbar.AppBarLayout
10-
android:id="@+id/appBar"
9+
<com.google.android.material.appbar.MaterialToolbar
10+
android:id="@+id/toolbar"
1111
android:layout_width="match_parent"
12-
android:layout_height="wrap_content">
13-
14-
<androidx.appcompat.widget.Toolbar
15-
android:id="@+id/toolbar"
16-
android:layout_width="match_parent"
17-
android:layout_height="?attr/actionBarSize"
18-
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
19-
app:contentInsetStartWithNavigation="0dp"
20-
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
21-
app:titleMarginStart="0dp"
22-
tools:title="Edit Sample note" />
23-
</com.google.android.material.appbar.AppBarLayout>
12+
android:layout_height="wrap_content"
13+
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
14+
tools:title="Edit Sample note" />
2415

2516
<androidx.fragment.app.FragmentContainerView
2617
android:id="@+id/fragment_container_view"
2718
android:layout_width="match_parent"
28-
android:layout_height="match_parent"
29-
android:background="?attr/colorPrimary" />
19+
android:layout_height="match_parent" />
3020

3121
</LinearLayout>

0 commit comments

Comments
 (0)