mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 04:46:04 +03:00
Store preference for richtext-editing
Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
This commit is contained in:
parent
3c359f8eb5
commit
b9fc9681e4
5 changed files with 49 additions and 8 deletions
|
@ -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 && isDirectEditEnabled()) {
|
if (isDirectEditEnabled()) {
|
||||||
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
|
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
|
||||||
directEditingButton.setExtended(false);
|
directEditingButton.setExtended(false);
|
||||||
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
|
ExtendedFabUtil.toggleExtendedOnLongClick(directEditingButton);
|
||||||
|
@ -112,19 +113,19 @@ 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() {
|
protected boolean isDirectEditEnabled() {
|
||||||
if (!directEditAvailable) {
|
if (!directEditRemotelyAvailable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//todo: handle preference here
|
final var sp = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
|
||||||
return false;
|
return sp.getBoolean(getString(R.string.pref_key_enable_direct_edit), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
24
app/src/main/res/drawable/ic_rich_editing_grey600_24dp.xml
Normal file
24
app/src/main/res/drawable/ic_rich_editing_grey600_24dp.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!--
|
||||||
|
Copyright Andreas Gohr
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<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>
|
|
@ -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, we will not show the advanced editor.</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>
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue