Migrating from ContextCompat.startActivity to context.startActivity

This commit is contained in:
Vitor Pamplona
2025-04-24 16:54:17 -04:00
parent 30c4e3c646
commit 5095c9f480
8 changed files with 26 additions and 31 deletions
@@ -79,7 +79,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Popup
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.AddressableNote
@@ -413,7 +412,7 @@ private fun RenderMainPopup(
sendIntent, sendIntent,
stringRes(context, R.string.quick_action_share), stringRes(context, R.string.quick_action_share),
) )
ContextCompat.startActivity(context, shareIntent, null) context.startActivity(shareIntent)
onDismiss() onDismiss()
} }
} }
@@ -587,7 +586,7 @@ private fun RenderDeleteFromGalleryPopup(
sendIntent, sendIntent,
stringRes(context, R.string.quick_action_share), stringRes(context, R.string.quick_action_share),
) )
ContextCompat.startActivity(context, shareIntent, null) context.startActivity(shareIntent)
onDismiss() onDismiss()
} }
} }
@@ -92,7 +92,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties import androidx.compose.ui.window.PopupProperties
import androidx.core.content.ContextCompat
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.commons.emojicoder.EmojiCoder import com.vitorpamplona.amethyst.commons.emojicoder.EmojiCoder
@@ -272,7 +271,7 @@ fun ShareReaction(
sendIntent, sendIntent,
stringRes(context, R.string.quick_action_share), stringRes(context, R.string.quick_action_share),
) )
ContextCompat.startActivity(context, shareIntent, null) context.startActivity(shareIntent)
}, },
) { ) {
ShareIcon(barChartModifier, grayTint) ShareIcon(barChartModifier, grayTint)
@@ -56,7 +56,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
@@ -391,7 +390,7 @@ fun payViaIntent(
val intent = Intent(Intent.ACTION_VIEW, "lightning:$invoice".toUri()) val intent = Intent(Intent.ACTION_VIEW, "lightning:$invoice".toUri())
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
ContextCompat.startActivity(context, intent, null) context.startActivity(intent)
onPaid() onPaid()
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e
@@ -21,7 +21,6 @@
package com.vitorpamplona.amethyst.ui.note.types package com.vitorpamplona.amethyst.ui.note.types
import android.content.Intent import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@@ -48,7 +47,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.net.toUri
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
@@ -213,17 +212,20 @@ fun DisplayFileList(
val context = LocalContext.current val context = LocalContext.current
IconButton(onClick = { IconButton(
onClick = {
try { try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(link())) val intent = Intent(Intent.ACTION_VIEW, link().toUri())
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
ContextCompat.startActivity(context, intent, null) context.startActivity(intent)
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e
accountViewModel.toastManager.toast(R.string.torrent_failure, R.string.torrent_no_apps) accountViewModel.toastManager.toast(R.string.torrent_failure, R.string.torrent_no_apps)
} }
}, Modifier.size(Size30dp)) { },
Modifier.size(Size30dp),
) {
DownloadForOfflineIcon(Size20dp, MaterialTheme.colorScheme.onBackground) DownloadForOfflineIcon(Size20dp, MaterialTheme.colorScheme.onBackground)
} }
} }
@@ -31,7 +31,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.PublicChatChannel import com.vitorpamplona.amethyst.model.PublicChatChannel
@@ -58,7 +57,7 @@ fun LinkChatButton(
val intent = Intent(Intent.ACTION_VIEW, channel.toNostrUri().toUri()) val intent = Intent(Intent.ACTION_VIEW, channel.toNostrUri().toUri())
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
ContextCompat.startActivity(context, intent, null) context.startActivity(intent)
val sendIntent = val sendIntent =
Intent().apply { Intent().apply {
@@ -74,7 +73,7 @@ fun LinkChatButton(
stringRes(context, R.string.quick_action_copy_note_id), stringRes(context, R.string.quick_action_copy_note_id),
) )
ContextCompat.startActivity(context, shareIntent, null) context.startActivity(shareIntent)
}, },
contentPadding = ZeroPadding, contentPadding = ZeroPadding,
) { ) {
@@ -31,7 +31,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.PublicChatChannel import com.vitorpamplona.amethyst.model.PublicChatChannel
@@ -58,7 +57,7 @@ fun OpenChatButton(
val intent = Intent(Intent.ACTION_VIEW, channel.toNostrUri().toUri()) val intent = Intent(Intent.ACTION_VIEW, channel.toNostrUri().toUri())
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
ContextCompat.startActivity(context, intent, null) context.startActivity(intent)
}, },
contentPadding = ZeroPadding, contentPadding = ZeroPadding,
) { ) {
@@ -31,7 +31,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.PublicChatChannel import com.vitorpamplona.amethyst.model.PublicChatChannel
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
@@ -69,7 +68,7 @@ fun ShareChatButton(
stringRes(context, R.string.quick_action_share), stringRes(context, R.string.quick_action_share),
) )
ContextCompat.startActivity(context, shareIntent, null) context.startActivity(shareIntent)
}, },
contentPadding = ZeroPadding, contentPadding = ZeroPadding,
) { ) {
@@ -29,7 +29,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.core.content.ContextCompat
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.note.externalLinkForUser import com.vitorpamplona.amethyst.ui.note.externalLinkForUser
@@ -59,7 +58,7 @@ fun UserProfileDropDownMenu(
}, },
) )
val actContext = LocalContext.current val context = LocalContext.current
DropdownMenuItem( DropdownMenuItem(
text = { Text(stringRes(R.string.quick_action_share)) }, text = { Text(stringRes(R.string.quick_action_share)) },
@@ -74,13 +73,13 @@ fun UserProfileDropDownMenu(
) )
putExtra( putExtra(
Intent.EXTRA_TITLE, Intent.EXTRA_TITLE,
stringRes(actContext, R.string.quick_action_share_browser_link), stringRes(context, R.string.quick_action_share_browser_link),
) )
} }
val shareIntent = val shareIntent =
Intent.createChooser(sendIntent, stringRes(actContext, R.string.quick_action_share)) Intent.createChooser(sendIntent, stringRes(context, R.string.quick_action_share))
ContextCompat.startActivity(actContext, shareIntent, null) context.startActivity(shareIntent)
onDismiss() onDismiss()
}, },
) )