2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] No issue: Show snackbar when opening non-http URL

This commit is contained in:
Roger Yang 2021-11-02 16:03:52 -04:00 committed by mergify[bot]
parent 5e2853ea47
commit 3ffe906bcb
2 changed files with 42 additions and 22 deletions

View File

@ -31,6 +31,7 @@ import androidx.constraintlayout.widget.ConstraintProperties.BOTTOM
import androidx.constraintlayout.widget.ConstraintProperties.PARENT_ID
import androidx.constraintlayout.widget.ConstraintProperties.TOP
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.net.toUri
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
@ -51,7 +52,9 @@ import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.content.hasCamera
import mozilla.components.support.ktx.android.content.isPermissionGranted
import mozilla.components.support.ktx.android.content.res.getSpanned
import mozilla.components.support.ktx.android.net.isHttpOrHttps
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import mozilla.components.ui.autocomplete.InlineAutocompleteEditText
@ -503,29 +506,42 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS)
},
onScanResult = { result ->
binding.qrScanButton.isChecked = false
activity?.let {
AlertDialog.Builder(it).apply {
val spannable = resources.getSpanned(
R.string.qr_scanner_confirmation_dialog_message,
getString(R.string.app_name) to StyleSpan(Typeface.BOLD),
result to StyleSpan(Typeface.ITALIC)
)
setMessage(spannable)
setNegativeButton(R.string.qr_scanner_dialog_negative) { dialog: DialogInterface, _ ->
dialog.cancel()
}
setPositiveButton(R.string.qr_scanner_dialog_positive) { dialog: DialogInterface, _ ->
(activity as? HomeActivity)?.openToBrowserAndLoad(
searchTermOrURL = result,
newTab = store.state.tabId == null,
from = BrowserDirection.FromSearchDialog,
flags = EngineSession.LoadUrlFlags.external()
val normalizedUrl = result.toNormalizedUrl()
if (!normalizedUrl.toUri().isHttpOrHttps) {
activity?.let {
AlertDialog.Builder(it).apply {
setMessage(R.string.qr_scanner_dialog_invalid)
setPositiveButton(R.string.qr_scanner_dialog_invalid_ok) { dialog: DialogInterface, _ ->
dialog.dismiss()
}
create()
}.show()
}
} else {
binding.qrScanButton.isChecked = false
activity?.let {
AlertDialog.Builder(it).apply {
val spannable = resources.getSpanned(
R.string.qr_scanner_confirmation_dialog_message,
getString(R.string.app_name) to StyleSpan(Typeface.BOLD),
normalizedUrl to StyleSpan(Typeface.ITALIC)
)
dialog.dismiss()
}
create()
}.show()
setMessage(spannable)
setNegativeButton(R.string.qr_scanner_dialog_negative) { dialog: DialogInterface, _ ->
dialog.cancel()
}
setPositiveButton(R.string.qr_scanner_dialog_positive) { dialog: DialogInterface, _ ->
(activity as? HomeActivity)?.openToBrowserAndLoad(
searchTermOrURL = normalizedUrl,
newTab = store.state.tabId == null,
from = BrowserDirection.FromSearchDialog,
flags = EngineSession.LoadUrlFlags.external()
)
dialog.dismiss()
}
create()
}.show()
}
}
}
)

View File

@ -1212,6 +1212,10 @@
<string name="qr_scanner_dialog_positive">ALLOW</string>
<!-- QR code scanner prompt dialog positive option to deny navigation to scanned link -->
<string name="qr_scanner_dialog_negative">DENY</string>
<!-- QR code scanner prompt dialog error message shown when a hostname does not contain http or https. -->
<string name="qr_scanner_dialog_invalid">Web address not valid.</string>
<!-- QR code scanner prompt dialog positive option when there is an error -->
<string name="qr_scanner_dialog_invalid_ok">OK</string>
<!-- Tab collection deletion prompt dialog message. Placeholder will be replaced with the collection name -->
<string name="tab_collection_dialog_message">Are you sure you want to delete %1$s?</string>
<!-- Collection and tab deletion prompt dialog message. This will show when the last tab from a collection is deleted -->