Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/src/main/java/com/movemusic/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.app.Activity
import android.app.AlertDialog
import android.app.RecoverableSecurityException
import android.content.ClipData
import android.content.ContentUris
import android.content.ComponentName
import android.content.Intent
Expand Down Expand Up @@ -623,6 +624,15 @@ class MainActivity : ComponentActivity() {

holder = SongHolder(row, title, artist, add, transfer, remove, deleteFile)
row.setOnClickListener { holder.boundSong?.let { play(it) } }
row.setOnLongClickListener {
val song = holder.boundSong
if (song != null) {
shareSong(song)
true
} else {
false
}
}
return holder
}

Expand All @@ -642,6 +652,21 @@ class MainActivity : ComponentActivity() {
}
}

private fun shareSong(song: Song) {
try {
val mimeType = contentResolver.getType(song.uri) ?: "audio/*"
val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = mimeType
putExtra(Intent.EXTRA_STREAM, song.uri)
clipData = ClipData.newUri(contentResolver, song.title, song.uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(Intent.createChooser(shareIntent, "اشتراک‌گذاری آهنگ"))
} catch (_: Exception) {
toast("اشتراک‌گذاری این آهنگ ممکن نشد.")
}
}

private fun songActionButton(text: String, action: () -> Unit) = TextView(this).apply {
this.text = text
textSize = 12f
Expand Down
Loading