Merge pull request #1904 from newhinton/feature/1819/disableRichEditor

Allow the user to disable direct-editing
This commit is contained in:
Andy Scherzinger 2024-04-01 14:45:28 +02:00 committed by GitHub
commit 9ab92fd883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 89 additions and 5 deletions

View file

@ -115,6 +115,11 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
return binding.directEditing; return binding.directEditing;
} }
protected ExtendedFloatingActionButton getNormalEditButton() {
// the edit fragment does not have a button
return null;
}
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 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) { public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_edit).setVisible(true); 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); menu.findItem(R.id.menu_preview).setVisible(false);
} }
@ -92,6 +96,11 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
return binding.directEditing; return binding.directEditing;
} }
@Override
protected ExtendedFloatingActionButton getNormalEditButton() {
return binding.edit;
}
@Override @Override
protected Layout getLayout() { protected Layout getLayout() {
binding.singleNoteContent.onPreDraw(); binding.singleNoteContent.onPreDraw();

View file

@ -21,6 +21,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton; import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -47,7 +48,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private SearchView searchView; private SearchView searchView;
private String searchQuery = null; private String searchQuery = null;
private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts. private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
private boolean directEditAvailable = false; private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()
@ColorInt @ColorInt
private int color; private int color;
@ -72,7 +73,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@Override @Override
protected void onScroll(int scrollY, int oldScrollY) { protected void onScroll(int scrollY, int oldScrollY) {
super.onScroll(scrollY, oldScrollY); super.onScroll(scrollY, oldScrollY);
if (directEditAvailable) { if (isDirectEditEnabled()) {
// only show FAB if search is not active // only show FAB if search is not active
if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) { if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) {
final ExtendedFloatingActionButton directFab = getDirectEditingButton(); final ExtendedFloatingActionButton directFab = getDirectEditingButton();
@ -85,7 +86,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
checkDirectEditingAvailable(); checkDirectEditingAvailable();
if (directEditAvailable) { if (isDirectEditEnabled()) {
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton(); final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
directEditingButton.setExtended(false); directEditingButton.setExtended(false);
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton); ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
@ -96,6 +97,15 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
}); });
} else { } else {
getDirectEditingButton().setVisibility(View.GONE); 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);
}
});
}
} }
} }
@ -103,13 +113,21 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
try { try {
final SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext()); final SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext());
final Account localAccount = repo.getAccountByName(ssoAccount.name); final Account localAccount = repo.getAccountByName(ssoAccount.name);
directEditAvailable = localAccount != null && localAccount.isDirectEditingAvailable(); directEditRemotelyAvailable = localAccount != null && localAccount.isDirectEditingAvailable();
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) { } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
Log.w(TAG, "checkDirectEditingAvailable: ", e); Log.w(TAG, "checkDirectEditingAvailable: ", e);
directEditAvailable = false; directEditRemotelyAvailable = false;
} }
} }
protected boolean isDirectEditEnabled() {
if (!directEditRemotelyAvailable) {
return false;
}
final var sp = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
return sp.getBoolean(getString(R.string.pref_key_enable_direct_edit), true);
}
@Override @Override
public void onPrepareOptionsMenu(@NonNull Menu menu) { public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
@ -258,6 +276,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
@NonNull @NonNull
protected abstract ExtendedFloatingActionButton getDirectEditingButton(); protected abstract ExtendedFloatingActionButton getDirectEditingButton();
protected abstract ExtendedFloatingActionButton getNormalEditButton();
private void showSearchFabs() { private void showSearchFabs() {
ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false); ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false);
@ -353,5 +372,9 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
util.material.themeFAB(getSearchNextButton()); util.material.themeFAB(getSearchNextButton());
util.material.themeFAB(getSearchPrevButton()); util.material.themeFAB(getSearchPrevButton());
util.material.themeExtendedFAB(getDirectEditingButton()); util.material.themeExtendedFAB(getDirectEditingButton());
var editFab = getNormalEditButton();
if(editFab != null) {
util.material.themeExtendedFAB(editFab);
}
} }
} }

View file

