Skip to content

Commit

Permalink
SS-75 Prevent 'Are you sure you want to open this URL?' dialog from b…
Browse files Browse the repository at this point in the history
…eing excessively tall when given a very long URL
  • Loading branch information
alansley committed Aug 21, 2024
1 parent b7f627f commit 59b4805
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,27 @@ class SessionDialogBuilder(val context: Context) {
.apply { orientation = VERTICAL }
.also(dialogBuilder::setCustomTitle)

val contentView = LinearLayout(context).apply { orientation = VERTICAL }
// Maximum height of the dialog. This comes into play in the Open URL dialog where we
// might have a a very, very long URL (which we provide a ScrollView for) - but without
// limiting the height of the dialog, the WRAP_CONTENT part can allow the dialog to be
// super tall!
// Note: I eye-balled this DP value for the max dialog height to make it match the
// height of regular not-scrollable dialogs.
val maxHeightInDp = 137
val scale = context.resources.displayMetrics.density
val maxHeightInPx = (maxHeightInDp * scale + 0.5f).toInt()

val contentView = LinearLayout(context).apply {
orientation = VERTICAL

// Limit the max height of the dialog to the above value
viewTreeObserver.addOnGlobalLayoutListener {
if (height > maxHeightInPx) {
layoutParams.height = maxHeightInPx
requestLayout()
}
}
}

private val buttonLayout = LinearLayout(context)

Expand Down Expand Up @@ -180,7 +200,10 @@ public fun Context.copyURLToClipboard(url: String) {

// Method to show a dialog used to open or copy a URL
fun Context.showOpenUrlDialog(url: String, showCloseButton: Boolean = true): AlertDialog {

return SessionDialogBuilder(this).apply {


// If we're not showing a close button we can just use a simple title..
if (!showCloseButton) {
title(R.string.urlOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() {

val delayStepMilliseconds = when (toastLengthSetting) {
Toast.LENGTH_SHORT -> 2000L
Toast.LENGTH_LONG -> 3500L
Toast.LENGTH_LONG -> 3500L
else -> {
Log.w("BlockContactsActivity", "Invalid toast length setting - using Toast.LENGTH_SHORT")
2000L
Expand Down

0 comments on commit 59b4805

Please sign in to comment.