diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java index c628bd4..dae24b0 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java @@ -15,14 +15,19 @@ import com.google.firebase.iid.FirebaseInstanceId; public class SCNSettings { private final static Object _lock = new Object(); - private static SCNSettings _inst = null; + private static volatile SCNSettings _inst = null; public static SCNSettings inst() { - synchronized (_lock) + SCNSettings local = _inst; + if (local == null) { - if (_inst != null) return _inst; - return _inst = new SCNSettings(); + synchronized (_lock) + { + local = _inst; + if (local == null) _inst = local = new SCNSettings(); + } } + return local; } // ------------------------------------------------------------ @@ -47,6 +52,7 @@ public class SCNSettings public boolean Enabled = true; public int LocalCacheSize = 500; + public boolean EnableDeleteSwipe = true; public final NotificationSettings PriorityLow = new NotificationSettings(PriorityEnum.LOW); public final NotificationSettings PriorityNorm = new NotificationSettings(PriorityEnum.NORMAL); @@ -70,6 +76,7 @@ public class SCNSettings Enabled = sharedPref.getBoolean("app_enabled", Enabled); LocalCacheSize = sharedPref.getInt("local_cache_size", LocalCacheSize); + EnableDeleteSwipe = sharedPref.getBoolean("do_del_swipe", EnableDeleteSwipe); PriorityLow.EnableLED = sharedPref.getBoolean("priority_low:enabled_led", PriorityLow.EnableLED); PriorityLow.EnableSound = sharedPref.getBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); @@ -116,6 +123,7 @@ public class SCNSettings e.putBoolean("app_enabled", Enabled); e.putInt( "local_cache_size", LocalCacheSize); + e.putBoolean("do_del_swipe", EnableDeleteSwipe); e.putBoolean("priority_low:enabled_led", PriorityLow.EnableLED); e.putBoolean("priority_low:enabled_sound", PriorityLow.EnableSound); diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/util/MessageAdapterTouchHelper.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/util/MessageAdapterTouchHelper.java index 191eb75..6edbc47 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/util/MessageAdapterTouchHelper.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/util/MessageAdapterTouchHelper.java @@ -3,6 +3,7 @@ package com.blackforestbytes.simplecloudnotifier.util; import android.graphics.Canvas; import android.view.View; +import com.blackforestbytes.simplecloudnotifier.model.SCNSettings; import com.blackforestbytes.simplecloudnotifier.view.MessageAdapter; import androidx.annotation.NonNull; @@ -13,10 +14,21 @@ public class MessageAdapterTouchHelper extends ItemTouchHelper.SimpleCallback { private MessageAdapterTouchHelperListener listener; + private int dir = 0; + public MessageAdapterTouchHelper(int dragDirs, int swipeDirs, MessageAdapterTouchHelperListener listener) { super(dragDirs, swipeDirs); + this.dir = swipeDirs; this.listener = listener; + updateEnabled(); + } + + public void updateEnabled() + { + int sdir = SCNSettings.inst().EnableDeleteSwipe ? ItemTouchHelper.LEFT : 0; + if (dir == sdir) return; + setDefaultSwipeDirs(dir = sdir); } @Override diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java index 554162c..78ab59d 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import com.blackforestbytes.simplecloudnotifier.R; import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.model.CMessage; -import com.blackforestbytes.simplecloudnotifier.model.CMessageList; import com.blackforestbytes.simplecloudnotifier.model.SCNSettings; import com.blackforestbytes.simplecloudnotifier.service.IABService; import com.blackforestbytes.simplecloudnotifier.util.MessageAdapterTouchHelper; @@ -28,6 +27,8 @@ public class NotificationsFragment extends Fragment implements MessageAdapterTou private PublisherAdView adView; private MessageAdapter adpMessages; + public MessageAdapterTouchHelper touchHelper; + public NotificationsFragment() { // Required empty public constructor @@ -43,7 +44,7 @@ public class NotificationsFragment extends Fragment implements MessageAdapterTou rvMessages.setLayoutManager(lman); rvMessages.setAdapter(adpMessages = new MessageAdapter(v.findViewById(R.id.tvNoElements), lman, rvMessages)); - ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new MessageAdapterTouchHelper(0, ItemTouchHelper.LEFT, this); + ItemTouchHelper.SimpleCallback itemTouchHelperCallback = touchHelper = new MessageAdapterTouchHelper(0, ItemTouchHelper.LEFT, this); new ItemTouchHelper(itemTouchHelperCallback).attachToRecyclerView(rvMessages); adView = v.findViewById(R.id.adBanner); diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java index cdb747d..1a42787 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/SettingsFragment.java @@ -49,6 +49,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener private Button prefUpgradeAccount; private TextView prefUpgradeAccount_msg; private TextView prefUpgradeAccount_info; + private Switch prefEnableDeleteSwipe; private Switch prefMsgLowEnableSound; private TextView prefMsgLowRingtone_value; @@ -114,6 +115,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener prefUpgradeAccount = v.findViewById(R.id.prefUpgradeAccount); prefUpgradeAccount_msg = v.findViewById(R.id.prefUpgradeAccount2); prefUpgradeAccount_info = v.findViewById(R.id.prefUpgradeAccount_info); + prefEnableDeleteSwipe = v.findViewById(R.id.prefEnableDeleteSwipe); prefMsgLowEnableSound = v.findViewById(R.id.prefMsgLowEnableSound); prefMsgLowRingtone_value = v.findViewById(R.id.prefMsgLowRingtone_value); @@ -159,6 +161,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener if (c == null) return; if (prefAppEnabled.isChecked() != s.Enabled) prefAppEnabled.setChecked(s.Enabled); + if (prefEnableDeleteSwipe.isChecked() != s.EnableDeleteSwipe) prefEnableDeleteSwipe.setChecked(s.EnableDeleteSwipe); prefUpgradeAccount.setVisibility( SCNSettings.inst().promode_local ? View.GONE : View.VISIBLE); prefUpgradeAccount_info.setVisibility(SCNSettings.inst().promode_local ? View.GONE : View.VISIBLE); @@ -214,6 +217,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener SCNSettings s = SCNSettings.inst(); prefAppEnabled.setOnCheckedChangeListener((a,b) -> { s.Enabled=b; saveAndUpdate(); }); + prefEnableDeleteSwipe.setOnCheckedChangeListener((a,b) -> { s.EnableDeleteSwipe=b; saveAndUpdate(); }); prefLocalCacheSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @@ -324,6 +328,7 @@ public class SettingsFragment extends Fragment implements MusicPickerListener { SCNSettings.inst().save(); updateUI(); + SCNApp.getMainActivity().adpTabs.tab1.touchHelper.updateEnabled(); } private void onUpgradeAccount() diff --git a/android/app/src/main/res/layout/fragment_settings.xml b/android/app/src/main/res/layout/fragment_settings.xml index ccb4ccb..6882028 100644 --- a/android/app/src/main/res/layout/fragment_settings.xml +++ b/android/app/src/main/res/layout/fragment_settings.xml @@ -79,6 +79,22 @@ + + + + Notification light color Enable notification vibration Upgrade account + Delete messages by swiping left Thank you for supporting the app and using the pro mode Increase your daily quota, remove the ad banner and support the developer (that\'s me) Volume icon