mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-08-14 09:13:42 +01:00
+15
-8
@@ -27,7 +27,6 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.provider.Browser
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.text.Editable
|
||||
@@ -57,6 +56,7 @@ import androidx.constraintlayout.widget.ConstraintSet
|
||||
import androidx.core.app.ActivityOptionsCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.doOnPreDraw
|
||||
@@ -129,6 +129,7 @@ import org.signal.core.util.concurrent.LifecycleDisposable
|
||||
import org.signal.core.util.concurrent.ListenableFuture
|
||||
import org.signal.core.util.concurrent.addTo
|
||||
import org.signal.core.util.dp
|
||||
import org.signal.core.util.encourageNewBrowserTab
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.orNull
|
||||
import org.signal.core.util.requireDrawable
|
||||
@@ -898,10 +899,6 @@ class ConversationFragment :
|
||||
}
|
||||
|
||||
override fun startActivity(intent: Intent) {
|
||||
if (intent.getStringArrayExtra(Browser.EXTRA_APPLICATION_ID) != null) {
|
||||
intent.removeExtra(Browser.EXTRA_APPLICATION_ID)
|
||||
}
|
||||
|
||||
try {
|
||||
super.startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
@@ -913,6 +910,10 @@ class ConversationFragment :
|
||||
}
|
||||
}
|
||||
|
||||
private fun openLink(url: String) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, url.toUri()).encourageNewBrowserTab())
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region Fragment callbacks and listeners
|
||||
@@ -3550,8 +3551,8 @@ class ConversationFragment :
|
||||
}
|
||||
|
||||
override fun onLinkPreviewClicked(linkPreview: LinkPreview) {
|
||||
val activity = activity ?: return
|
||||
CommunicationActions.openBrowserLink(activity, linkPreview.url)
|
||||
activity ?: return
|
||||
openLink(linkPreview.url)
|
||||
}
|
||||
|
||||
override fun onQuotedIndicatorClicked(messageRecord: MessageRecord) {
|
||||
@@ -3940,8 +3941,14 @@ class ConversationFragment :
|
||||
override fun onScheduledIndicatorClicked(view: View, conversationMessage: ConversationMessage) = Unit
|
||||
|
||||
override fun onUrlClicked(url: String): Boolean {
|
||||
return CommunicationActions.handlePotentialGroupLinkUrl(requireActivity(), url) ||
|
||||
if (CommunicationActions.handlePotentialGroupLinkUrl(requireActivity(), url) ||
|
||||
CommunicationActions.handlePotentialProxyLinkUrl(requireActivity(), url)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
openLink(url)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onViewGiftBadgeClicked(messageRecord: MessageRecord) {
|
||||
|
||||
@@ -3,6 +3,19 @@ package org.signal.core.util
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Parcelable
|
||||
import android.provider.Browser
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Encourages the browser to open this link in a new tab rather than re-using an existing one. The random application id prevents browsers from
|
||||
* associating this link with a tab we previously opened.
|
||||
*/
|
||||
fun Intent.encourageNewBrowserTab(): Intent {
|
||||
return apply {
|
||||
putExtra(Browser.EXTRA_APPLICATION_ID, UUID.randomUUID().toString())
|
||||
putExtra(Browser.EXTRA_CREATE_NEW_TAB, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Parcelable> Intent.getParcelableExtraCompat(key: String, clazz: Class<T>): T? {
|
||||
return if (Build.VERSION.SDK_INT >= 33) {
|
||||
|
||||
Reference in New Issue
Block a user