Refact move utility method open settings

This commit is contained in:
Valere 2020-11-20 13:24:32 +01:00
parent 6146925757
commit fd92d6559c
4 changed files with 21 additions and 31 deletions

View File

@ -29,6 +29,7 @@ import android.os.Build
import android.os.Environment import android.os.Environment
import android.provider.Browser import android.provider.Browser
import android.provider.MediaStore import android.provider.MediaStore
import android.provider.Settings
import android.webkit.MimeTypeMap import android.webkit.MimeTypeMap
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher 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 * Ask the user to select a location and a file name to write in
*/ */

View File

@ -19,11 +19,8 @@ package im.vector.app.core.utils
import android.Manifest import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build import android.os.Build
import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
@ -34,7 +31,6 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.platform.VectorBaseActivity
import org.matrix.android.sdk.api.extensions.tryOrNull
import timber.log.Timber import timber.log.Timber
// Android M permission request code management // Android M permission request code management
@ -291,14 +287,7 @@ private fun checkPermissions(permissionsToBeGrantedBitMap: Int,
fun VectorBaseActivity.onPermissionDeniedSnackbar(@StringRes rationaleMessage: Int) { fun VectorBaseActivity.onPermissionDeniedSnackbar(@StringRes rationaleMessage: Int) {
showSnackbar(getString(rationaleMessage), R.string.settings) { showSnackbar(getString(rationaleMessage), R.string.settings) {
tryOrNull { openAppSettingsPage(this)
startActivity(
Intent().apply {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
data = Uri.fromParts("package", this@onPermissionDeniedSnackbar.packageName, null)
})
}
} }
} }

View File

@ -16,15 +16,13 @@
package im.vector.app.features.settings package im.vector.app.features.settings
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.preference.Preference import androidx.preference.Preference
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.preference.VectorPreference import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.utils.copyToClipboard import im.vector.app.core.utils.copyToClipboard
import im.vector.app.core.utils.displayInWebView 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.core.utils.openUrlInChromeCustomTab
import im.vector.app.features.version.VersionProvider import im.vector.app.features.version.VersionProvider
import im.vector.app.openOssLicensesMenuActivity 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 // preference to start the App info screen, to facilitate App permissions access
findPreference<VectorPreference>(APP_INFO_LINK_PREFERENCE_KEY)!! findPreference<VectorPreference>(APP_INFO_LINK_PREFERENCE_KEY)!!
.onPreferenceClickListener = Preference.OnPreferenceClickListener { .onPreferenceClickListener = Preference.OnPreferenceClickListener {
activity?.let { activity?.let { openAppSettingsPage(it) }
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)
}
true true
} }

View File

@ -425,8 +425,8 @@
<string name="permissions_msg_contacts_warning_other_androids">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?</string> <string name="permissions_msg_contacts_warning_other_androids">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?</string>
<string name="permissions_action_not_performed_missing_permissions">Sorry. Action not performed, due to missing permissions</string> <string name="permissions_action_not_performed_missing_permissions">Sorry. Action not performed, due to missing permissions</string>
<string name="permissions_denied_qr_code">To scan a QR code, allow Camera permission to take a picture</string> <string name="permissions_denied_qr_code">To scan a QR code, you need to allow camera access.</string>
<string name="permissions_denied_add_contact">To check your address book, allow Contact permission.</string> <string name="permissions_denied_add_contact">To check your address book, you need to allow Contact permission.</string>
<!-- medias slider string --> <!-- medias slider string -->
<string name="media_slider_saved">Saved</string> <string name="media_slider_saved">Saved</string>
@ -2561,9 +2561,9 @@
</plurals> </plurals>
<string name="invite_users_to_room_failure">We could not invite users. Please check the users you want to invite and try again.</string> <string name="invite_users_to_room_failure">We could not invite users. Please check the users you want to invite and try again.</string>
<string name="user_code_scan">Scan</string> <string name="user_code_scan">SCAN A QR CODE</string>
<string name="user_code_my_code">My code</string> <string name="user_code_my_code">My code</string>
<string name="user_code_info_text">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</string> <string name="user_code_info_text">This is your QR code. Share it with people so they can scan it to add you and start chatting.</string>
<string name="choose_locale_current_locale_title">Current language</string> <string name="choose_locale_current_locale_title">Current language</string>
<string name="choose_locale_other_locales_title">Other available languages</string> <string name="choose_locale_other_locales_title">Other available languages</string>