Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: Provides toolbar for native markdown editor #2209

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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));
}

Expand Down
141 changes: 83 additions & 58 deletions app/src/main/res/layout/fragment_note_edit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Notes - Android Client
~
~ SPDX-FileCopyrightText: 2015-2024 Nextcloud GmbH and Nextcloud contributors
Expand All @@ -20,68 +19,94 @@
android:focusableInTouchMode="true"
android:orientation="horizontal" />

<ScrollView
android:id="@+id/scrollView"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
tools:context="it.niedermann.owncloud.notes.edit.EditNoteActivity">
android:orientation="vertical">

<it.niedermann.android.markdown.MarkdownEditorImpl
android:id="@+id/editContent"
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/controller"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="it.niedermann.owncloud.notes.edit.EditNoteActivity">

<it.niedermann.android.markdown.MarkdownEditorImpl
android:id="@+id/editContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
android:background="@android:color/transparent"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences"
android:lineSpacingMultiplier="@dimen/note_line_spacing"
android:padding="@dimen/spacer_2x"
android:textColor="@color/fg_default"
tools:text="@tools:sample/lorem/random" />
</ScrollView>

<it.niedermann.android.markdown.controller.MarkdownToolbarController
android:id="@+id/controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacer_activity_sides"
android:background="@android:color/transparent"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences"
android:lineSpacingMultiplier="@dimen/note_line_spacing"
android:padding="@dimen/spacer_2x"
android:textColor="@color/fg_default"
tools:text="@tools:sample/lorem/random" />
</ScrollView>
android:gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/toolbar" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/searchPrev"
style="?attr/floatingActionButtonSmallSecondaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/simple_prev"
android:translationY="-56dp"
android:visibility="gone"
app:backgroundTint="@color/defaultBrand"
app:srcCompat="@drawable/ic_keyboard_arrow_up_white_24dp"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/searchPrev"
style="?attr/floatingActionButtonSmallSecondaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/simple_prev"
android:translationY="-56dp"
android:visibility="gone"
app:backgroundTint="@color/defaultBrand"
app:layout_constraintBottom_toTopOf="@id/controller"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_up_white_24dp"
tools:visibility="visible" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/searchNext"
style="?attr/floatingActionButtonSmallSecondaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/simple_next"
android:visibility="gone"
app:backgroundTint="@color/defaultBrand"
app:srcCompat="@drawable/ic_keyboard_arrow_down_white_24dp"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/searchNext"
style="?attr/floatingActionButtonSmallSecondaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/simple_next"
android:visibility="gone"
app:backgroundTint="@color/defaultBrand"
app:layout_constraintBottom_toTopOf="@id/controller"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_down_white_24dp"
tools:visibility="visible" />

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/direct_editing"
style="?attr/floatingActionButtonPrimaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/noteMode_rich_edit"
android:text="@string/noteMode_rich_edit"
android:visibility="visible"
app:backgroundTint="@color/defaultBrand"
app:layout_anchor="@id/scrollView"
app:layout_anchorGravity="bottom|end"
app:icon="@drawable/ic_rich_editing" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/direct_editing"
style="?attr/floatingActionButtonPrimaryStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/spacer_2x"
android:contentDescription="@string/noteMode_rich_edit"
android:text="@string/noteMode_rich_edit"
android:visibility="visible"
app:backgroundTint="@color/defaultBrand"
app:icon="@drawable/ic_rich_editing"
app:layout_anchor="@id/scrollView"
app:layout_anchorGravity="bottom|end"
app:layout_constraintBottom_toTopOf="@id/controller"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading