Skip to content

Commit 8d7f61f

Browse files
Allow user to share podcast/episode Url (#96)
* Allow user to share podcast/episode url * Use more meaningful parameter names
1 parent 6be4299 commit 8d7f61f

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

app/src/main/kotlin/com/mr3y/podcaster/ui/screens/EpisodeDetailsScreen.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import com.mr3y.podcaster.ui.theme.isAppThemeDark
7676
import com.mr3y.podcaster.ui.theme.onPrimaryTertiary
7777
import com.mr3y.podcaster.ui.theme.primaryTertiary
7878
import com.mr3y.podcaster.ui.theme.setStatusBarAppearanceLight
79+
import com.mr3y.podcaster.ui.utils.TopBarMoreOptionsButton
7980
import com.mr3y.podcaster.ui.utils.dateSharedTransitionKey
8081
import com.mr3y.podcaster.ui.utils.rememberFormattedEpisodeDate
8182

@@ -183,6 +184,14 @@ fun EpisodeDetailsScreen(
183184
containerColor = MaterialTheme.colorScheme.surface,
184185
navigationIconContentColor = MaterialTheme.colorScheme.onSurface,
185186
),
187+
actions = {
188+
if (state.episode != null && !state.isLoading) {
189+
TopBarMoreOptionsButton(
190+
shareActionTitle = state.episode.title,
191+
shareActionText = state.episode.episodeUrl
192+
)
193+
}
194+
},
186195
modifier = Modifier
187196
.renderInSharedTransitionScopeOverlay(
188197
LocalSharedTransitionScope.current,

app/src/main/kotlin/com/mr3y/podcaster/ui/screens/PodcastDetailsScreen.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import com.mr3y.podcaster.ui.theme.onPrimaryTertiaryContainer
118118
import com.mr3y.podcaster.ui.theme.primaryTertiary
119119
import com.mr3y.podcaster.ui.theme.primaryTertiaryContainer
120120
import com.mr3y.podcaster.ui.theme.setStatusBarAppearanceLight
121+
import com.mr3y.podcaster.ui.utils.TopBarMoreOptionsButton
121122

122123
@Composable
123124
fun PodcastDetailsScreen(
@@ -247,6 +248,18 @@ fun PodcastDetailsScreen(
247248
dominantColorState.onColor
248249
},
249250
),
251+
actions = {
252+
if (state.podcast != null && !state.isPodcastLoading) {
253+
TopBarMoreOptionsButton(
254+
shareActionTitle = state.podcast.title,
255+
shareActionText = state.podcast.website,
256+
colors = IconButtonDefaults.iconButtonColors(
257+
containerColor = Color.Transparent,
258+
contentColor = dominantColorState.onColor,
259+
)
260+
)
261+
}
262+
},
250263
modifier = Modifier
251264
.renderInSharedTransitionScopeOverlay(
252265
LocalSharedTransitionScope.current,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.mr3y.podcaster.ui.utils
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import androidx.compose.material.icons.Icons
6+
import androidx.compose.material.icons.filled.MoreVert
7+
import androidx.compose.material3.DropdownMenu
8+
import androidx.compose.material3.DropdownMenuItem
9+
import androidx.compose.material3.Icon
10+
import androidx.compose.material3.IconButton
11+
import androidx.compose.material3.IconButtonColors
12+
import androidx.compose.material3.IconButtonDefaults
13+
import androidx.compose.material3.Text
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.LaunchedEffect
16+
import androidx.compose.runtime.getValue
17+
import androidx.compose.runtime.mutableStateOf
18+
import androidx.compose.runtime.remember
19+
import androidx.compose.runtime.setValue
20+
import androidx.compose.ui.Modifier
21+
import androidx.compose.ui.platform.LocalContext
22+
import com.mr3y.podcaster.LocalStrings
23+
24+
@Composable
25+
fun TopBarMoreOptionsButton(
26+
shareActionTitle: String,
27+
shareActionText: String,
28+
modifier: Modifier = Modifier,
29+
colors: IconButtonColors? = null
30+
) {
31+
var showOptions by remember { mutableStateOf(false) }
32+
var showShareSheet by remember { mutableStateOf(false) }
33+
val strings = LocalStrings.current
34+
val context = LocalContext.current
35+
IconButton(
36+
onClick = { showOptions = !showOptions },
37+
colors = colors ?: IconButtonDefaults.iconButtonColors(),
38+
modifier = modifier
39+
) {
40+
Icon(
41+
imageVector = Icons.Filled.MoreVert,
42+
contentDescription = strings.icon_more_options_content_description
43+
)
44+
}
45+
46+
DropdownMenu(
47+
expanded = showOptions,
48+
onDismissRequest = { showOptions = false },
49+
) {
50+
DropdownMenuItem(
51+
text = { Text(strings.share_label) },
52+
onClick = { showShareSheet = true }
53+
)
54+
}
55+
56+
LaunchedEffect(showShareSheet) {
57+
if (showShareSheet) {
58+
context.launchShareSheet(shareActionTitle, shareActionText)
59+
showShareSheet = false
60+
showOptions = false
61+
}
62+
}
63+
}
64+
65+
internal fun Context.launchShareSheet(title: String, url: String) {
66+
val sendIntent: Intent = Intent().apply {
67+
action = Intent.ACTION_SEND
68+
putExtra(Intent.EXTRA_TITLE, title)
69+
putExtra(Intent.EXTRA_TEXT, url)
70+
type = "text/plain"
71+
}
72+
73+
val shareIntent = Intent.createChooser(sendIntent, null)
74+
startActivity(shareIntent)
75+
}

ui/resources/src/main/kotlin/com/mr3y/podcaster/ui/resources/PodcasterEnStrings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ val EnStrings = PodcasterStrings(
7777
import_unknown_error = "Sorry, Something went wrong",
7878
favorites_label = "Favorites",
7979
favorites_empty_list = "You have no favorite episodes. start adding some to your favorites and they will show up here",
80+
share_label = "Share",
81+
icon_more_options_content_description = "More options",
8082
)

ui/resources/src/main/kotlin/com/mr3y/podcaster/ui/resources/PodcasterStrings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ data class PodcasterStrings(
6767
val import_unknown_error: String,
6868
val favorites_label: String,
6969
val favorites_empty_list: String,
70+
val share_label: String,
71+
val icon_more_options_content_description: String,
7072
)

0 commit comments

Comments
 (0)