Allow an edit fab to replace the rich text fab

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
This commit is contained in:
Felix Nüsse 2023-09-24 23:35:49 +02:00 committed by Andy Scherzinger
parent b20ed02f17
commit 3c359f8eb5
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
4 changed files with 52 additions and 1 deletions

View file

@ -115,6 +115,11 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
return binding.directEditing;
}
protected ExtendedFloatingActionButton getNormalEditButton() {
// the edit fragment does not have a button
return null;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

View file

@ -58,6 +58,10 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_edit).setVisible(true);
if(getNormalEditButton().getVisibility() == View.VISIBLE) {
menu.findItem(R.id.menu_edit).setVisible(false);
}
menu.findItem(R.id.menu_preview).setVisible(false);
}
@ -92,6 +96,11 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
return binding.directEditing;
}
@Override
protected ExtendedFloatingActionButton getNormalEditButton() {
return binding.edit;
}
@Override
protected Layout getLayout() {
binding.singleNoteContent.onPreDraw();

View file

@ -85,7 +85,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
checkDirectEditingAvailable();
if (directEditAvailable) {
if (directEditAvailable && isDirectEditEnabled()) {
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
directEditingButton.setExtended(false);
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
@ -96,6 +96,15 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
});
} else {
getDirectEditingButton().setVisibility(View.GONE);
ExtendedFloatingActionButton edit = getNormalEditButton();
if(edit!=null) {
edit.setVisibility(View.VISIBLE);
edit.setOnClickListener(v -> {
if (listener != null) {
listener.changeMode(NoteFragmentListener.Mode.EDIT, true);
}
});
}
}
}
@ -110,6 +119,14 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
}
}
protected boolean isDirectEditEnabled() {
if (!directEditAvailable) {
return false;
}
//todo: handle preference here
return false;
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
@ -258,6 +275,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@NonNull
protected abstract ExtendedFloatingActionButton getDirectEditingButton();
protected abstract ExtendedFloatingActionButton getNormalEditButton();
private void showSearchFabs() {
ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false);
@ -353,5 +371,9 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
util.material.themeFAB(getSearchNextButton());
util.material.themeFAB(getSearchPrevButton());
util.material.themeExtendedFAB(getDirectEditingButton());
var editFab = getNormalEditButton();
if(editFab != null) {
util.material.themeExtendedFAB(editFab);
}
}
}

View file

@ -81,4 +81,19 @@
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/edit"
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_plain_edit"
android:text="@string/noteMode_plain_edit"
android:visibility="visible"
app:backgroundTint="@color/defaultBrand"
app:layout_anchor="@id/scrollView"
app:layout_anchorGravity="bottom|end"
app:icon="@drawable/ic_edit_grey600_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>