From 05166944d8e29aa200dd76598fe29182760893e9 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 7 Oct 2021 12:45:59 +0100 Subject: [PATCH] navigating to the settings discovery page on policy link clicked from non discovery screens --- .../src/main/java/im/vector/app/core/utils/Dialogs.kt | 10 +++------- .../app/features/contactsbook/ContactsBookFragment.kt | 9 ++++++--- .../features/discovery/DiscoverySettingsFragment.kt | 1 - .../app/features/userdirectory/UserListFragment.kt | 8 +++++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/utils/Dialogs.kt b/vector/src/main/java/im/vector/app/core/utils/Dialogs.kt index 99e8684229..ed3ae00567 100644 --- a/vector/src/main/java/im/vector/app/core/utils/Dialogs.kt +++ b/vector/src/main/java/im/vector/app/core/utils/Dialogs.kt @@ -40,19 +40,15 @@ fun Context.displayInWebView(url: String) { .show() } -fun Context.showIdentityServerConsentDialog(configuredIdentityServer: String?, policyLinkCallback: (() -> Unit)? = null, consentCallBack: (() -> Unit)) { +fun Context.showIdentityServerConsentDialog(configuredIdentityServer: String?, policyLinkCallback: () -> Unit, consentCallBack: (() -> Unit)) { MaterialAlertDialogBuilder(this) .setTitle(R.string.identity_server_consent_dialog_title) .setMessage(getString(R.string.identity_server_consent_dialog_content, configuredIdentityServer ?: "")) .setPositiveButton(R.string.yes) { _, _ -> consentCallBack.invoke() } - .apply { - if (policyLinkCallback != null) { - setNeutralButton(R.string.identity_server_consent_dialog_neutral_policy) { _, _ -> - policyLinkCallback.invoke() - } - } + .setNeutralButton(R.string.identity_server_consent_dialog_neutral_policy) { _, _ -> + policyLinkCallback.invoke() } .setNegativeButton(R.string.no, null) .show() diff --git a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt index fc913ff835..fc24aa3e87 100644 --- a/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt +++ b/vector/src/main/java/im/vector/app/features/contactsbook/ContactsBookFragment.kt @@ -31,6 +31,7 @@ import im.vector.app.core.extensions.hideKeyboard import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.showIdentityServerConsentDialog import im.vector.app.databinding.FragmentContactsBookBinding +import im.vector.app.features.settings.VectorSettingsActivity import im.vector.app.features.userdirectory.PendingSelection import im.vector.app.features.userdirectory.UserListAction import im.vector.app.features.userdirectory.UserListSharedAction @@ -74,9 +75,11 @@ class ContactsBookFragment @Inject constructor( private fun setupConsentView() { views.phoneBookSearchForMatrixContacts.setOnClickListener { withState(contactsBookViewModel) { state -> - requireContext().showIdentityServerConsentDialog(state.identityServerUrl) { - contactsBookViewModel.handle(ContactsBookAction.UserConsentGranted) - } + requireContext().showIdentityServerConsentDialog( + state.identityServerUrl, + policyLinkCallback = { navigator.openSettings(requireContext(), VectorSettingsActivity.EXTRA_DIRECT_ACCESS_DISCOVERY_SETTINGS) }, + consentCallBack = { contactsBookViewModel.handle(ContactsBookAction.UserConsentGranted) } + ) } } } diff --git a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt index 1302df48ec..0d31edd047 100644 --- a/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/discovery/DiscoverySettingsFragment.kt @@ -31,7 +31,6 @@ import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.observeEvent import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.platform.VectorBaseFragment -import im.vector.app.core.utils.displayInWebView import im.vector.app.core.utils.ensureProtocol import im.vector.app.core.utils.openUrlInChromeCustomTab import im.vector.app.core.utils.showIdentityServerConsentDialog diff --git a/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt b/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt index 5fdc316851..009961ebbc 100644 --- a/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/userdirectory/UserListFragment.kt @@ -227,9 +227,11 @@ class UserListFragment @Inject constructor( override fun giveIdentityServerConsent() { withState(viewModel) { state -> - requireContext().showIdentityServerConsentDialog(state.configuredIdentityServer) { - viewModel.handle(UserListAction.UpdateUserConsent(true)) - } + requireContext().showIdentityServerConsentDialog( + state.configuredIdentityServer, + policyLinkCallback = { navigator.openSettings(requireContext(), VectorSettingsActivity.EXTRA_DIRECT_ACCESS_DISCOVERY_SETTINGS) }, + consentCallBack = { viewModel.handle(UserListAction.UpdateUserConsent(true)) } + ) } }