diff --git a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt index 171a2a7049..006d2e630d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/SessionDialogBuilder.kt @@ -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 @@ -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 @@ -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() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsNavHost.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsNavHost.kt index 8af681b86c..771dfd29dd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsNavHost.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsNavHost.kt @@ -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 @@ -129,7 +130,7 @@ fun ConversationSettingsNavHost( NavigationAction.NavigateUp -> handleBack() is NavigationAction.NavigateToIntent -> { - navController.context.startActivity(action.intent) + navController.handleIntent(action.intent) } is NavigationAction.ReturnResult -> { diff --git a/app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenuNavHost.kt b/app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenuNavHost.kt index 491418be66..cc4cece795 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenuNavHost.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenuNavHost.kt @@ -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 @@ -63,7 +64,7 @@ fun DebugMenuNavHost( NavigationAction.NavigateUp -> handleBack() is NavigationAction.NavigateToIntent -> { - navController.context.startActivity(action.intent) + navController.handleIntent(action.intent) } else -> {} diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt index 5b33f83d38..82f4623fba 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt @@ -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 @@ -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() @@ -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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/startconversation/StartConversationSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/home/startconversation/StartConversationSheet.kt index e19cb6de74..fd1737a3a9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/startconversation/StartConversationSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/startconversation/StartConversationSheet.kt @@ -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 @@ -126,7 +126,7 @@ fun StartConversationNavHost( NavigationAction.NavigateUp -> navController.navigateUp() is NavigationAction.NavigateToIntent -> { - navController.context.startActivity(action.intent) + navController.handleIntent(action.intent) } else -> {} diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/LandingActivity.kt index dcee8a0da5..fd1d74664c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/LandingActivity.kt @@ -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) - } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt index 87d0b46fd6..dbdb9c0d1b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt @@ -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() { @@ -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) @@ -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() - } - } - } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsDialogs.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsDialogs.kt index d790d1e945..ef4458ad16 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsDialogs.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsDialogs.kt @@ -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( diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsNavHost.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsNavHost.kt index 9252199ff7..33fe94fe89 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsNavHost.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsNavHost.kt @@ -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 @@ -89,7 +90,7 @@ fun ProSettingsNavHost( NavigationAction.NavigateUp -> handleBack() is NavigationAction.NavigateToIntent -> { - navController.context.startActivity(action.intent) + navController.handleIntent(action.intent) } is NavigationAction.PerformCustomAction -> { diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt index 99e8af2de3..cb2be5960b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt @@ -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 @@ -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( @@ -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( diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/UINavigator.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/UINavigator.kt index 8aa4c05bc3..bc4c0330b0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/UINavigator.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/UINavigator.kt @@ -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 @@ -47,6 +50,21 @@ class UINavigator () { } } +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 { data class Navigate( val destination: T, diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt index b987c831a0..95da4c7df5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Util.kt @@ -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 @@ -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) { @@ -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 versions of this or the `getSubbedString` method because the JVM sees the signatures as identical. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db363a5f9a..a4e8bb6015 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,6 +58,7 @@ You cannot change your admin status. To leave the group, open the conversation settings and select Leave Group. {name} and {other_name} were promoted to Admin. Admins + Allow +{count} Anonymous App Icon @@ -174,6 +175,7 @@ Are you sure you want to unblock {name} and 1 other? Unblocked {name} View and manage blocked contacts. + No browser found to open that URL, try copying the URL instead Call {name} called you You cannot start a new call. Finish your current call first. @@ -220,6 +222,7 @@ Change Failed to change password Change your password for {app_name}. Locally stored data will be re-encrypted with your new password. + Change Setting Checking {pro} Status Checking your {pro} status. You\'ll be able to continue once this check is complete. Checking your {pro} details. Some actions on this page may be unavailable until this check is complete. @@ -410,6 +413,7 @@ Are you sure you want to delete these messages for everyone? Deleting Toggle Developer Tools + Device Notification Settings Start Dictation... Disappearing Messages Message will delete in {time_large} @@ -683,6 +687,8 @@ You and {other_name} joined the group. {name} and {other_name} joined the group. You joined the group. + Limit Background Activity? + You currently allow {app_name} to run in the background to improve notification reliability. Changing this setting could result in less reliable notifications. Link Previews Show link previews for supported URLs. Enable Link Previews @@ -1256,6 +1262,9 @@ Retry Review Limit It looks like you\'ve already reviewed {app_name} recently, thanks for your feedback! + Run App in the Background + Run {app_name} in the Background? + 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. Save Saved Saved messages