From 36fde04ddf75a2b84463ae27cd2fdfba6d698da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Fri, 24 Feb 2023 16:30:35 +0100 Subject: [PATCH] feat: add fab while direct editing to switch to normal editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- .../notes/edit/NoteDirectEditFragment.kt | 24 ++++++++++++++-- .../edit/SearchableBaseNoteFragment.java | 15 ++-------- .../notes/shared/util/ExtendedFabUtil.kt | 28 ++++++++++++++++++- app/src/main/res/drawable/ic_notes.xml | 11 ++++++++ .../res/layout/fragment_note_direct_edit.xml | 22 +++++++++++++-- 5 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/drawable/ic_notes.xml diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt index 181d83950..8b2b08766 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt @@ -19,12 +19,16 @@ import androidx.core.view.isVisible import com.nextcloud.android.sso.helper.SingleAccountHelper import io.reactivex.android.schedulers.AndroidSchedulers import it.niedermann.owncloud.notes.BuildConfig +import it.niedermann.owncloud.notes.branding.Branded +import it.niedermann.owncloud.notes.branding.BrandingUtil import it.niedermann.owncloud.notes.databinding.FragmentNoteDirectEditBinding import it.niedermann.owncloud.notes.persistence.DirectEditingRepository import it.niedermann.owncloud.notes.persistence.entity.Note import it.niedermann.owncloud.notes.shared.model.ISyncCallback +import it.niedermann.owncloud.notes.shared.util.ExtendedFabUtil +import it.niedermann.owncloud.notes.shared.util.ExtendedFabUtil.toggleVisibilityOnScroll -class NoteDirectEditFragment : BaseNoteFragment() { +class NoteDirectEditFragment : BaseNoteFragment(), Branded { private var _binding: FragmentNoteDirectEditBinding? = null private val binding: FragmentNoteDirectEditBinding get() = _binding!! @@ -44,6 +48,7 @@ class NoteDirectEditFragment : BaseNoteFragment() { ): View { Log.d(TAG, "onCreateView() called") _binding = FragmentNoteDirectEditBinding.inflate(inflater, container, false) + setupFab() // TODO prepare webview setupWebSettings(binding.noteWebview.settings) // TODO remove this @@ -63,6 +68,18 @@ class NoteDirectEditFragment : BaseNoteFragment() { return binding.root } + private fun setupFab() { + binding.plainEditingFab.isExtended = false + ExtendedFabUtil.toggleExtendedOnLongClick(binding.plainEditingFab) + binding.noteWebview.setOnScrollChangeListener { _, _, scrollY, _, oldScrollY -> + toggleVisibilityOnScroll(binding.plainEditingFab, scrollY, oldScrollY) + } + binding.plainEditingFab.setOnClickListener { + // TODO save note? + listener.changeMode(NoteFragmentListener.Mode.EDIT) + } + } + override fun onDestroyView() { super.onDestroyView() binding.noteWebview.destroy() @@ -147,8 +164,8 @@ class NoteDirectEditFragment : BaseNoteFragment() { } override fun applyBrand(color: Int) { - // TODO check if any branding needed - // nothing for now + val util = BrandingUtil.of(color, requireContext()) + util.material.themeExtendedFAB(binding.plainEditingFab) } companion object { @@ -194,6 +211,7 @@ class NoteDirectEditFragment : BaseNoteFragment() { activity?.runOnUiThread { binding.progress.isVisible = false binding.noteWebview.isVisible = true + binding.plainEditingFab.isVisible = true } } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java index 4ee154c33..a2271fb5a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java @@ -60,11 +60,7 @@ protected void onScroll(int scrollY, int oldScrollY) { super.onScroll(scrollY, oldScrollY); if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) { final ExtendedFloatingActionButton directFab = getDirectEditingButton(); - if (oldScrollY > 0 && scrollY > oldScrollY && directFab.isShown()) { - ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false); - } else if (scrollY < oldScrollY && !directFab.isShown()) { - ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), true); - } + ExtendedFabUtil.toggleVisibilityOnScroll(directFab, scrollY, oldScrollY); } } @@ -74,14 +70,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat // TODO don't show fab if direct editing not available final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton(); directEditingButton.setExtended(false); - directEditingButton.setOnLongClickListener(v -> { - if (directEditingButton.isExtended()) { - directEditingButton.shrink(); - } else { - directEditingButton.extend(); - } - return true; - }); + ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton); directEditingButton.setOnClickListener(v -> { listener.changeMode(NoteFragmentListener.Mode.DIRECT_EDIT); }); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ExtendedFabUtil.kt b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ExtendedFabUtil.kt index f860cae61..a27714fbe 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ExtendedFabUtil.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/ExtendedFabUtil.kt @@ -8,7 +8,7 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu object ExtendedFabUtil { @JvmStatic - public fun setExtendedFabVisibility( + fun setExtendedFabVisibility( extendedFab: ExtendedFloatingActionButton, visibility: Boolean, ) { @@ -36,4 +36,30 @@ object ExtendedFabUtil { } } } + + @JvmStatic + fun toggleExtendedOnLongClick(extendedFab: ExtendedFloatingActionButton) { + extendedFab.setOnLongClickListener { v: View? -> + if (extendedFab.isExtended) { + extendedFab.shrink() + } else { + extendedFab.extend() + } + true + } + } + + @JvmStatic + fun toggleVisibilityOnScroll( + extendedFab: ExtendedFloatingActionButton, + scrollY: Int, + oldScrollY: Int, + ) { + @Suppress("ConvertTwoComparisonsToRangeCheck") + if (oldScrollY > 0 && scrollY > oldScrollY && extendedFab.isShown) { + setExtendedFabVisibility(extendedFab, false) + } else if (scrollY < oldScrollY && !extendedFab.isShown) { + setExtendedFabVisibility(extendedFab, true) + } + } } diff --git a/app/src/main/res/drawable/ic_notes.xml b/app/src/main/res/drawable/ic_notes.xml new file mode 100644 index 000000000..7ef43fc14 --- /dev/null +++ b/app/src/main/res/drawable/ic_notes.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/layout/fragment_note_direct_edit.xml b/app/src/main/res/layout/fragment_note_direct_edit.xml index ee7297851..cecad852a 100644 --- a/app/src/main/res/layout/fragment_note_direct_edit.xml +++ b/app/src/main/res/layout/fragment_note_direct_edit.xml @@ -1,6 +1,7 @@ @@ -8,7 +9,8 @@ android:visibility="gone" android:id="@+id/note_webview" android:layout_width="match_parent" - android:layout_height="match_parent" /> + android:layout_height="match_parent" + tools:visibility="visible" /> - + +