commit
eac03f702a
22 changed files with 135 additions and 0 deletions
|
@ -57,6 +57,7 @@ import org.oxycblt.auxio.util.collectImmediately
|
|||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.navigateSafe
|
||||
import org.oxycblt.auxio.util.setFullWidthLookup
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -163,6 +164,10 @@ class AlbumDetailFragment :
|
|||
musicModel.addToPlaylist(currentAlbum)
|
||||
true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(currentAlbum)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.oxycblt.auxio.util.collectImmediately
|
|||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.navigateSafe
|
||||
import org.oxycblt.auxio.util.setFullWidthLookup
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -159,6 +160,10 @@ class ArtistDetailFragment :
|
|||
musicModel.addToPlaylist(currentArtist)
|
||||
true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(currentArtist)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.oxycblt.auxio.util.collectImmediately
|
|||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.navigateSafe
|
||||
import org.oxycblt.auxio.util.setFullWidthLookup
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -158,6 +159,10 @@ class GenreDetailFragment :
|
|||
musicModel.addToPlaylist(currentGenre)
|
||||
true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(currentGenre)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.oxycblt.auxio.util.collectImmediately
|
|||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.navigateSafe
|
||||
import org.oxycblt.auxio.util.setFullWidthLookup
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -209,6 +210,10 @@ class PlaylistDetailFragment :
|
|||
musicModel.deletePlaylist(currentPlaylist)
|
||||
true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(currentPlaylist)
|
||||
true
|
||||
}
|
||||
R.id.action_save -> {
|
||||
detailModel.savePlaylistEdit()
|
||||
true
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.oxycblt.auxio.music.Song
|
|||
import org.oxycblt.auxio.navigation.MainNavigationAction
|
||||
import org.oxycblt.auxio.navigation.NavigationViewModel
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
|
||||
/**
|
||||
|
@ -104,6 +105,9 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
R.id.action_go_album -> {
|
||||
navModel.exploreNavigateTo(song.album)
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(song)
|
||||
}
|
||||
R.id.action_playlist_add -> {
|
||||
musicModel.addToPlaylist(song)
|
||||
}
|
||||
|
@ -152,6 +156,9 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
R.id.action_playlist_add -> {
|
||||
musicModel.addToPlaylist(album)
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(album)
|
||||
}
|
||||
else -> {
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
|
@ -189,6 +196,9 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
R.id.action_playlist_add -> {
|
||||
musicModel.addToPlaylist(artist)
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(artist)
|
||||
}
|
||||
else -> {
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
|
@ -226,6 +236,9 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
R.id.action_playlist_add -> {
|
||||
musicModel.addToPlaylist(genre)
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(genre)
|
||||
}
|
||||
else -> {
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
|
@ -266,6 +279,9 @@ abstract class ListFragment<in T : Music, VB : ViewBinding> :
|
|||
R.id.action_delete -> {
|
||||
musicModel.deletePlaylist(playlist)
|
||||
}
|
||||
R.id.action_share -> {
|
||||
requireContext().share(playlist)
|
||||
}
|
||||
else -> {
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
|
||||
/**
|
||||
|
@ -79,6 +80,10 @@ abstract class SelectionFragment<VB : ViewBinding> :
|
|||
playbackModel.shuffle(selectionModel.take())
|
||||
true
|
||||
}
|
||||
R.id.action_selection_share -> {
|
||||
requireContext().share(selectionModel.take())
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,6 +147,16 @@ data class MusicDirectories(val dirs: List<Directory>, val shouldInclude: Boolea
|
|||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
data class MimeType(val fromExtension: String, val fromFormat: String?) {
|
||||
|
||||
/**
|
||||
* Return a mime-type such as "audio/ogg"
|
||||
*
|
||||
* @return A raw mime-type string. Will first try [fromFormat], then falling back to
|
||||
* [fromExtension], and then null if that fails.
|
||||
*/
|
||||
val raw: String
|
||||
get() = fromFormat ?: fromExtension
|
||||
|
||||
/**
|
||||
* Resolve the mime type into a human-readable format name, such as "Ogg Vorbis".
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.oxycblt.auxio.playback.state.RepeatMode
|
|||
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.share
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
|
@ -180,6 +181,10 @@ class PlaybackPanelFragment :
|
|||
}
|
||||
true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
playbackModel.song.value?.let { requireContext().share(it) }
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.view.WindowInsets
|
|||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.app.ShareCompat
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.navigation.NavController
|
||||
|
@ -34,6 +35,12 @@ import androidx.navigation.NavDirections
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import java.lang.IllegalArgumentException
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
|
||||
private const val MIME_TYPE_FALLBACK = "audio/*"
|
||||
|
||||
/**
|
||||
* Get if this [View] contains the given [PointF], with optional leeway.
|
||||
|
@ -262,3 +269,37 @@ fun WindowInsets.replaceSystemBarInsetsCompat(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show system share sheet to share songs
|
||||
*
|
||||
* @param music the [Music] to share
|
||||
*/
|
||||
fun Context.share(music: Music) = share(
|
||||
when (music) {
|
||||
is Song -> listOf(music)
|
||||
is MusicParent -> music.songs
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Show system share sheet to share multiple song
|
||||
*
|
||||
* @param songs the collection of [Song] to share
|
||||
*/
|
||||
fun Context.share(songs: Collection<Song>) {
|
||||
if (songs.isEmpty()) {
|
||||
return
|
||||
}
|
||||
val type = songs.mapTo(HashSet(songs.size)) {
|
||||
it.mimeType.raw
|
||||
}.singleOrNull() ?: MIME_TYPE_FALLBACK
|
||||
ShareCompat.IntentBuilder(this)
|
||||
.apply {
|
||||
for (song in songs) {
|
||||
addStream(song.uri)
|
||||
}
|
||||
}
|
||||
.setType(type)
|
||||
.startChooser()
|
||||
}
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
</menu>
|
|
@ -9,6 +9,9 @@
|
|||
<item
|
||||
android:id="@+id/action_go_artist"
|
||||
android:title="@string/lbl_go_artist" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_song_detail"
|
||||
android:title="@string/lbl_song_detail" />
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
</menu>
|
|
@ -12,6 +12,9 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_song_detail"
|
||||
android:title="@string/lbl_song_detail" />
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
<item
|
||||
android:id="@+id/action_queue_add"
|
||||
android:title="@string/lbl_queue_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
|
|
|
@ -9,4 +9,7 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
</menu>
|
|
@ -14,6 +14,9 @@
|
|||
android:id="@+id/action_go_album"
|
||||
android:title="@string/lbl_go_album"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/lbl_delete" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
</menu>
|
|
@ -12,4 +12,7 @@
|
|||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/lbl_delete" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
</menu>
|
|
@ -21,4 +21,8 @@
|
|||
android:id="@+id/action_selection_shuffle"
|
||||
android:title="@string/lbl_shuffle_selected"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/action_selection_share"
|
||||
android:title="@string/lbl_share"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
|
@ -15,6 +15,9 @@
|
|||
<item
|
||||
android:id="@+id/action_playlist_add"
|
||||
android:title="@string/lbl_playlist_add" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/lbl_share" />
|
||||
<item
|
||||
android:id="@+id/action_song_detail"
|
||||
android:title="@string/lbl_song_detail" />
|
||||
|
|
|
@ -120,6 +120,7 @@
|
|||
<string name="lbl_go_artist">Go to artist</string>
|
||||
<string name="lbl_go_album">Go to album</string>
|
||||
<string name="lbl_song_detail">View properties</string>
|
||||
<string name="lbl_share">Share</string>
|
||||
|
||||
<string name="lbl_props">Song properties</string>
|
||||
<string name="lbl_file_name">File name</string>
|
||||
|
|
Loading…
Reference in a new issue