Add "Share" options menu

This commit is contained in:
Naveen 2023-07-26 02:08:32 +05:30
parent 80cb44c810
commit 0e02ef9cc1
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
13 changed files with 73 additions and 1 deletions

View file

@ -60,6 +60,7 @@ class AlbumsAdapter(activity: BaseSimpleActivity, var albums: ArrayList<Album>,
R.id.cab_add_to_playlist -> addToPlaylist()
R.id.cab_add_to_queue -> addToQueue()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_share -> shareFiles()
R.id.cab_select_all -> selectAll()
}
}
@ -123,6 +124,12 @@ class AlbumsAdapter(activity: BaseSimpleActivity, var albums: ArrayList<Album>,
}
}
private fun shareFiles() {
ensureBackgroundThread {
activity.shareTracks(getAllSelectedTracks())
}
}
private fun getSelectedAlbums(): List<Album> = albums.filter { selectedKeys.contains(it.hashCode()) }.toList()
fun updateItems(newItems: ArrayList<Album>, highlightText: String = "", forceUpdate: Boolean = false) {

View file

@ -106,6 +106,7 @@ class AlbumsTracksAdapter(
R.id.cab_add_to_queue -> addToQueue()
R.id.cab_properties -> showProperties()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_share -> shareFiles()
R.id.cab_rename -> displayEditDialog()
R.id.cab_select_all -> selectAll()
R.id.cab_play_next -> playNext()
@ -190,6 +191,12 @@ class AlbumsTracksAdapter(
}
}
private fun shareFiles() {
ensureBackgroundThread {
activity.shareTracks(getAllSelectedTracks())
}
}
private fun getAllSelectedTracks(): ArrayList<Track> {
val tracks = getSelectedTracks()
tracks.addAll(activity.audioHelper.getAlbumTracks(getSelectedAlbums()))

View file

@ -60,6 +60,7 @@ class ArtistsAdapter(activity: BaseSimpleActivity, var artists: ArrayList<Artist
R.id.cab_add_to_playlist -> addToPlaylist()
R.id.cab_add_to_queue -> addToQueue()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_share -> shareFiles()
R.id.cab_select_all -> selectAll()
}
}
@ -124,6 +125,12 @@ class ArtistsAdapter(activity: BaseSimpleActivity, var artists: ArrayList<Artist
}
}
private fun shareFiles() {
ensureBackgroundThread {
activity.shareTracks(getAllSelectedTracks())
}
}
private fun getSelectedArtists(): List<Artist> = artists.filter { selectedKeys.contains(it.hashCode()) }.toList()
fun updateItems(newItems: ArrayList<Artist>, highlightText: String = "", forceUpdate: Boolean = false) {

View file

@ -8,12 +8,18 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.highlightTextPart
import com.simplemobiletools.commons.extensions.setupViewBackground
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.extensions.audioHelper
import com.simplemobiletools.musicplayer.extensions.config
import com.simplemobiletools.musicplayer.extensions.shareTracks
import com.simplemobiletools.musicplayer.models.Events
import com.simplemobiletools.musicplayer.models.Folder
import kotlinx.android.synthetic.main.item_folder.view.*
import com.simplemobiletools.musicplayer.models.Track
import kotlinx.android.synthetic.main.item_folder.view.folder_frame
import kotlinx.android.synthetic.main.item_folder.view.folder_title
import kotlinx.android.synthetic.main.item_folder.view.folder_tracks
import org.greenrobot.eventbus.EventBus
class FoldersAdapter(
@ -45,6 +51,7 @@ class FoldersAdapter(
override fun actionItemPressed(id: Int) {
when (id) {
R.id.cab_exclude_folders -> excludeFolders()
R.id.cab_share -> shareFiles()
}
}
@ -69,6 +76,17 @@ class FoldersAdapter(
EventBus.getDefault().post(Events.RefreshFragments())
}
private fun shareFiles() {
ensureBackgroundThread {
val tracks = arrayListOf<Track>()
getSelectedFolders().forEach {
tracks += activity.audioHelper.getFolderTracks(it.title)
}
activity.shareTracks(tracks)
}
}
private fun getSelectedFolders(): List<Folder> = folders.filter { selectedKeys.contains(it.hashCode()) }.toList()
fun updateItems(newItems: ArrayList<Folder>, highlightText: String = "", forceUpdate: Boolean = false) {

View file

@ -101,6 +101,7 @@ class TracksAdapter(
R.id.cab_rename -> displayEditDialog()
R.id.cab_remove_from_playlist -> removeFromPlaylist()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_share -> activity.shareTracks(getSelectedTracks())
R.id.cab_select_all -> selectAll()
R.id.cab_play_next -> playNext()
}

View file

@ -97,6 +97,7 @@ class TracksHeaderAdapter(activity: SimpleActivity, var items: ArrayList<ListIte
R.id.cab_add_to_queue -> addToQueue()
R.id.cab_properties -> showProperties()
R.id.cab_delete -> askConfirmDelete()
R.id.cab_share -> activity.shareTracks(getSelectedTracks())
R.id.cab_rename -> displayEditDialog()
R.id.cab_select_all -> selectAll()
R.id.cab_play_next -> playNext()

View file

@ -7,9 +7,11 @@ import android.provider.MediaStore
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.extensions.rescanPaths
import com.simplemobiletools.commons.extensions.sharePathsIntent
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.musicplayer.BuildConfig
import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.dialogs.SelectPlaylistDialog
import com.simplemobiletools.musicplayer.helpers.*
@ -160,3 +162,8 @@ fun Activity.ensureActivityNotDestroyed(callback: () -> Unit) {
callback()
}
}
fun Activity.shareTracks(tracks: List<Track>) {
val paths = tracks.map { it.path }
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
}

View file

@ -8,6 +8,10 @@
android:icon="@drawable/ic_delete_vector"
android:showAsAction="always"
android:title="@string/delete" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
<item
android:id="@+id/cab_add_to_playlist"
android:showAsAction="never"

View file

@ -9,6 +9,10 @@
android:showAsAction="always"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
<item
android:id="@+id/cab_properties"
android:icon="@drawable/ic_info_vector"

View file

@ -9,6 +9,10 @@
android:showAsAction="always"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
<item
android:id="@+id/cab_add_to_playlist"
android:showAsAction="never"

View file

@ -9,4 +9,8 @@
android:showAsAction="always"
android:title="@string/exclude_folder"
app:showAsAction="always" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
</menu>

View file

@ -15,6 +15,10 @@
android:showAsAction="always"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
<item
android:id="@+id/cab_properties"
android:icon="@drawable/ic_info_vector"

View file

@ -9,6 +9,10 @@
android:showAsAction="always"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/cab_share"
android:showAsAction="never"
android:title="@string/share" />
<item
android:id="@+id/cab_properties"
android:icon="@drawable/ic_info_vector"