mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-21 20:35:58 +03:00
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:
parent
b20ed02f17
commit
3c359f8eb5
4 changed files with 52 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue