Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package org.thoughtcrime.securesms
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
Expand All @@ -15,9 +13,7 @@ import android.widget.LinearLayout
import android.widget.LinearLayout.VERTICAL
import android.widget.Space
import android.widget.TextView
import androidx.annotation.AttrRes
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
Expand Down Expand Up @@ -195,9 +191,6 @@ public fun Context.copyURLToClipboard(url: String) {
clipboard.setPrimaryClip(clip)
}

// Method to actually open a given URL via an Intent that will use the default browser
fun Context.openUrl(url: String) = Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity)

fun Fragment.showSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
SessionDialogBuilder(requireContext()).apply { build() }.show()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.thoughtcrime.securesms.media.MediaOverviewViewModel
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable

// Destinations
Expand Down Expand Up @@ -129,7 +130,7 @@ fun ConversationSettingsNavHost(
NavigationAction.NavigateUp -> handleBack()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

is NavigationAction.ReturnResult -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.serialization.Serializable
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable

// Destinations
Expand Down Expand Up @@ -63,7 +64,7 @@ fun DebugMenuNavHost(
NavigationAction.NavigateUp -> handleBack()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

else -> {}
Expand Down
17 changes: 4 additions & 13 deletions app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.ScreenLockActionBarActivity
import org.thoughtcrime.securesms.reviews.InAppReviewManager
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.openUrl
import org.thoughtcrime.securesms.util.GlowViewUtilities
import org.thoughtcrime.securesms.util.IP2Country
import org.thoughtcrime.securesms.util.PathDotView
Expand Down Expand Up @@ -71,7 +72,9 @@ class PathActivity : ScreenLockActionBarActivity() {
binding.pathDescription.text = txt

binding.pathRowsContainer.disableClipping()
binding.learnMoreButton.setOnClickListener { learnMore() }
binding.learnMoreButton.setOnClickListener {
openUrl("https://getsession.org/faq/#onion-routing")
}
update(false)
registerObservers()

Expand Down Expand Up @@ -199,18 +202,6 @@ class PathActivity : ScreenLockActionBarActivity() {
}
// endregion

// region Interaction
private fun learnMore() {
try {
val url = "https://getsession.org/faq/#onion-routing"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(this, R.string.communityEnterUrlErrorInvalid, Toast.LENGTH_SHORT).show()
}
}
// endregion

// region Line View
private class LineView : RelativeLayout {
private lateinit var location: Location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import org.thoughtcrime.securesms.home.startconversation.invitefriend.InviteFrie
import org.thoughtcrime.securesms.home.startconversation.newmessage.NewMessage
import org.thoughtcrime.securesms.home.startconversation.newmessage.NewMessageViewModel
import org.thoughtcrime.securesms.home.startconversation.newmessage.State
import org.thoughtcrime.securesms.openUrl
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.OpenURLAlertDialog
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.components.BaseBottomSheet
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable
import org.thoughtcrime.securesms.ui.theme.PreviewTheme

Expand Down Expand Up @@ -126,7 +126,7 @@ fun StartConversationNavHost(
NavigationAction.NavigateUp -> navController.navigateUp()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ class LandingActivity: BaseActionBarActivity() {
// AC: This is a temporary workaround to trick the old code that the screen is unlocked.
KeyCachingService.setMasterSecret(applicationContext, Object())
}

private fun open(url: String) {
Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.ScreenLockActionBarActivity
import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.openUrl

@AndroidEntryPoint
class HelpSettingsActivity: ScreenLockActionBarActivity() {
Expand Down Expand Up @@ -68,19 +69,19 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
true
}
TRANSLATE -> {
openLink(CROWDIN_URL)
requireContext().openUrl(CROWDIN_URL)
true
}
FEEDBACK -> {
openLink(FEEDBACK_URL)
requireContext().openUrl(FEEDBACK_URL)
true
}
FAQ -> {
openLink(FAQ_URL)
requireContext().openUrl(FAQ_URL)
true
}
SUPPORT -> {
openLink(SUPPORT_URL)
requireContext().openUrl(SUPPORT_URL)
true
}
else -> super.onPreferenceTreeClick(preference)
Expand Down Expand Up @@ -115,14 +116,4 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
}
.execute()
}

private fun openLink(url: String) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(requireActivity(), requireContext().getString(R.string.errorUnknown), Toast.LENGTH_LONG).show()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
package org.thoughtcrime.securesms.preferences.prosettings

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import network.loki.messenger.R
import org.thoughtcrime.securesms.openUrl
import org.thoughtcrime.securesms.preferences.prosettings.ProSettingsViewModel.Commands.HideSimpleDialog
import org.thoughtcrime.securesms.preferences.prosettings.ProSettingsViewModel.Commands.HideTCPolicyDialog
import org.thoughtcrime.securesms.preferences.prosettings.ProSettingsViewModel.Commands.ShowOpenUrlDialog
import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.Cell
import org.thoughtcrime.securesms.ui.DialogButtonData
import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.GetString
import org.thoughtcrime.securesms.ui.IconActionRowItem
import org.thoughtcrime.securesms.ui.OpenURLAlertDialog
import org.thoughtcrime.securesms.ui.TCPolicyDialog
import org.thoughtcrime.securesms.ui.components.annotatedStringResource
import org.thoughtcrime.securesms.ui.theme.LocalColors
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.ui.theme.LocalType
import org.thoughtcrime.securesms.ui.theme.PreviewTheme
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.theme.ThemeColors
import org.thoughtcrime.securesms.ui.theme.bold

@Composable
fun ProSettingsDialogs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.preferences.prosettings.chooseplan.ChoosePlanH
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable

// Destinations
Expand Down Expand Up @@ -89,7 +90,7 @@ fun ProSettingsNavHost(
NavigationAction.NavigateUp -> handleBack()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

is NavigationAction.PerformCustomAction -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import com.squareup.phrase.Phrase
import network.loki.messenger.R
import org.session.libsession.utilities.StringSubstitutionConstants.URL_KEY
import org.thoughtcrime.securesms.copyURLToClipboard
import org.thoughtcrime.securesms.openUrl
import org.thoughtcrime.securesms.ui.components.CircularProgressIndicator
import org.thoughtcrime.securesms.ui.components.annotatedStringResource
import org.thoughtcrime.securesms.ui.theme.LocalColors
Expand All @@ -55,7 +54,6 @@ import org.thoughtcrime.securesms.ui.theme.LocalType
import org.thoughtcrime.securesms.ui.theme.PreviewTheme
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.theme.ThemeColors
import org.thoughtcrime.securesms.ui.theme.blackAlpha40
import org.thoughtcrime.securesms.ui.theme.bold

data class DialogButtonData(
Expand Down Expand Up @@ -282,9 +280,12 @@ fun OpenURLAlertDialog(
DialogButtonData(
text = GetString(R.string.open),
color = LocalColors.current.danger,
dismissOnClick = false,
onClick = {
onLinkOpened(url)
context.openUrl(url)
if(context.openUrl(url)){
onLinkOpened(url)
onDismissRequest()
}
}
),
DialogButtonData(
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/org/thoughtcrime/securesms/ui/UINavigator.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.thoughtcrime.securesms.ui

import android.content.Intent
import android.widget.Toast
import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import network.loki.messenger.R
import org.session.libsignal.utilities.Log
import javax.inject.Inject

Expand Down Expand Up @@ -47,6 +50,21 @@ class UINavigator<T> () {
}
}

fun NavController.handleIntent(intent: Intent){
try {
context.startActivity(intent)
} catch (e: Exception) {
val isWebUrl = intent.action == Intent.ACTION_VIEW &&
intent.data != null &&
(intent.data?.scheme == "http" || intent.data?.scheme == "https")

if(isWebUrl) {
Toast.makeText(context, R.string.browserNotFound, Toast.LENGTH_LONG).show()
Log.w("Dialog", "No browser found to open link", e)
}
}
}

sealed interface NavigationAction<out T> {
data class Navigate<T>(
val destination: T,
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package org.thoughtcrime.securesms.ui
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.net.Uri
import android.view.View
import android.view.ViewTreeObserver
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.core.FiniteAnimationSpec
Expand All @@ -24,6 +27,8 @@ import com.squareup.phrase.Phrase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
import network.loki.messenger.R
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme

fun Activity.setComposeContent(content: @Composable () -> Unit) {
Expand All @@ -37,6 +42,23 @@ fun Context.createThemedComposeView(content: @Composable () -> Unit): ComposeVie
setThemedContent(content)
}

// Method to actually open a given URL via an Intent that will use the default browser
/**
* Returns false if the phone was unable to open the link
* Returns true otherwise
*/
fun Context.openUrl(url: String): Boolean {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
return true
} catch (e: Exception) {
Toast.makeText(this, R.string.browserNotFound, Toast.LENGTH_LONG).show()
Log.w("Dialog", "No browser found to open link", e)
}

return false
}

// Extension method to use the Phrase library to substitute strings & return a CharSequence.
// The pair is the key name, such as APP_NAME_KEY and the value is the localised string, such as context.getString(R.string.app_name).
// Note: We cannot have Pair<String, Int> versions of this or the `getSubbedString` method because the JVM sees the signatures as identical.
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="adminStatusYou">You cannot change your admin status. To leave the group, open the conversation settings and select Leave Group.</string>
<string name="adminTwoPromotedToAdmin"><b>{name}</b> and <b>{other_name}</b> were promoted to Admin.</string>
<string name="admins">Admins</string>
<string name="allow">Allow</string>
<string name="andMore">+{count}</string>
<string name="anonymous">Anonymous</string>
<string name="appIcon">App Icon</string>
Expand Down Expand Up @@ -174,6 +175,7 @@
<string name="blockUnblockNameTwo">Are you sure you want to unblock <b>{name}</b> and 1 other?</string>
<string name="blockUnblockedUser">Unblocked {name}</string>
<string name="blockedContactsManageDescription">View and manage blocked contacts.</string>
<string name="browserNotFound">No browser found to open that URL, try copying the URL instead</string>
<string name="call">Call</string>
<string name="callsCalledYou">{name} called you</string>
<string name="callsCannotStart">You cannot start a new call. Finish your current call first.</string>
Expand Down Expand Up @@ -220,6 +222,7 @@
<string name="change">Change</string>
<string name="changePasswordFail">Failed to change password</string>
<string name="changePasswordModalDescription">Change your password for {app_name}. Locally stored data will be re-encrypted with your new password.</string>
<string name="changeSetting">Change Setting</string>
<string name="checkingProStatus">Checking {pro} Status</string>
<string name="checkingProStatusContinue">Checking your {pro} status. You\'ll be able to continue once this check is complete.</string>
<string name="checkingProStatusDescription">Checking your {pro} details. Some actions on this page may be unavailable until this check is complete.</string>
Expand Down Expand Up @@ -410,6 +413,7 @@
<string name="deleteMessagesDescriptionEveryone">Are you sure you want to delete these messages for everyone?</string>
<string name="deleting">Deleting</string>
<string name="developerToolsToggle">Toggle Developer Tools</string>
<string name="deviceNotificationSettings">Device Notification Settings</string>
<string name="dictationStart">Start Dictation...</string>
<string name="disappearingMessages">Disappearing Messages</string>
<string name="disappearingMessagesCountdownBig">Message will delete in {time_large}</string>
Expand Down Expand Up @@ -683,6 +687,8 @@
<string name="legacyGroupMemberNewYouOther"><b>You</b> and <b>{other_name}</b> joined the group.</string>
<string name="legacyGroupMemberTwoNew"><b>{name}</b> and <b>{other_name}</b> joined the group.</string>
<string name="legacyGroupMemberYouNew"><b>You</b> joined the group.</string>
<string name="limitBackgroundActivity">Limit Background Activity?</string>
<string name="limitBackgroundActivityDescription">You currently allow {app_name} to run in the background to improve notification reliability. Changing this setting could result in less reliable notifications.</string>
<string name="linkPreviews">Link Previews</string>
<string name="linkPreviewsDescription">Show link previews for supported URLs.</string>
<string name="linkPreviewsEnable">Enable Link Previews</string>
Expand Down Expand Up @@ -1256,6 +1262,9 @@
<string name="retry">Retry</string>
<string name="reviewLimit">Review Limit</string>
<string name="reviewLimitDescription">It looks like you\'ve already reviewed {app_name} recently, thanks for your feedback!</string>
<string name="runAppBackground">Run App in the Background</string>
<string name="runSessionBackground">Run {app_name} in the Background?</string>
<string name="runSessionBackgroundDescription">Since you’re using slow mode, we recommend allowing {app_name} to run in the background to improve notifications. This can improve notification consistency, although your system may still automatically limit background activity.\n\nYou can change this later in Settings.</string>
<string name="save">Save</string>
<string name="saved">Saved</string>
<string name="savedMessages">Saved messages</string>
Expand Down