From 45528cfeb51415c08a0821540281d586f685bfeb Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 23 May 2024 11:36:12 +0200 Subject: [PATCH] feat(toolbar): Provides toolbar for native markdown editor Signed-off-by: Stefan Niedermann --- .../notes/branding/NotesViewThemeUtils.java | 29 +++- .../owncloud/notes/edit/NoteEditFragment.java | 3 + .../main/res/layout/fragment_note_edit.xml | 141 +++++++++++------- 3 files changed, 114 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java index a28e68126..6487fad86 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java @@ -13,6 +13,7 @@ import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.util.Log; import android.view.View; @@ -26,6 +27,8 @@ import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; +import androidx.core.graphics.BlendModeColorFilterCompat; +import androidx.core.graphics.BlendModeCompat; import androidx.core.graphics.drawable.DrawableCompat; import com.google.android.material.appbar.AppBarLayout; @@ -35,7 +38,11 @@ import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase; import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils; +import java.util.Optional; + +import dynamiccolor.DynamicScheme; import dynamiccolor.MaterialDynamicColors; +import it.niedermann.android.markdown.controller.MarkdownToolbarController; import it.niedermann.android.util.ColorUtil; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.main.navigation.NavigationItem; @@ -190,8 +197,8 @@ public void themeSearchToolbar(@NonNull MaterialToolbar 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 Should be replaced with {@link com.google.android.material.search.SearchView} */ @Deprecated public void themeToolbarSearchView(@NonNull SearchView searchView) { @@ -209,4 +216,24 @@ public void themeToolbarSearchView(@NonNull SearchView searchView) { return searchView; }); } + + public void themeToolbar(@NonNull Toolbar toolbar) { + withScheme(toolbar, scheme -> { + toolbar.setBackgroundColor(dynamicColor.surface().getArgb(scheme)); +// toolbar.setNavigationIconTint(dynamicColor.onSurface().getArgb(scheme)); + toolbar.setTitleTextColor(dynamicColor.onSurface().getArgb(scheme)); + final var overflowIcon = Optional.ofNullable(toolbar.getOverflowIcon()); + overflowIcon.ifPresent(drawable -> colorTrailingIcon(scheme, drawable)); + return toolbar; + }); + } + + private void colorTrailingIcon(@NonNull DynamicScheme scheme, + @NonNull Drawable icon) { + icon.setColorFilter( + BlendModeColorFilterCompat.createBlendModeColorFilterCompat( + dynamicColor.surfaceVariant().getArgb(scheme), + BlendModeCompat.SRC_ATOP + )); + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java index c4adc066c..04195ee69 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java @@ -34,6 +34,7 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import it.niedermann.android.markdown.controller.ControllerConnector; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.databinding.FragmentNoteEditBinding; @@ -124,6 +125,7 @@ protected ExtendedFloatingActionButton getNormalEditButton() { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { binding = FragmentNoteEditBinding.inflate(inflater, container, false); + ControllerConnector.connect(getViewLifecycleOwner(), binding.editContent, binding.controller); return binding.getRoot(); } @@ -272,6 +274,7 @@ public void applyBrand(int color) { final var util = BrandingUtil.of(color, requireContext()); binding.editContent.setSearchColor(color); + util.notes.themeToolbar(binding.controller); binding.editContent.setHighlightColor(util.notes.getTextHighlightBackgroundColor(requireContext(), color, colorPrimary, colorAccent)); } diff --git a/app/src/main/res/layout/fragment_note_edit.xml b/app/src/main/res/layout/fragment_note_edit.xml index 4de3e67b8..9bf7ee657 100644 --- a/app/src/main/res/layout/fragment_note_edit.xml +++ b/app/src/main/res/layout/fragment_note_edit.xml @@ -1,5 +1,4 @@ - -