From db49cdf7c46d91e0ccadd866e054465388ae1079 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Tue, 24 Sep 2024 15:36:45 +0300 Subject: [PATCH] Adjusted shortcut clicks to only happen if a swipe isn't detected and made swipe thresholds customizable --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 27 ++++++++++++++----- .../settings/SharedPreferenceManager.kt | 8 ++++++ app/src/main/res/values/arrays.xml | 8 ++++++ app/src/main/res/xml/ui_preferences.xml | 18 +++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 32be30c..54ec718 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -105,9 +105,11 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private var isBatteryReceiverRegistered = false private var isJobActive = true + private var isInitialOpen = false + private var canLaunchShortcut = true - private val swipeThreshold = 100 - private val swipeVelocityThreshold = 100 + private var swipeThreshold = 100 + private var swipeVelocityThreshold = 100 private lateinit var clockApp: Pair private lateinit var dateApp: Pair @@ -120,8 +122,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh var returnAllowed = true - private var isInitialOpen = false - private val handler = Handler(Looper.getMainLooper()) override fun onCreate(savedInstanceState: Bundle?) { @@ -295,7 +295,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private fun unsetShortcutListeners(textView: TextView) { textView.setOnClickListener { - Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show() + if (canLaunchShortcut) { + Toast.makeText(this, "Long click to select an app", Toast.LENGTH_SHORT).show() + } } } @@ -311,7 +313,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh private fun setShortcutListeners(textView: TextView, savedView: List?) { textView.setOnClickListener { - if (savedView != null) { + if (savedView != null && canLaunchShortcut) { appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()]) } } @@ -353,6 +355,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh leftSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "left") rightSwipeActivity = gestureUtils.getSwipeInfo(launcherApps, "right") + + swipeThreshold = sharedPreferenceManager.getSwipeThreshold() + swipeVelocityThreshold = sharedPreferenceManager.getSwipeVelocity() } @SuppressLint("ClickableViewAccessibility") @@ -583,6 +588,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh setShortcuts() } + "swipeThreshold" -> { + swipeThreshold = sharedPreferenceManager.getSwipeThreshold() + } + + "swipeVelocity" -> { + swipeVelocityThreshold = sharedPreferenceManager.getSwipeVelocity() + } + "isRestored" -> { preferences.edit().remove("isRestored").apply() setPreferences() @@ -604,6 +617,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } fun backToHome(animSpeed: Long = sharedPreferenceManager.getAnimationSpeed()) { + canLaunchShortcut = true closeKeyboard() animations.showHome(binding.homeView, binding.appView, animSpeed) animations.backgroundOut(this@MainActivity, animSpeed) @@ -1012,6 +1026,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh // Swipe up if (deltaY < -swipeThreshold && abs(velocityY) > swipeVelocityThreshold) { + canLaunchShortcut = false openAppMenu() } diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index 6bfb250..72d825a 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -55,6 +55,14 @@ class SharedPreferenceManager (private val context: Context) { return 200 } + fun getSwipeThreshold(): Int { + return preferences.getString("swipeThreshold", "100")?.toInt() ?: 100 + } + + fun getSwipeVelocity(): Int { + return preferences.getString("swipeVelocity", "100")?.toInt() ?: 100 + } + // Home Screen fun isClockEnabled(): Boolean { return preferences.getBoolean("clockEnabled", true) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index ac1377b..f9f3088 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -99,6 +99,14 @@ 50 + + 25 + 50 + 100 + 200 + 400 + + 0 diff --git a/app/src/main/res/xml/ui_preferences.xml b/app/src/main/res/xml/ui_preferences.xml index 559faed..508944d 100644 --- a/app/src/main/res/xml/ui_preferences.xml +++ b/app/src/main/res/xml/ui_preferences.xml @@ -56,6 +56,24 @@ app:key="animationSpeed" app:title="Animation Speed" app:useSimpleSummaryProvider="true" /> + +