@ -40,6 +40,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
private BrandedSwitchPreference preventScreenCapturePref; private BrandedSwitchPreference preventScreenCapturePref;
private BrandedSwitchPreference backgroundSyncPref; private BrandedSwitchPreference backgroundSyncPref;
private BrandedSwitchPreference keepScreenOnPref; private BrandedSwitchPreference keepScreenOnPref;
private BrandedSwitchPreference enableDirectEditorPref;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@ -114,6 +115,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
SyncWorker.update(requireContext(), (Boolean) newValue); SyncWorker.update(requireContext(), (Boolean) newValue);
return true; return true;
}); });
enableDirectEditorPref = findPreference(getString(R.string.pref_key_enable_direct_edit));
} }
@ -141,5 +144,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
preventScreenCapturePref.applyBrand(color); preventScreenCapturePref.applyBrand(color);
backgroundSyncPref.applyBrand(color); backgroundSyncPref.applyBrand(color);
keepScreenOnPref.applyBrand(color); keepScreenOnPref.applyBrand(color);
enableDirectEditorPref.applyBrand(color);
} }
} }

View file

@ -0,0 +1,16 @@
<!--
~ Nextcloud Notes - Android Client
~
~ SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
~ SPDX-FileCopyrightText: 2021 Andreas Gohr
~ SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF757575"
android:pathData="M3,7H9V13H3V7M3,3H21V5H3V3M21,7V9H11V7H21M21,11V13H11V11H21M3,15H17V17H3V15M3,19H21V21H3V19Z" />
</vector>

View file

@ -81,4 +81,19 @@
app:layout_anchor="@id/scrollView" app:layout_anchor="@id/scrollView"
app:layout_anchorGravity="bottom|end" app:layout_anchorGravity="bottom|end"
app:icon="@drawable/ic_rich_editing" /> 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> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -56,6 +56,8 @@
<string name="settings_background_sync">Background synchronization</string> <string name="settings_background_sync">Background synchronization</string>
<string name="settings_prevent_screen_capture">Prevent screen capture</string> <string name="settings_prevent_screen_capture">Prevent screen capture</string>
<string name="settings_gridview">Grid view</string> <string name="settings_gridview">Grid view</string>
<string name="settings_enable_direct_edit">Direct Edit</string>
<string name="settings_enable_direct_edit_summary">When disabled, the advanced editor will be hidden.</string>
<string name="settings_keep_screen_on">Keep screen on</string> <string name="settings_keep_screen_on">Keep screen on</string>
<string name="settings_keep_screen_on_summary">When viewing or editing a note</string> <string name="settings_keep_screen_on_summary">When viewing or editing a note</string>
@ -127,6 +129,7 @@
<string name="pref_category_security" translatable="false">security</string> <string name="pref_category_security" translatable="false">security</string>
<string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string> <string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string>
<string name="pref_key_background_sync" translatable="false">backgroundSync</string> <string name="pref_key_background_sync" translatable="false">backgroundSync</string>
<string name="pref_key_enable_direct_edit" translatable="false">directEditPreference</string>
<string name="pref_value_mode_edit" translatable="false">edit</string> <string name="pref_value_mode_edit" translatable="false">edit</string>
<string name="pref_value_mode_direct_edit" translatable="false">directEdit</string> <string name="pref_value_mode_direct_edit" translatable="false">directEdit</string>
<string name="pref_value_mode_preview" translatable="false">preview</string> <string name="pref_value_mode_preview" translatable="false">preview</string>

View file

@ -52,6 +52,15 @@
android:summary="%s" android:summary="%s"
android:title="@string/settings_note_mode_new" /> android:title="@string/settings_note_mode_new" />
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_rich_editing_grey600_24dp"
android:key="@string/pref_key_enable_direct_edit"
android:layout="@layout/item_pref"
android:title="@string/settings_enable_direct_edit"
android:summary="@string/settings_enable_direct_edit_summary" />
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference <it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
android:icon="@drawable/ic_baseline_dashboard_24" android:icon="@drawable/ic_baseline_dashboard_24"
android:key="@string/pref_key_gridview" android:key="@string/pref_key_gridview"