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 && isDirectEditEnabled ()) {
89+ if (isDirectEditEnabled ()) {
8990 final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton ();
9091 directEditingButton .setExtended (false );
9192 ExtendedFabUtil .toggleExtendedOnLongClick (directEditingButton );
@@ -112,19 +113,19 @@ private void checkDirectEditingAvailable() {
112113 try {
113114 final SingleSignOnAccount ssoAccount = SingleAccountHelper .getCurrentSingleSignOnAccount (requireContext ());
114115 final Account localAccount = repo .getAccountByName (ssoAccount .name );
115- directEditAvailable = localAccount != null && localAccount .isDirectEditingAvailable ();
116+ directEditRemotelyAvailable = localAccount != null && localAccount .isDirectEditingAvailable ();
116117 } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e ) {
117118 Log .w (TAG , "checkDirectEditingAvailable: " , e );
118- directEditAvailable = false ;
119+ directEditRemotelyAvailable = false ;
119120 }
120121 }
121122
122123 protected boolean isDirectEditEnabled () {
123- if (!directEditAvailable ) {
124+ if (!directEditRemotelyAvailable ) {
124125 return false ;
125126 }
126- //todo: handle preference here
127- return false ;
127+ final var sp = PreferenceManager . getDefaultSharedPreferences ( requireContext (). getApplicationContext ());
128+ return sp . getBoolean ( getString ( R . string . pref_key_enable_direct_edit ), true ) ;
128129 }
129130
130131 @ Override
0 commit comments