Skip to content

Commit 3c359f8

Browse files
newhintonAndyScherzinger
authored andcommitted
Allow an edit fab to replace the rich text fab
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
1 parent b20ed02 commit 3c359f8

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

app/src/main/java/it/niedermann/owncloud/notes/edit/NoteEditFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ protected FloatingActionButton getSearchPrevButton() {
115115
return binding.directEditing;
116116
}
117117

118+
protected ExtendedFloatingActionButton getNormalEditButton() {
119+
// the edit fragment does not have a button
120+
return null;
121+
}
122+
118123
@Nullable
119124
@Override
120125
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

app/src/main/java/it/niedermann/owncloud/notes/edit/NotePreviewFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
5858
public void onPrepareOptionsMenu(@NonNull Menu menu) {
5959
super.onPrepareOptionsMenu(menu);
6060
menu.findItem(R.id.menu_edit).setVisible(true);
61+
if(getNormalEditButton().getVisibility() == View.VISIBLE) {
62+
menu.findItem(R.id.menu_edit).setVisible(false);
63+
}
64+
6165
menu.findItem(R.id.menu_preview).setVisible(false);
6266
}
6367

@@ -92,6 +96,11 @@ protected FloatingActionButton getSearchPrevButton() {
9296
return binding.directEditing;
9397
}
9498

99+
@Override
100+
protected ExtendedFloatingActionButton getNormalEditButton() {
101+
return binding.edit;
102+
}
103+
95104
@Override
96105
protected Layout getLayout() {
97106
binding.singleNoteContent.onPreDraw();

app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected void onScroll(int scrollY, int oldScrollY) {
8585
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
8686
super.onViewCreated(view, savedInstanceState);
8787
checkDirectEditingAvailable();
88-
if (directEditAvailable) {
88+
if (directEditAvailable && isDirectEditEnabled()) {
8989
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
9090
directEditingButton.setExtended(false);
9191
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
@@ -96,6 +96,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9696
});
9797
} else {
9898
getDirectEditingButton().setVisibility(View.GONE);
99+
ExtendedFloatingActionButton edit = getNormalEditButton();
100+
if(edit!=null) {
101+
edit.setVisibility(View.VISIBLE);
102+
edit.setOnClickListener(v -> {
103+
if (listener != null) {
104+
listener.changeMode(NoteFragmentListener.Mode.EDIT, true);
105+
}
106+
});
107+
}
99108
}
100109
}
101110

@@ -110,6 +119,14 @@ private void checkDirectEditingAvailable() {
110119
}
111120
}
112121

122+
protected boolean isDirectEditEnabled() {
123+
if (!directEditAvailable) {
124+
return false;
125+
}
126+
//todo: handle preference here
127+
return false;
128+
}
129+
113130
@Override
114131
public void onPrepareOptionsMenu(@NonNull Menu menu) {
115132
super.onPrepareOptionsMenu(menu);
@@ -258,6 +275,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
258275
@NonNull
259276
protected abstract ExtendedFloatingActionButton getDirectEditingButton();
260277

278+
protected abstract ExtendedFloatingActionButton getNormalEditButton();
261279

262280
private void showSearchFabs() {
263281
ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false);
@@ -353,5 +371,9 @@ public void applyBrand(int color) {
353371
util.material.themeFAB(getSearchNextButton());
354372
util.material.themeFAB(getSearchPrevButton());
355373
util.material.themeExtendedFAB(getDirectEditingButton());
374+
var editFab = getNormalEditButton();
375+
if(editFab != null) {
376+
util.material.themeExtendedFAB(editFab);
377+
}
356378
}
357379
}

app/src/main/res/layout/fragment_note_preview.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@
8181
app:layout_anchor="@id/scrollView"
8282
app:layout_anchorGravity="bottom|end"
8383
app:icon="@drawable/ic_rich_editing" />
84+
85+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
86+
android:id="@+id/edit"
87+
style="?attr/floatingActionButtonPrimaryStyle"
88+
android:layout_width="wrap_content"
89+
android:layout_height="wrap_content"
90+
android:layout_gravity="bottom|end"
91+
android:layout_margin="@dimen/spacer_2x"
92+
android:contentDescription="@string/noteMode_plain_edit"
93+
android:text="@string/noteMode_plain_edit"
94+
android:visibility="visible"
95+
app:backgroundTint="@color/defaultBrand"
96+
app:layout_anchor="@id/scrollView"
97+
app:layout_anchorGravity="bottom|end"
98+
app:icon="@drawable/ic_edit_grey600_24dp" />
8499
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)