mirror of
				https://github.com/oxen-io/session-android.git
				synced 2025-10-30 23:09:20 +00:00 
			
		
		
		
	SS-75 Prevent 'Are you sure you want to open this URL?' dialog from being excessively tall when given a very long URL
This commit is contained in:
		| @@ -56,7 +56,27 @@ class SessionDialogBuilder(val context: Context) { | |||||||
|         .apply { orientation = VERTICAL } |         .apply { orientation = VERTICAL } | ||||||
|         .also(dialogBuilder::setCustomTitle) |         .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) |     private val buttonLayout = LinearLayout(context) | ||||||
|  |  | ||||||
| @@ -180,7 +200,10 @@ public fun Context.copyURLToClipboard(url: String) { | |||||||
|  |  | ||||||
| // Method to show a dialog used to open or copy a URL | // Method to show a dialog used to open or copy a URL | ||||||
| fun Context.showOpenUrlDialog(url: String, showCloseButton: Boolean = true): AlertDialog { | fun Context.showOpenUrlDialog(url: String, showCloseButton: Boolean = true): AlertDialog { | ||||||
|  |  | ||||||
|     return SessionDialogBuilder(this).apply { |     return SessionDialogBuilder(this).apply { | ||||||
|  |  | ||||||
|  |  | ||||||
|         // If we're not showing a close button we can just use a simple title.. |         // If we're not showing a close button we can just use a simple title.. | ||||||
|         if (!showCloseButton) { |         if (!showCloseButton) { | ||||||
|             title(R.string.urlOpen) |             title(R.string.urlOpen) | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() { | |||||||
|  |  | ||||||
|         val delayStepMilliseconds = when (toastLengthSetting) { |         val delayStepMilliseconds = when (toastLengthSetting) { | ||||||
|             Toast.LENGTH_SHORT -> 2000L |             Toast.LENGTH_SHORT -> 2000L | ||||||
|             Toast.LENGTH_LONG -> 3500L |             Toast.LENGTH_LONG  -> 3500L | ||||||
|             else -> { |             else -> { | ||||||
|                 Log.w("BlockContactsActivity", "Invalid toast length setting - using Toast.LENGTH_SHORT") |                 Log.w("BlockContactsActivity", "Invalid toast length setting - using Toast.LENGTH_SHORT") | ||||||
|                 2000L |                 2000L | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 alansley
					alansley