-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into cristhian/update-app-version
- Loading branch information
Showing
7 changed files
with
137 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...res/music-player/src/main/java/io/newm/feature/musicplayer/share/RandomPhraseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.newm.feature.musicplayer.share | ||
|
||
import android.content.Context | ||
import io.newm.core.resources.R | ||
|
||
fun Context.getRandomSharePhrase(songTitle: String, songArtist: String): String { | ||
val phraseIds = listOf( | ||
R.string.share_phrase_1, | ||
R.string.share_phrase_2, | ||
R.string.share_phrase_3, | ||
R.string.share_phrase_4, | ||
R.string.share_phrase_5, | ||
R.string.share_phrase_6, | ||
R.string.share_phrase_7, | ||
R.string.share_phrase_8, | ||
R.string.share_phrase_9, | ||
R.string.share_phrase_10, | ||
R.string.share_phrase_11, | ||
R.string.share_phrase_12, | ||
R.string.share_phrase_13, | ||
R.string.share_phrase_14, | ||
R.string.share_phrase_15 | ||
) | ||
return this.getString( phraseIds.random(), songTitle, songArtist) | ||
} |
49 changes: 49 additions & 0 deletions
49
android/features/music-player/src/main/java/io/newm/feature/musicplayer/share/ShareButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.newm.feature.musicplayer.share | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import io.newm.core.resources.R | ||
|
||
@Composable | ||
fun ShareButton( | ||
modifier: Modifier = Modifier, | ||
songTitle: String? = null, | ||
songArtist: String? = null, | ||
) { | ||
if (songTitle.isNullOrBlank() || songArtist.isNullOrBlank()) return | ||
val context = LocalContext.current | ||
IconButton(modifier = modifier, onClick = { | ||
shareSong(context, songTitle, songArtist) | ||
}) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_share), | ||
contentDescription = "Share Song", | ||
tint = Color.White | ||
) | ||
} | ||
} | ||
|
||
fun shareSong(context: Context, songTitle: String, songArtist: String) { | ||
val randomPhrase = context.getRandomSharePhrase(songTitle, songArtist) | ||
val callToAction = context.getString(R.string.share_call_to_action) | ||
val shareText = """ | ||
$randomPhrase | ||
$callToAction | ||
""".trimIndent() | ||
|
||
val shareIntent = Intent().apply { | ||
action = Intent.ACTION_SEND | ||
putExtra(Intent.EXTRA_TEXT, shareText) | ||
type = "text/plain" | ||
} | ||
val chooser = Intent.createChooser(shareIntent, "Share song via") | ||
context.startActivity(chooser) | ||
} |