diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 4fdfc7d..4bcded2 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -75,6 +75,9 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap private lateinit var dateText: TextClock + private var cameraSwipeEnabled = true + private var contactsSwipeEnabled = true + @SuppressLint("ClickableViewAccessibility") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -143,6 +146,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap setShortCutAlignment() setSearchAlignment() + setGestures() + adapter?.notifyDataSetChanged() } @@ -177,12 +182,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap } // Detect swipe left - else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold){ + else if (cameraSwipeEnabled && deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold){ startActivity(cameraIntent) } // Detect swipe right - else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold) { + else if (contactsSwipeEnabled && deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold) { startActivity(phoneIntent) } } @@ -722,6 +727,15 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap } } + private fun setGestures() { + val cameraGesture = sharedPreferenceManager.getCameraEnabled(this@MainActivity) + val contactsGesture = sharedPreferenceManager.getContactsEnabled(this@MainActivity) + + cameraSwipeEnabled = cameraGesture + + contactsSwipeEnabled = contactsGesture + } + fun isJobActive(): Boolean { return if (job != null) { job!!.isActive diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt index 075c3c2..957fc8d 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsActivity.kt @@ -122,5 +122,18 @@ class SettingsActivity : AppCompatActivity() { override fun onNothingSelected(parent: AdapterView<*>) { } } + + binding.camera.isChecked = sharedPreferenceManager.getCameraEnabled(this@SettingsActivity) + + binding.camera.setOnCheckedChangeListener { _, isChecked -> + sharedPreferenceManager.setCameraEnabled(this@SettingsActivity, isChecked) + } + + binding.contacts.isChecked = sharedPreferenceManager.getContactsEnabled(this@SettingsActivity) + + binding.contacts.setOnCheckedChangeListener { _, isChecked -> + sharedPreferenceManager.setContactsEnabled(this@SettingsActivity, isChecked) + } + } } \ No newline at end of file diff --git a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt index 4b9ef9d..de9240f 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt @@ -189,4 +189,30 @@ class SharedPreferenceManager { val key = "search_size" return sharedPreferences.getInt(key, 2) } + + fun setCameraEnabled(cont: Context, isEnabled: Boolean) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "camera_enabled" + editor.putBoolean(key, isEnabled) + editor.apply() + } + + fun getCameraEnabled(cont: Context) : Boolean { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "camera_enabled" + return sharedPreferences.getBoolean(key, true) + } + + fun setContactsEnabled(cont: Context, isEnabled: Boolean) { + val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit() + val key = "contacts_enabled" + editor.putBoolean(key, isEnabled) + editor.apply() + } + + fun getContactsEnabled(cont: Context) : Boolean { + val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE) + val key = "contacts_enabled" + return sharedPreferences.getBoolean(key, true) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 55d7af1..ea1317d 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -371,4 +371,82 @@ app:layout_constraintTop_toBottomOf="@+id/search_size_label" tools:layout_editor_absoluteX="46dp" /> + + + + + + + + + + + + \ No newline at end of file