Skip to content

Commit ba14d75

Browse files
committed
feat(note-list): add option to disable swipe actions
Add a toggle in the "Appearance and behavior" settings to enable or disable swipe gestures (delete and favorite) in the note list. The default value is set to enabled, preserving existing behavior while allowing users who accidentally trigger these actions to disable them. Changes: - Add `swipe_actions` preference to `preferences.xml` - Add `isSwipeEnabled` global state in `NotesApplication` - Update `NotesListViewItemTouchHelper` to respect the setting - Create `ic_swipe_grey600_24dp.xml` for the settings icon
1 parent 970bbc2 commit ba14d75

6 files changed

Lines changed: 53 additions & 1 deletion

File tree

app/src/main/java/it/niedermann/owncloud/notes/NotesApplication.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class NotesApplication extends Application {
3636
private static long lastInteraction = 0;
3737
private static String PREF_KEY_THEME;
3838
private static boolean isGridViewEnabled = false;
39+
private static boolean isSwipeEnabled = true;
3940
private static BrandingUtil brandingUtil;
4041

4142
@Override
@@ -45,6 +46,7 @@ public void onCreate() {
4546
final var prefs = getDefaultSharedPreferences(getApplicationContext());
4647
lockedPreference = prefs.getBoolean(getString(R.string.pref_key_lock), false);
4748
isGridViewEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_gridview), false);
49+
isSwipeEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_swipe_actions), true);
4850
super.onCreate();
4951
brandingUtil = BrandingUtil.getInstance(this);
5052
if (BuildConfig.DEBUG) {
@@ -80,6 +82,14 @@ public static void updateGridViewEnabled(boolean gridView) {
8082
isGridViewEnabled = gridView;
8183
}
8284

85+
public static boolean isSwipeEnabled() {
86+
return isSwipeEnabled;
87+
}
88+
89+
public static void updateSwipeEnabled(boolean swipeEnabled) {
90+
isSwipeEnabled = swipeEnabled;
91+
}
92+
8393
public static DarkModeSetting getAppTheme(Context context) {
8494
final var prefs = getDefaultSharedPreferences(context);
8595
String mode;

app/src/main/java/it/niedermann/owncloud/notes/main/items/list/NotesListViewItemTouchHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.android.material.snackbar.Snackbar;
2525

2626
import it.niedermann.owncloud.notes.R;
27+
import it.niedermann.owncloud.notes.NotesApplication;
2728
import it.niedermann.owncloud.notes.branding.BrandedSnackbar;
2829
import it.niedermann.owncloud.notes.main.MainViewModel;
2930
import it.niedermann.owncloud.notes.main.items.ItemAdapter;
@@ -63,7 +64,7 @@ public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.
6364
*/
6465
@Override
6566
public int getSwipeDirs(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
66-
if (gridView || viewHolder instanceof SectionViewHolder) return 0;
67+
if (gridView || !NotesApplication.isSwipeEnabled() || viewHolder instanceof SectionViewHolder) return 0;
6768
return super.getSwipeDirs(recyclerView, viewHolder);
6869
}
6970

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat implements Bra
3737
private BrandedSwitchPreference lockPref;
3838
private BrandedSwitchPreference wifiOnlyPref;
3939
private BrandedSwitchPreference gridViewPref;
40+
private BrandedSwitchPreference swipeActionsPref;
4041
private BrandedSwitchPreference preventScreenCapturePref;
4142
private BrandedSwitchPreference backgroundSyncPref;
4243
private BrandedSwitchPreference keepScreenOnPref;
@@ -66,6 +67,17 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
6667
Log.e(TAG, "Could not find preference with key: \"" + getString(R.string.pref_key_gridview) + "\"");
6768
}
6869

70+
swipeActionsPref = findPreference(getString(R.string.pref_key_swipe_actions));
71+
if (swipeActionsPref != null) {
72+
swipeActionsPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
73+
final Boolean swipeEnabled = (Boolean) newValue;
74+
Log.v(TAG, "swipeEnabled: " + swipeEnabled);
75+
viewModel.resultCode$.setValue(Activity.RESULT_OK);
76+
NotesApplication.updateSwipeEnabled(swipeEnabled);
77+
return true;
78+
});
79+
}
80+
6981
keepScreenOnPref = findPreference(getString(R.string.pref_key_keep_screen_on));
7082
if (keepScreenOnPref != null) {
7183
keepScreenOnPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
@@ -144,6 +156,7 @@ public void applyBrand(int color) {
144156
lockPref.applyBrand(color);
145157
wifiOnlyPref.applyBrand(color);
146158
gridViewPref.applyBrand(color);
159+
swipeActionsPref.applyBrand(color);
147160
showEcosystemAppBarPref.applyBrand(color);
148161
preventScreenCapturePref.applyBrand(color);
149162
backgroundSyncPref.applyBrand(color);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
~ Nextcloud Notes - Android Client
3+
~
4+
~ SPDX-FileCopyrightText: 2018-2025 Google LLC
5+
~ SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
8+
android:width="24dp"
9+
android:height="24dp"
10+
android:autoMirrored="true"
11+
android:tint="#757575"
12+
android:viewportWidth="960"
13+
android:viewportHeight="960">
14+
<path
15+
android:fillColor="@android:color/white"
16+
android:pathData="M640,680L583,624L767,440L583,256L640,200L880,440L640,680ZM80,760L80,600Q80,517 138.5,458.5Q197,400 280,400L527,400L383,256L440,200L680,440L440,680L383,624L527,480L280,480Q230,480 195,515Q160,550 160,600L160,760L80,760Z" />
17+
</vector>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
<string name="settings_enable_direct_edit_summary">When disabled, the advanced editor will be hidden.</string>
191191
<string name="settings_keep_screen_on">Keep screen on</string>
192192
<string name="settings_keep_screen_on_summary">When viewing or editing a note</string>
193+
<string name="settings_swipe_actions">Swipe actions</string>
194+
<string name="settings_swipe_actions_summary">Mark as favorite or delete notes with a swipe</string>
193195

194196
<string name="error_sync">Synchronization failed: %1$s</string>
195197
<string name="error_synchronization">Synchronization failed</string>
@@ -261,6 +263,7 @@
261263
<string name="pref_key_background_sync" translatable="false">backgroundSync</string>
262264
<string name="pref_key_enable_direct_edit" translatable="false">directEditPreference</string>
263265
<string name="pref_key_show_ecosystem_apps" translatable="false">show_ecosystem_apps</string>
266+
<string name="pref_key_swipe_actions" translatable="false">swipe_actions</string>
264267
<string name="pref_value_mode_edit" translatable="false">edit</string>
265268
<string name="pref_value_mode_direct_edit" translatable="false">directEdit</string>
266269
<string name="pref_value_mode_preview" translatable="false">preview</string>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
android:layout="@layout/item_pref"
7575
android:title="@string/settings_gridview" />
7676

77+
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
78+
android:defaultValue="true"
79+
android:icon="@drawable/ic_swipe_grey600_24dp"
80+
android:key="@string/pref_key_swipe_actions"
81+
android:layout="@layout/item_pref"
82+
android:title="@string/settings_swipe_actions"
83+
android:summary="@string/settings_swipe_actions_summary" />
84+
7785
<it.niedermann.owncloud.notes.branding.BrandedSwitchPreference
7886
android:defaultValue="@string/pref_value_font_normal"
7987
android:icon="@drawable/ic_text_format_grey600_24dp"

0 commit comments

Comments
 (0)