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 -> {
|
||||
startActivity(Intent.createChooser(song?.let {
|
||||
MusicUtil.createShareSongFileIntent(
|
||||
it,
|
||||
requireContext()
|
||||
requireContext(), it
|
||||
)
|
||||
}, null))
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ object SongMenuHelper : KoinComponent {
|
|||
R.id.action_share -> {
|
||||
activity.startActivity(
|
||||
Intent.createChooser(
|
||||
MusicUtil.createShareSongFileIntent(song, activity),
|
||||
MusicUtil.createShareSongFileIntent(activity, song),
|
||||
null
|
||||
)
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
package code.name.monkey.retromusic.helper.menu
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
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.model.Song
|
||||
import code.name.monkey.retromusic.repository.RealRepository
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -53,6 +55,15 @@ object SongsMenuHelper : KoinComponent {
|
|||
}
|
||||
return true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
activity.startActivity(
|
||||
Intent.createChooser(
|
||||
MusicUtil.createShareMultipleSongIntent(activity, songs),
|
||||
null
|
||||
)
|
||||
)
|
||||
return true
|
||||
}
|
||||
R.id.action_delete_from_device -> {
|
||||
DeleteSongsDialog.create(songs)
|
||||
.show(activity.supportFragmentManager, "DELETE_SONGS")
|
||||
|
|
|
@ -41,23 +41,49 @@ import java.util.regex.Pattern
|
|||
|
||||
|
||||
object MusicUtil : KoinComponent {
|
||||
fun createShareSongFileIntent(song: Song, context: Context): Intent {
|
||||
fun createShareSongFileIntent(context: Context, song: Song): Intent {
|
||||
return Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, try {
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
File(song.data)
|
||||
)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
getSongFileUri(song.id)
|
||||
})
|
||||
putExtra(
|
||||
Intent.EXTRA_STREAM, try {
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
File(song.data)
|
||||
)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
getSongFileUri(song.id)
|
||||
}
|
||||
)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
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 {
|
||||
if (string1.isNullOrEmpty()) {
|
||||
return if (string2.isNullOrEmpty()) "" else string2
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
android:title="@string/action_add_to_playlist"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:title="@string/action_share"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete_from_device"
|
||||
android:icon="@drawable/ic_delete"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue