Skip to content

Commit dd0ef93

Browse files
committed
update to use share sheet when sharing article
1 parent 92e3698 commit dd0ef93

3 files changed

Lines changed: 18 additions & 46 deletions

File tree

app/src/main/java/dev/dimension/flare/ui/screen/article/ArticleScreen.kt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.dimension.flare.ui.screen.article
22

33
import android.content.Context
4-
import android.content.Intent
54
import android.widget.Toast
65
import androidx.compose.foundation.background
76
import androidx.compose.foundation.clickable
@@ -257,8 +256,14 @@ internal fun ArticleScreen(
257256
IconButton(
258257
enabled = sourceUrl != null,
259258
onClick = {
260-
article?.let {
261-
shareArticle(context, it)
259+
sourceUrl?.let {
260+
navigate(
261+
Route.Status.ShareSheet(
262+
statusKey = articleKey,
263+
accountType = accountType,
264+
shareUrl = it,
265+
),
266+
)
262267
}
263268
},
264269
) {
@@ -1054,22 +1059,3 @@ private fun Context.showArticleDownloadToast(messageRes: Int) {
10541059
.makeText(this, getString(messageRes), Toast.LENGTH_SHORT)
10551060
.show()
10561061
}
1057-
1058-
private fun shareArticle(
1059-
context: Context,
1060-
article: UiArticle,
1061-
) {
1062-
val url = article.sourceUrl?.takeIf { it.isNotBlank() } ?: return
1063-
val title = article.title.takeIf { it.isNotBlank() }
1064-
val sendIntent =
1065-
Intent().apply {
1066-
action = Intent.ACTION_SEND
1067-
title?.let {
1068-
putExtra(Intent.EXTRA_TITLE, it)
1069-
putExtra(Intent.EXTRA_SUBJECT, it)
1070-
}
1071-
putExtra(Intent.EXTRA_TEXT, url)
1072-
type = "text/plain"
1073-
}
1074-
context.startActivity(Intent.createChooser(sendIntent, title))
1075-
}

desktopApp/src/main/kotlin/dev/dimension/flare/ui/screen/article/ArticleScreen.kt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ import dev.dimension.flare.article_content_gate_subscription_description
5252
import dev.dimension.flare.article_content_gate_subscription_description_with_fee
5353
import dev.dimension.flare.article_content_gate_subscription_title
5454
import dev.dimension.flare.common.DesktopDownloadManager
55-
import dev.dimension.flare.copied_to_clipboard
5655
import dev.dimension.flare.media_save
5756
import dev.dimension.flare.model.AccountType
5857
import dev.dimension.flare.model.MicroBlogKey
5958
import dev.dimension.flare.rss_detail_open_in_browser
6059
import dev.dimension.flare.status_share
61-
import dev.dimension.flare.ui.component.ComposeInAppNotification
6260
import dev.dimension.flare.ui.component.DateTimeText
6361
import dev.dimension.flare.ui.component.ErrorContent
6462
import dev.dimension.flare.ui.component.FAIcon
@@ -96,8 +94,6 @@ import moe.tlaster.precompose.molecule.producePresenter
9694
import org.jetbrains.compose.resources.stringResource
9795
import org.koin.compose.koinInject
9896
import java.awt.FileDialog
99-
import java.awt.Toolkit
100-
import java.awt.datatransfer.StringSelection
10197
import java.io.File
10298

10399
private val ArticleCoverHeight = 260.dp
@@ -125,7 +121,6 @@ internal fun ArticleScreen(
125121
val scope = rememberCoroutineScope()
126122
val window = LocalComposeWindow.current
127123
val downloadManager: DesktopDownloadManager = koinInject()
128-
val inAppNotification: ComposeInAppNotification = koinInject()
129124
val article = state.article.takeSuccess()
130125
val windowPadding = LocalWindowPadding.current
131126
val contentPadding =
@@ -160,8 +155,13 @@ internal fun ArticleScreen(
160155
article = currentArticle,
161156
onOpenUrl = uriHandler::openUri,
162157
onShare = {
163-
shareArticleText(it)
164-
inAppNotification.message(Res.string.copied_to_clipboard)
158+
navigate(
159+
Route.StatusShareSheet(
160+
accountType = accountType,
161+
statusKey = articleKey,
162+
shareUrl = sourceUrl,
163+
),
164+
)
165165
},
166166
)
167167
}
@@ -881,14 +881,3 @@ private fun UiMedia.Image.rawImageRoute(): Route.RawImage =
881881
rawImage = url,
882882
customHeaders = customHeaders,
883883
)
884-
885-
private fun shareArticleText(article: UiArticle) {
886-
val url = article.sourceUrl?.takeIf { it.isNotBlank() } ?: return
887-
val text =
888-
if (article.title.isBlank()) {
889-
url
890-
} else {
891-
"${article.title}\n$url"
892-
}
893-
Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(text), null)
894-
}

iosApp/flare/UI/Screen/ArticleScreen.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ struct ArticleScreen: View {
5353
.accessibilityLabel(Text("Open in Browser"))
5454
}
5555
ToolbarItem {
56-
ShareLink(
57-
item: sourceURL,
58-
subject: Text(article.title),
59-
message: Text(article.title),
60-
preview: SharePreview(article.title)
61-
) {
56+
Button {
57+
onNavigate(.statusShareSheet(accountType, articleKey, sourceURL.absoluteString, nil, nil))
58+
} label: {
6259
Image(.faShareNodes)
6360
}
6461
.accessibilityLabel(Text("Share"))

0 commit comments

Comments
 (0)