From fd92d6559cc80424d3bf4654eb6d2f2c6424ffd4 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 20 Nov 2020 13:24:32 +0100 Subject: [PATCH] Refact move utility method open settings --- .../app/core/utils/ExternalApplicationsUtil.kt | 14 ++++++++++++++ .../vector/app/core/utils/PermissionsTools.kt | 13 +------------ .../settings/VectorSettingsHelpAboutFragment.kt | 17 ++--------------- vector/src/main/res/values/strings.xml | 8 ++++---- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt index ff1055fa44..4c6aa51348 100644 --- a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt +++ b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt @@ -29,6 +29,7 @@ import android.os.Build import android.os.Environment import android.provider.Browser import android.provider.MediaStore +import android.provider.Settings import android.webkit.MimeTypeMap import android.widget.Toast import androidx.activity.result.ActivityResultLauncher @@ -448,6 +449,19 @@ fun openPlayStore(activity: Activity, appId: String = BuildConfig.APPLICATION_ID } } +fun openAppSettingsPage(activity: Activity) { + try { + activity.startActivity( + Intent().apply { + action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + data = Uri.fromParts("package", activity.packageName, null) + }) + } catch (activityNotFoundException: ActivityNotFoundException) { + activity.toast(R.string.error_no_external_application_found) + } +} + /** * Ask the user to select a location and a file name to write in */ diff --git a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt index f3ac8d9c47..606321fff2 100644 --- a/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt +++ b/vector/src/main/java/im/vector/app/core/utils/PermissionsTools.kt @@ -19,11 +19,8 @@ package im.vector.app.core.utils import android.Manifest import android.app.Activity import android.content.Context -import android.content.Intent import android.content.pm.PackageManager -import android.net.Uri import android.os.Build -import android.provider.Settings import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts @@ -34,7 +31,6 @@ import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import im.vector.app.R import im.vector.app.core.platform.VectorBaseActivity -import org.matrix.android.sdk.api.extensions.tryOrNull import timber.log.Timber // Android M permission request code management @@ -291,14 +287,7 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int, fun VectorBaseActivity.onPermissionDeniedSnackbar(@StringRes rationaleMessage: Int) { showSnackbar(getString(rationaleMessage), R.string.settings) { - tryOrNull { - startActivity( - Intent().apply { - action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - data = Uri.fromParts("package", this@onPermissionDeniedSnackbar.packageName, null) - }) - } + openAppSettingsPage(this) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsHelpAboutFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsHelpAboutFragment.kt index 861e0dea1f..c9160b8ebc 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsHelpAboutFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsHelpAboutFragment.kt @@ -16,15 +16,13 @@ package im.vector.app.features.settings -import android.content.Intent -import android.net.Uri -import android.provider.Settings import androidx.preference.Preference import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.preference.VectorPreference import im.vector.app.core.utils.copyToClipboard import im.vector.app.core.utils.displayInWebView +import im.vector.app.core.utils.openAppSettingsPage import im.vector.app.core.utils.openUrlInChromeCustomTab import im.vector.app.features.version.VersionProvider import im.vector.app.openOssLicensesMenuActivity @@ -42,18 +40,7 @@ class VectorSettingsHelpAboutFragment @Inject constructor( // preference to start the App info screen, to facilitate App permissions access findPreference(APP_INFO_LINK_PREFERENCE_KEY)!! .onPreferenceClickListener = Preference.OnPreferenceClickListener { - activity?.let { - val intent = Intent().apply { - action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - - val uri = Uri.fromParts("package", requireContext().packageName, null) - - data = uri - } - it.applicationContext.startActivity(intent) - } - + activity?.let { openAppSettingsPage(it) } true } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index d32dd86a19..7611d0579a 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -425,8 +425,8 @@ Element can check your address book to find other Matrix users based on their email and phone numbers.\n\nDo you agree to share your address book for this purpose? Sorry. Action not performed, due to missing permissions - To scan a QR code, allow Camera permission to take a picture - To check your address book, allow Contact permission. + To scan a QR code, you need to allow camera access. + To check your address book, you need to allow Contact permission. Saved @@ -2561,9 +2561,9 @@ We could not invite users. Please check the users you want to invite and try again. - Scan + SCAN A QR CODE My code - This is your matrix.to code. If you share it with someone they can scan it with their element camera to add you as a contact + This is your QR code. Share it with people so they can scan it to add you and start chatting. Current language Other available languages