From 3d5d9ad154dd9f5437ca8c7177e561e390008831 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 30 Nov 2021 15:46:27 +0100 Subject: [PATCH] Iterate on the consent dialog of the identity server. --- changelog.d/4577.feature | 1 + .../java/im/vector/app/core/utils/Dialogs.kt | 42 +++++++++++++++---- .../contactsbook/ContactsBookFragment.kt | 5 +-- .../discovery/DiscoverySettingsFragment.kt | 2 +- .../userdirectory/UserListFragment.kt | 5 +-- vector/src/main/res/values/strings.xml | 5 +++ 6 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 changelog.d/4577.feature diff --git a/changelog.d/4577.feature b/changelog.d/4577.feature new file mode 100644 index 0000000000..56ce827769 --- /dev/null +++ b/changelog.d/4577.feature @@ -0,0 +1 @@ +Iterate on the consent dialog of the identity server. \ No newline at end of file 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 ad62b0fcb1..6847c1661c 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 @@ -17,10 +17,15 @@ package im.vector.app.core.utils import android.content.Context +import android.text.method.LinkMovementMethod import android.webkit.WebView import android.webkit.WebViewClient +import android.widget.TextView import com.google.android.material.dialog.MaterialAlertDialogBuilder import im.vector.app.R +import im.vector.app.features.discovery.IdentityServerPolicy +import me.gujun.android.span.link +import me.gujun.android.span.span /** * Open a web view above the current activity. @@ -40,16 +45,37 @@ fun Context.displayInWebView(url: String) { .show() } -fun Context.showIdentityServerConsentDialog(configuredIdentityServer: String?, policyLinkCallback: () -> Unit, consentCallBack: (() -> Unit)) { +fun Context.showIdentityServerConsentDialog(configuredIdentityServer: String?, + policies: List?, + consentCallBack: (() -> Unit)) { + // Build the message + val content = span { + +getString(R.string.identity_server_consent_dialog_content_3) + +"\n\n" + if (!policies.isNullOrEmpty()) { + span { + textStyle = "bold" + text = getString(R.string.settings_privacy_policy) + } + policies.forEach { + +"\n • " + // Use the url as the text too + link(it.url, it.url) + } + +"\n\n" + } + +getString(R.string.identity_server_consent_dialog_content_question) + } MaterialAlertDialogBuilder(this) - .setTitle(getString(R.string.identity_server_consent_dialog_title_2, configuredIdentityServer ?: "")) - .setMessage(R.string.identity_server_consent_dialog_content_2) - .setPositiveButton(R.string.yes) { _, _ -> + .setTitle(getString(R.string.identity_server_consent_dialog_title_2, configuredIdentityServer.orEmpty())) + .setMessage(content) + .setPositiveButton(R.string.reactions_agree) { _, _ -> consentCallBack.invoke() } - .setNeutralButton(R.string.identity_server_consent_dialog_neutral_policy) { _, _ -> - policyLinkCallback.invoke() - } - .setNegativeButton(R.string.no, null) + .setNegativeButton(R.string.action_not_now, null) .show() + .apply { + // Make the link(s) clickable. Must be called after show() + (findViewById(android.R.id.message) as? TextView)?.movementMethod = LinkMovementMethod.getInstance() + } } 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 95c6105912..c98763714b 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 @@ -30,7 +30,6 @@ 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.navigation.SettingsActivityPayload import im.vector.app.features.userdirectory.PendingSelection import im.vector.app.features.userdirectory.UserListAction import im.vector.app.features.userdirectory.UserListSharedAction @@ -75,9 +74,7 @@ class ContactsBookFragment @Inject constructor( withState(contactsBookViewModel) { state -> requireContext().showIdentityServerConsentDialog( state.identityServerUrl, - policyLinkCallback = { - navigator.openSettings(requireContext(), SettingsActivityPayload.DiscoverySettings(expandIdentityPolicies = true)) - }, + /* TODO */ emptyList(), 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 7306146027..0b0236e000 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 @@ -187,7 +187,7 @@ class DiscoverySettingsFragment @Inject constructor( withState(viewModel) { state -> requireContext().showIdentityServerConsentDialog( state.identityServer.invoke()?.serverUrl, - policyLinkCallback = { viewModel.handle(DiscoverySettingsAction.SetPoliciesExpandState(expanded = true)) }, + state.identityServer.invoke()?.policies, consentCallBack = { viewModel.handle(DiscoverySettingsAction.UpdateUserConsent(true)) } ) } 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 2b4d4f6f1e..5ac1a83a6d 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 @@ -42,7 +42,6 @@ import im.vector.app.core.utils.showIdentityServerConsentDialog import im.vector.app.core.utils.startSharePlainTextIntent import im.vector.app.databinding.FragmentUserListBinding import im.vector.app.features.homeserver.HomeServerCapabilitiesViewModel -import im.vector.app.features.navigation.SettingsActivityPayload import im.vector.app.features.settings.VectorSettingsActivity import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -234,9 +233,7 @@ class UserListFragment @Inject constructor( withState(viewModel) { state -> requireContext().showIdentityServerConsentDialog( state.configuredIdentityServer, - policyLinkCallback = { - navigator.openSettings(requireContext(), SettingsActivityPayload.DiscoverySettings(expandIdentityPolicies = true)) - }, + /* TODO */ emptyList(), consentCallBack = { viewModel.handle(UserListAction.UpdateUserConsent(true)) } ) } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index dec9e6e8db..ddb731a5e0 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -456,6 +456,7 @@ Copied to clipboard Disable Return + Not now Confirmation @@ -2193,7 +2194,9 @@ Your rooms will be displayed here. Tap the + bottom right to find existing ones or start some of your own. Reactions + Agree + Like Add Reaction View Reactions @@ -2377,6 +2380,8 @@ Send emails and phone numbers to %s In order to discover existing contacts you know, do you accept to send your contact data (phone numbers and/or emails) to the configured identity server (%1$s)?\n\nFor more privacy, the sent data will be hashed before being sent. To discover existing contacts, you need to send contact info to your identity server.\n\nWe hash your data before sending for privacy. Do you consent to send this info? + To discover existing contacts, you need to send contact info (emails and phone numbers) to your identity server. We hash your data before sending for privacy. + Do you agree to send this info? Policy Enter an identity server URL