Skip to content

Commit

Permalink
Merge pull request #1752 from nextcloud/align-theming-to-files-app
Browse files Browse the repository at this point in the history
feat(theming): Align theming closer to files app
  • Loading branch information
AndyScherzinger authored Apr 11, 2023
2 parents 6b336e4 + 5cab30b commit 01fc67a
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 112 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'

// Nextcloud SSO
implementation 'com.github.nextcloud.android-common:ui:0.7.0'
implementation 'com.github.nextcloud.android-common:ui:0.8.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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.niedermann.owncloud.notes;

import android.content.SharedPreferences;
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences;

import android.graphics.Typeface;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
Expand All @@ -10,13 +11,10 @@
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding;

import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences;

public class FormattingHelpActivity extends BrandedActivity {

private ActivityFormattingHelpBinding binding;
Expand Down Expand Up @@ -225,6 +223,7 @@ private String buildFormattingHelp() {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.material.themeTabLayout(binding.tabs);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
util.material.themeTabLayoutOnSurface(binding.tabs);
}

private static class TabsStateAdapter extends FragmentStateAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
Expand All @@ -15,23 +16,23 @@
import androidx.annotation.ColorInt;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
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.card.MaterialCardView;
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;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.shared.util.NotesColorUtil;
import kotlin.Pair;
import scheme.Scheme;

public class NotesViewThemeUtils extends ViewThemeUtilsBase {

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

Expand Down Expand Up @@ -117,7 +120,10 @@ public void colorLayerDrawable(@NonNull LayerDrawable check, @IdRes int areaToCo
}

@ColorInt
public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt int mainColor, @ColorInt int colorPrimary, @ColorInt int colorAccent) {
public int getTextHighlightBackgroundColor(@NonNull Context context,
@ColorInt int mainColor,
@ColorInt int colorPrimary,
@ColorInt int colorAccent) {
if (isDarkMode(context)) { // Dark background
if (ColorUtil.INSTANCE.isColorDark(mainColor)) { // Dark brand color
if (NotesColorUtil.contrastRatioIsSufficient(mainColor, colorPrimary)) { // But also dark text
Expand Down Expand Up @@ -148,4 +154,49 @@ public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt i
}
}
}

/**
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} component.
*/
@Deprecated
public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) {
withScheme(searchBarWrapper, scheme -> {
searchBarWrapper.setBackgroundTintList(ColorStateList.valueOf(scheme.getSurface()));
return searchBarWrapper;
});
}

/**
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} or
* {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)}
*/
@Deprecated
public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) {
withScheme(toolbar, scheme -> {
toolbar.setNavigationIconTint(scheme.getOnSurface());
toolbar.setTitleTextColor(scheme.getOnSurface());
return toolbar;
});
}

/**
* @deprecated Should be replaced with {@link com.google.android.material.search.SearchView}
* @see com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils#themeToolbarSearchView(SearchView)
*/
@Deprecated
public void themeToolbarSearchView(@NonNull SearchView searchView) {
withScheme(searchView, scheme -> {
// hacky as no default way is provided
final var editText = (SearchView.SearchAutoComplete) searchView
.findViewById(androidx.appcompat.R.id.search_src_text);
final var closeButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
final var searchButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_button);
editText.setHintTextColor(scheme.getOnSurfaceVariant());
editText.setHighlightColor(scheme.getInverseOnSurface());
editText.setTextColor(scheme.getOnSurface());
closeButton.setColorFilter(scheme.getOnSurface());
searchButton.setColorFilter(scheme.getOnSurface());
return searchView;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public void onAccountPicked(@NonNull Account account) {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,13 @@ public void onIconClick(NavigationItem item) {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.material.themeFAB(activityBinding.fabCreate);
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);
util.material.themeFAB(activityBinding.fabCreate);
util.notes.themeSearchCardView(binding.activityNotesListView.searchBarWrapper);
util.notes.themeSearchToolbar(binding.activityNotesListView.searchToolbar);
util.notes.themeToolbarSearchView(binding.activityNotesListView.searchView);

binding.headerView.setBackgroundColor(color);
@ColorInt final int headerTextColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void onFailure(@NonNull Call<NotesSettings> call, @NonNull Throwable t) {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void applyBrand(int color) {
final var util = BrandingUtil.of(color, this);
util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent);
util.platform.themeStatusBar(this);
util.material.themeToolbar(binding.toolbar);
}
}
10 changes: 2 additions & 8 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,31 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:orientation="vertical">

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

<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"
tools:title="@string/simple_about" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabMode="fixed" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:paddingHorizontal="@dimen/spacer_1x" />

</LinearLayout>
22 changes: 6 additions & 16 deletions app/src/main/res/layout/activity_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,16 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:titleMarginStart="0dp"
tools:title="Edit Sample note" />
</com.google.android.material.appbar.AppBarLayout>
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
tools:title="Edit Sample note" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary" />
android:layout_height="match_parent" />

</LinearLayout>
8 changes: 2 additions & 6 deletions app/src/main/res/layout/activity_exception.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
android:layout_height="wrap_content"
app:elevation="4dp"
app:titleMarginStart="0dp"
tools:title="@string/simple_exception" />

<TextView
Expand Down
20 changes: 5 additions & 15 deletions app/src/main/res/layout/activity_formatting_help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary"
android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/action_formatting_help"
app:titleMarginStart="0dp" />
</com.google.android.material.appbar.AppBarLayout>
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/action_formatting_help" />

<ScrollView
android:id="@+id/scrollView"
Expand Down
20 changes: 5 additions & 15 deletions app/src/main/res/layout/activity_manage_accounts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/manage_accounts"
app:titleMarginStart="0dp" />
</com.google.android.material.appbar.AppBarLayout>
android:layout_height="wrap_content"
app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp"
app:title="@string/manage_accounts" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/accounts"
Expand Down
Loading

0 comments on commit 01fc67a

Please sign in to comment.