From 5f4bc7fafde92f18453571054dbdc3b29d196416 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 24 May 2022 16:17:35 +0530 Subject: [PATCH] Allow disabling pull-to-sync operation (#1922) --- .../dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt | 7 +++++++ .../java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt | 6 ++++++ .../java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt | 1 + app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 16 insertions(+) diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt index 0d0f9cfc..117d1d49 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/passwords/PasswordFragment.kt @@ -29,6 +29,7 @@ import dev.msfjarvis.aps.R import dev.msfjarvis.aps.data.password.PasswordItem import dev.msfjarvis.aps.data.repo.PasswordRepository import dev.msfjarvis.aps.databinding.PasswordRecyclerViewBinding +import dev.msfjarvis.aps.injection.prefs.SettingsPreferences import dev.msfjarvis.aps.ui.adapters.PasswordItemRecyclerAdapter import dev.msfjarvis.aps.ui.dialogs.BasicBottomSheet import dev.msfjarvis.aps.ui.dialogs.ItemCreationBottomSheet @@ -55,6 +56,7 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { @Inject lateinit var gitSettings: GitSettings @Inject lateinit var shortcutHandler: ShortcutHandler + @Inject @SettingsPreferences lateinit var prefs: SharedPreferences private lateinit var recyclerAdapter: PasswordItemRecyclerAdapter private lateinit var listener: OnFragmentInteractionListener private lateinit var settings: SharedPreferences @@ -290,6 +292,11 @@ class PasswordFragment : Fragment(R.layout.password_recycler_view) { } } + override fun onResume() { + super.onResume() + binding.swipeRefresher.isEnabled = !prefs.getBoolean(PreferenceKeys.DISABLE_SYNC_ACTION, false) + } + override fun onAttach(context: Context) { super.onAttach(context) runCatching { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt b/app/src/main/java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt index f78f2cb2..6d8ab5f6 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt @@ -42,6 +42,12 @@ class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider titleRes = R.string.pref_sort_order_title } + checkBox(PreferenceKeys.DISABLE_SYNC_ACTION) { + titleRes = R.string.pref_disable_sync_on_pull_title + summaryRes = R.string.pref_disable_sync_on_pull_summary + defaultValue = false + } + checkBox(PreferenceKeys.FILTER_RECURSIVELY) { titleRes = R.string.pref_recursive_filter_title summaryRes = R.string.pref_recursive_filter_summary diff --git a/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt b/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt index 152275d6..7f4e0daf 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/settings/PreferenceKeys.kt @@ -84,4 +84,5 @@ object PreferenceKeys { const val DICEWARE_SEPARATOR = "diceware_separator" const val DICEWARE_LENGTH = "diceware_length" + const val DISABLE_SYNC_ACTION = "disable_sync_action" } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fcfc4ade..adac6d51 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -132,6 +132,8 @@ Rebase on pull When pulling or syncing, create a merge commit with upstream changes When pulling or syncing, rebase commits that are not present in the remote repository + Disable pull to sync action + Prevent pulling down on the password list from triggering a Git sync Generate Password