[Share] Cleanup Sharing of bug report and backup
This commit is contained in:
parent
f6a44672be
commit
e9340b429a
5 changed files with 21 additions and 56 deletions
|
@ -64,7 +64,7 @@ class ErrorActivity : AppCompatActivity() {
|
|||
intent
|
||||
), ".txt"
|
||||
)
|
||||
shareFile(this, bugReport)
|
||||
shareFile(this, bugReport, "text/*")
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import code.name.monkey.retromusic.extensions.materialDialog
|
|||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.helper.BackupHelper
|
||||
import code.name.monkey.retromusic.helper.sanitize
|
||||
import code.name.monkey.retromusic.util.BackupUtil
|
||||
import code.name.monkey.retromusic.util.Share
|
||||
import com.afollestad.materialdialogs.input.input
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -128,12 +128,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
|||
return true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
activity?.startActivity(
|
||||
Intent.createChooser(
|
||||
BackupUtil.createShareFileIntent(file, requireContext()),
|
||||
null
|
||||
)
|
||||
)
|
||||
Share.shareFile(requireContext(), file, "*/*")
|
||||
return true
|
||||
}
|
||||
R.id.action_rename -> {
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.content.FileProvider
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import java.io.File
|
||||
|
||||
object BackupUtil {
|
||||
fun createShareFileIntent(file: File, context: Context): Intent? {
|
||||
return try {
|
||||
Intent().setAction(Intent.ACTION_SEND).putExtra(
|
||||
Intent.EXTRA_STREAM,
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
file
|
||||
)
|
||||
).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setType("*/*")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
e.printStackTrace()
|
||||
context.showToast(
|
||||
"Could not share this file."
|
||||
)
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ import code.name.monkey.retromusic.model.Song
|
|||
import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics
|
||||
import code.name.monkey.retromusic.repository.Repository
|
||||
import code.name.monkey.retromusic.repository.SongRepository
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -42,21 +41,20 @@ import java.util.regex.Pattern
|
|||
|
||||
|
||||
object MusicUtil : KoinComponent {
|
||||
fun createShareSongFileIntent(song: Song, context: Context): Intent? {
|
||||
return try {
|
||||
Intent().setAction(Intent.ACTION_SEND).putExtra(
|
||||
Intent.EXTRA_STREAM,
|
||||
fun createShareSongFileIntent(song: Song, context: Context): Intent {
|
||||
return Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, try {
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
File(song.data)
|
||||
)
|
||||
).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setType("audio/*")
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Intent().setAction(Intent.ACTION_SEND).putExtra(
|
||||
Intent.EXTRA_STREAM,
|
||||
getSongFileUri(song.id)
|
||||
).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).setType("audio/*")
|
||||
})
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
type = "audio/*"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,15 +32,15 @@ object Share {
|
|||
context.startActivity(feedIntent, null)
|
||||
}
|
||||
|
||||
fun shareFile(context: Context, file: File) {
|
||||
val attachmentUri = FileProvider.getUriForFile(
|
||||
fun shareFile(context: Context, file: File, mimeType: String) {
|
||||
Intent(Intent.ACTION_SEND).apply {
|
||||
type = mimeType
|
||||
putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
file
|
||||
)
|
||||
val sharingIntent = Intent(Intent.ACTION_SEND)
|
||||
sharingIntent.type = "text/*"
|
||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, attachmentUri)
|
||||
context.startActivity(Intent.createChooser(sharingIntent, "send bug report"))
|
||||
))
|
||||
context.startActivity(Intent.createChooser(this, null))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue