mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-26 14:57:38 +03:00
Merge pull request #1904 from newhinton/feature/1819/disableRichEditor
Allow the user to disable direct-editing
This commit is contained in:
commit
9ab92fd883
8 changed files with 89 additions and 5 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();
|
||||
|
|
|
@ -21,6 +21,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
@ -47,7 +48,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
private SearchView searchView;
|
||||
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 boolean directEditAvailable = false;
|
||||
private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()
|
||||
|
||||
@ColorInt
|
||||
private int color;
|
||||
|
@ -72,7 +73,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
@Override
|
||||
protected void onScroll(int scrollY, int oldScrollY) {
|
||||
super.onScroll(scrollY, oldScrollY);
|
||||
if (directEditAvailable) {
|
||||
if (isDirectEditEnabled()) {
|
||||
// only show FAB if search is not active
|
||||
if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) {
|
||||
final ExtendedFloatingActionButton directFab = getDirectEditingButton();
|
||||
|
@ -85,7 +86,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
checkDirectEditingAvailable();
|
||||
if (directEditAvailable) {
|
||||
if (isDirectEditEnabled()) {
|
||||
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
|
||||
directEditingButton.setExtended(false);
|
||||
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
|
||||
|
@ -96,6 +97,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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,13 +113,21 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
|||
try {
|
||||
final SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext());
|
||||
final Account localAccount = repo.getAccountByName(ssoAccount.name);
|
||||
directEditAvailable = localAccount != null && localAccount.isDirectEditingAvailable();
|
||||
directEditRemotelyAvailable = localAccount != null && localAccount.isDirectEditingAvailable();
|
||||
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException 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
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
@ -258,6 +276,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 +372,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
|
|||
private BrandedSwitchPreference preventScreenCapturePref;
|
||||
private BrandedSwitchPreference backgroundSyncPref;
|
||||
private BrandedSwitchPreference keepScreenOnPref;
|
||||
private BrandedSwitchPreference enableDirectEditorPref;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
|
@ -114,6 +115,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
|
|||
SyncWorker.update(requireContext(), (Boolean) newValue);
|
||||
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);
|
||||
backgroundSyncPref.applyBrand(color);
|
||||
keepScreenOnPref.applyBrand(color);
|
||||
enableDirectEditorPref.applyBrand(color);
|
||||
}
|
||||
}
|
||||
|
|
16
app/src/main/res/drawable/ic_rich_editing_grey600_24dp.xml
Normal file
16
app/src/main/res/drawable/ic_rich_editing_grey600_24dp.xml
Normal 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>
|
|
@ -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>
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
<string name="settings_background_sync">Background synchronization</string>
|
||||
<string name="settings_prevent_screen_capture">Prevent screen capture</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_summary">When viewing or editing a note</string>
|
||||
|
||||
|
@ -127,6 +129,7 @@
|
|||
<string name="pref_category_security" translatable="false">security</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_enable_direct_edit" translatable="false">directEditPreference</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_preview" translatable="false">preview</string>
|
||||
|
|
|
@ -52,6 +52,15 @@
|
|||
android:summary="%s"
|
||||
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
|
||||
android:icon="@drawable/ic_baseline_dashboard_24"
|
||||
android:key="@string/pref_key_gridview"
|
||||
|
|
Loading…
Reference in a new issue