2121import androidx .annotation .Nullable ;
2222import androidx .appcompat .widget .SearchView ;
2323import androidx .core .content .ContextCompat ;
24+ import androidx .preference .PreferenceManager ;
2425
2526import com .google .android .material .floatingactionbutton .ExtendedFloatingActionButton ;
2627import com .google .android .material .floatingactionbutton .FloatingActionButton ;
@@ -47,7 +48,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
4748 private SearchView searchView ;
4849 private String searchQuery = null ;
4950 private static final int delay = 50 ; // If the search string does not change after $delay ms, then the search task starts.
50- private boolean directEditAvailable = false ;
51+ private boolean directEditRemotelyAvailable = false ; // avoid using this directly, instead use: isDirectEditEnabled()
5152
5253 @ ColorInt
5354 private int color ;
@@ -72,7 +73,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
7273 @ Override
7374 protected void onScroll (int scrollY , int oldScrollY ) {
7475 super .onScroll (scrollY , oldScrollY );
75- if (directEditAvailable ) {
76+ if (isDirectEditEnabled () ) {
7677 // only show FAB if search is not active
7778 if (getSearchNextButton () == null || getSearchNextButton ().getVisibility () != View .VISIBLE ) {
7879 final ExtendedFloatingActionButton directFab = getDirectEditingButton ();
@@ -85,7 +86,7 @@ protected void onScroll(int scrollY, int oldScrollY) {
8586 public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
8687 super .onViewCreated (view , savedInstanceState );
8788 checkDirectEditingAvailable ();
88- if (directEditAvailable ) {
89+ if (isDirectEditEnabled () ) {
8990 final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton ();
9091 directEditingButton .setExtended (false );
9192 ExtendedFabUtil .toggleExtendedOnLongClick (directEditingButton );
@@ -96,18 +97,35 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9697 });
9798 } else {
9899 getDirectEditingButton ().setVisibility (View .GONE );
100+ ExtendedFloatingActionButton edit = getNormalEditButton ();
101+ if (edit !=null ) {
102+ edit .setVisibility (View .VISIBLE );
103+ edit .setOnClickListener (v -> {
104+ if (listener != null ) {
105+ listener .changeMode (NoteFragmentListener .Mode .EDIT , true );
106+ }
107+ });
108+ }
99109 }
100110 }
101111
102112 private void checkDirectEditingAvailable () {
103113 try {
104114 final SingleSignOnAccount ssoAccount = SingleAccountHelper .getCurrentSingleSignOnAccount (requireContext ());
105115 final Account localAccount = repo .getAccountByName (ssoAccount .name );
106- directEditAvailable = localAccount != null && localAccount .isDirectEditingAvailable ();
116+ directEditRemotelyAvailable = localAccount != null && localAccount .isDirectEditingAvailable ();
107117 } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e ) {
108118 Log .w (TAG , "checkDirectEditingAvailable: " , e );
109- directEditAvailable = false ;
119+ directEditRemotelyAvailable = false ;
120+ }
121+ }
122+
123+ protected boolean isDirectEditEnabled () {
124+ if (!directEditRemotelyAvailable ) {
125+ return false ;
110126 }
127+ final var sp = PreferenceManager .getDefaultSharedPreferences (requireContext ().getApplicationContext ());
128+ return sp .getBoolean (getString (R .string .pref_key_enable_direct_edit ), true );
111129 }
112130
113131 @ Override
@@ -258,6 +276,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
258276 @ NonNull
259277 protected abstract ExtendedFloatingActionButton getDirectEditingButton ();
260278
279+ protected abstract ExtendedFloatingActionButton getNormalEditButton ();
261280
262281 private void showSearchFabs () {
263282 ExtendedFabUtil .setExtendedFabVisibility (getDirectEditingButton (), false );
@@ -353,5 +372,9 @@ public void applyBrand(int color) {
353372 util .material .themeFAB (getSearchNextButton ());
354373 util .material .themeFAB (getSearchPrevButton ());
355374 util .material .themeExtendedFAB (getDirectEditingButton ());
375+ var editFab = getNormalEditButton ();
376+ if (editFab != null ) {
377+ util .material .themeExtendedFAB (editFab );
378+ }
356379 }
357380}
0 commit comments