Skip to content

Commit b9fc968

Browse files
newhintonAndyScherzinger
authored andcommitted
Store preference for richtext-editing
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
1 parent 3c359f8 commit b9fc968

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import androidx.annotation.Nullable;
2222
import androidx.appcompat.widget.SearchView;
2323
import androidx.core.content.ContextCompat;
24+
import androidx.preference.PreferenceManager;
2425

2526
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
2627
import 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

app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
4040
private BrandedSwitchPreference preventScreenCapturePref;
4141
private BrandedSwitchPreference backgroundSyncPref;
4242
private BrandedSwitchPreference keepScreenOnPref;
43+
private BrandedSwitchPreference enableDirectEditorPref;
4344

4445
@Override
4546
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@@ -114,6 +115,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
114115
SyncWorker.update(requireContext(), (Boolean) newValue);
115116
return true;
116117
});
118+
119+
enableDirectEditorPref = findPreference(getString(R.string.pref_key_enable_direct_edit));
117120
}
118121

119122

@@ -141,5 +144,6 @@ public void applyBrand(int color) {
141144
preventScreenCapturePref.applyBrand(color);
142145
backgroundSyncPref.applyBrand(color);
143146
keepScreenOnPref.applyBrand(color);
147+
enableDirectEditorPref.applyBrand(color);
144148
}
145149
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
Copyright Andreas Gohr
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="24"
20+
android:viewportHeight="24">
21+
<path
22+
android:fillColor="#FF757575"
23+
android:pathData="M3,7H9V13H3V7M3,3H21V5H3V3M21,7V9H11V7H21M21,11V13H11V11H21M3,15H17V17H3V15M3,19H21V21H3V19Z" />
24+
</vector>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<string name="settings_background_sync">Background synchronization</string>
5757
<string name="settings_prevent_screen_capture">Prevent screen capture</string>
5858
<string name="settings_gridview">Grid view</string>
59+
<string name="settings_enable_direct_edit">Direct Edit</string>
60+
<string name="settings_enable_direct_edit_summary">When disabled, we will not show the advanced editor.</string>
5961
<string name="settings_keep_screen_on">Keep screen on</string>
6062
<string name="settings_keep_screen_on_summary">When viewing or editing a note</string>
6163

@@ -127,6 +129,7 @@
127129
<string name="pref_category_security" translatable="false">security</string>
128130
<string name="pref_key_last_note_mode" translatable="false">lastNoteMode</string>
129131
<string name="pref_key_background_sync" translatable="false">backgroundSync</string>
132+
<string name="pref_key_enable_direct_edit" translatable="false">directEditPreference</string>
130133
<string name="pref_value_mode_edit" translatable="false">edit</string>
131134
<string name="pref_value_mode_direct_edit" translatable="false">directEdit</string>
132135
<string name="pref_value_mode_preview" translatable="false">preview</string>

app/src/main/res/xml/preferences.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
android:summary="%s"
5353
android:title="@string/settings_note_mode_new" />
5454

55+
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
56+
android:defaultValue="true"
57+
android:icon="@drawable/ic_rich_editing_grey600_24dp"
58+
android:key="@string/pref_key_enable_direct_edit"
59+
android:layout="@layout/item_pref"
60+
android:title="@string/settings_enable_direct_edit"
61+
android:summary="@string/settings_enable_direct_edit_summary" />
62+
63+
5564
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
5665
android:icon="@drawable/ic_baseline_dashboard_24"
5766
android:key="@string/pref_key_gridview"

0 commit comments

Comments
 (0)