Added ability to share multiple songs
This commit is contained in:
parent
ad4467af93
commit
20ab3dad0d
5 changed files with 55 additions and 13 deletions
|
@ -60,8 +60,7 @@ class SongShareDialog : DialogFragment() {
|
||||||
0 -> {
|
0 -> {
|
||||||
startActivity(Intent.createChooser(song?.let {
|
startActivity(Intent.createChooser(song?.let {
|
||||||
MusicUtil.createShareSongFileIntent(
|
MusicUtil.createShareSongFileIntent(
|
||||||
it,
|
requireContext(), it
|
||||||
requireContext()
|
|
||||||
)
|
)
|
||||||
}, null))
|
}, null))
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ object SongMenuHelper : KoinComponent {
|
||||||
R.id.action_share -> {
|
R.id.action_share -> {
|
||||||
activity.startActivity(
|
activity.startActivity(
|
||||||
Intent.createChooser(
|
Intent.createChooser(
|
||||||
MusicUtil.createShareSongFileIntent(song, activity),
|
MusicUtil.createShareSongFileIntent(activity, song),
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
package code.name.monkey.retromusic.helper.menu
|
package code.name.monkey.retromusic.helper.menu
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
|
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
|
||||||
|
@ -21,6 +22,7 @@ import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
import code.name.monkey.retromusic.repository.RealRepository
|
||||||
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -53,6 +55,15 @@ object SongsMenuHelper : KoinComponent {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
R.id.action_share -> {
|
||||||
|
activity.startActivity(
|
||||||
|
Intent.createChooser(
|
||||||
|
MusicUtil.createShareMultipleSongIntent(activity, songs),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
R.id.action_delete_from_device -> {
|
R.id.action_delete_from_device -> {
|
||||||
DeleteSongsDialog.create(songs)
|
DeleteSongsDialog.create(songs)
|
||||||
.show(activity.supportFragmentManager, "DELETE_SONGS")
|
.show(activity.supportFragmentManager, "DELETE_SONGS")
|
||||||
|
|
|
@ -41,23 +41,49 @@ import java.util.regex.Pattern
|
||||||
|
|
||||||
|
|
||||||
object MusicUtil : KoinComponent {
|
object MusicUtil : KoinComponent {
|
||||||
fun createShareSongFileIntent(song: Song, context: Context): Intent {
|
fun createShareSongFileIntent(context: Context, song: Song): Intent {
|
||||||
return Intent().apply {
|
return Intent().apply {
|
||||||
action = Intent.ACTION_SEND
|
action = Intent.ACTION_SEND
|
||||||
putExtra(Intent.EXTRA_STREAM, try {
|
putExtra(
|
||||||
FileProvider.getUriForFile(
|
Intent.EXTRA_STREAM, try {
|
||||||
context,
|
FileProvider.getUriForFile(
|
||||||
context.applicationContext.packageName,
|
context,
|
||||||
File(song.data)
|
context.applicationContext.packageName,
|
||||||
)
|
File(song.data)
|
||||||
} catch (e: IllegalArgumentException) {
|
)
|
||||||
getSongFileUri(song.id)
|
} catch (e: IllegalArgumentException) {
|
||||||
})
|
getSongFileUri(song.id)
|
||||||
|
}
|
||||||
|
)
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
type = "audio/*"
|
type = "audio/*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createShareMultipleSongIntent(context: Context, songs: List<Song>): Intent {
|
||||||
|
return Intent().apply {
|
||||||
|
action = Intent.ACTION_SEND_MULTIPLE
|
||||||
|
type = "audio/*"
|
||||||
|
|
||||||
|
val files = ArrayList<Uri>()
|
||||||
|
|
||||||
|
for (song in songs) {
|
||||||
|
files.add(
|
||||||
|
try {
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
context.applicationContext.packageName,
|
||||||
|
File(song.data)
|
||||||
|
)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
getSongFileUri(song.id)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
putParcelableArrayListExtra(Intent.EXTRA_STREAM, files)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun buildInfoString(string1: String?, string2: String?): String {
|
fun buildInfoString(string1: String?, string2: String?): String {
|
||||||
if (string1.isNullOrEmpty()) {
|
if (string1.isNullOrEmpty()) {
|
||||||
return if (string2.isNullOrEmpty()) "" else string2
|
return if (string2.isNullOrEmpty()) "" else string2
|
||||||
|
|
|
@ -20,6 +20,12 @@
|
||||||
android:title="@string/action_add_to_playlist"
|
android:title="@string/action_add_to_playlist"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_share"
|
||||||
|
android:icon="@drawable/ic_share"
|
||||||
|
android:title="@string/action_share"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_delete_from_device"
|
android:id="@+id/action_delete_from_device"
|
||||||
android:icon="@drawable/ic_delete"
|
android:icon="@drawable/ic_delete"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue