Ignore blacklist and other things, so any song can be played when opened from File Managers, and also from Folders tab.
This commit is contained in:
parent
4d9396873e
commit
5415d3869a
5 changed files with 68 additions and 41 deletions
|
@ -1,5 +1,6 @@
|
|||
package code.name.monkey.retromusic.fragments.backup
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
|
@ -65,10 +66,10 @@ class RestoreActivity : AppCompatActivity() {
|
|||
|
||||
private fun getFileName(uri: Uri?): String? {
|
||||
when (uri?.scheme) {
|
||||
"file" -> {
|
||||
ContentResolver.SCHEME_FILE -> {
|
||||
return uri.lastPathSegment
|
||||
}
|
||||
"content" -> {
|
||||
ContentResolver.SCHEME_CONTENT -> {
|
||||
val proj = arrayOf(MediaStore.Files.FileColumns.DISPLAY_NAME)
|
||||
contentResolver.query(
|
||||
uri, proj, null, null, null
|
||||
|
|
|
@ -308,7 +308,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
|
|||
openQueue(songs, startIndex, true)
|
||||
} else {
|
||||
Snackbar.make(
|
||||
binding.root,
|
||||
mainActivity.slidingPanel,
|
||||
Html.fromHtml(
|
||||
String.format(
|
||||
getString(R.string.not_listed_in_media_store), file1.name
|
||||
|
|
|
@ -15,12 +15,10 @@
|
|||
package code.name.monkey.retromusic.helper
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.content.*
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.os.IBinder
|
||||
import android.provider.DocumentsContract
|
||||
|
@ -440,12 +438,14 @@ object MusicPlayerRemote : KoinComponent {
|
|||
} else if (uri.authority == "media") {
|
||||
songId = uri.lastPathSegment
|
||||
}
|
||||
if (songId != null) {
|
||||
songs = songRepository.songs(songId)
|
||||
songs = if (songId != null) {
|
||||
songRepository.songs(songId)
|
||||
} else {
|
||||
songRepository.songsIgnoreBlacklist(uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (songs == null) {
|
||||
if (songs == null || songs.isEmpty()) {
|
||||
var songFile: File? = null
|
||||
if (uri.authority != null && uri.authority == "com.android.externalstorage.documents") {
|
||||
songFile = File(
|
||||
|
@ -462,7 +462,7 @@ object MusicPlayerRemote : KoinComponent {
|
|||
songFile = File(uri.path!!)
|
||||
}
|
||||
if (songFile != null) {
|
||||
songs = songRepository.songsByFilePath(songFile.absolutePath)
|
||||
songs = songRepository.songsByFilePath(songFile.absolutePath, true)
|
||||
}
|
||||
}
|
||||
if (songs != null && songs.isNotEmpty()) {
|
||||
|
@ -474,7 +474,6 @@ object MusicPlayerRemote : KoinComponent {
|
|||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private fun getSongIdFromMediaProvider(uri: Uri): String {
|
||||
return DocumentsContract.getDocumentId(uri).split(":".toRegex())
|
||||
.dropLastWhile { it.isEmpty() }.toTypedArray()[1]
|
||||
|
|
|
@ -16,6 +16,7 @@ package code.name.monkey.retromusic.repository
|
|||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Audio.AudioColumns
|
||||
|
@ -42,11 +43,13 @@ interface SongRepository {
|
|||
|
||||
fun songs(query: String): List<Song>
|
||||
|
||||
fun songsByFilePath(filePath: String): List<Song>
|
||||
fun songsByFilePath(filePath: String, ignoreBlacklist: Boolean = false): List<Song>
|
||||
|
||||
fun song(cursor: Cursor?): Song
|
||||
|
||||
fun song(songId: Long): Song
|
||||
|
||||
fun songsIgnoreBlacklist(uri: Uri): List<Song>
|
||||
}
|
||||
|
||||
class RealSongRepository(private val context: Context) : SongRepository {
|
||||
|
@ -84,15 +87,38 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
|||
return song(makeSongCursor(AudioColumns._ID + "=?", arrayOf(songId.toString())))
|
||||
}
|
||||
|
||||
override fun songsByFilePath(filePath: String): List<Song> {
|
||||
override fun songsByFilePath(filePath: String, ignoreBlacklist: Boolean): List<Song> {
|
||||
return songs(
|
||||
makeSongCursor(
|
||||
AudioColumns.DATA + "=?",
|
||||
arrayOf(filePath)
|
||||
arrayOf(filePath),
|
||||
ignoreBlacklist = ignoreBlacklist
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun songsIgnoreBlacklist(uri: Uri): List<Song> {
|
||||
var filePath = ""
|
||||
context.contentResolver.query(
|
||||
uri,
|
||||
arrayOf(AudioColumns.DATA),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
).use { cursor ->
|
||||
if (cursor != null) {
|
||||
if (cursor.count != 0) {
|
||||
cursor.moveToFirst()
|
||||
filePath = cursor.getString(AudioColumns.DATA)
|
||||
println("File Path: $filePath")
|
||||
}
|
||||
}
|
||||
}
|
||||
return songsByFilePath(
|
||||
filePath, true
|
||||
)
|
||||
}
|
||||
|
||||
private fun getSongFromCursorImpl(
|
||||
cursor: Cursor
|
||||
): Song {
|
||||
|
@ -128,13 +154,14 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
|||
|
||||
@JvmOverloads
|
||||
fun makeSongCursor(
|
||||
|
||||
selection: String?,
|
||||
selectionValues: Array<String>?,
|
||||
sortOrder: String = PreferenceUtil.songSortOrder
|
||||
sortOrder: String = PreferenceUtil.songSortOrder,
|
||||
ignoreBlacklist: Boolean = false
|
||||
): Cursor? {
|
||||
var selectionFinal = selection
|
||||
var selectionValuesFinal = selectionValues
|
||||
if (!ignoreBlacklist) {
|
||||
selectionFinal = if (selection != null && selection.trim { it <= ' ' } != "") {
|
||||
"$IS_MUSIC AND $selectionFinal"
|
||||
} else {
|
||||
|
@ -161,7 +188,7 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
|||
|
||||
selectionFinal =
|
||||
selectionFinal + " AND " + Media.DURATION + ">= " + (PreferenceUtil.filterLength * 1000)
|
||||
|
||||
}
|
||||
val uri = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
|
||||
Media.getContentUri(MediaStore.VOLUME_EXTERNAL)
|
||||
} else {
|
||||
|
|
|
@ -92,7 +92,7 @@ public final class FileUtil {
|
|||
}
|
||||
|
||||
Cursor songCursor =
|
||||
new RealSongRepository(context).makeSongCursor(selection, selection == null ? null : paths);
|
||||
new RealSongRepository(context).makeSongCursor(selection, selection == null ? null : paths, PreferenceUtil.INSTANCE.getSongSortOrder(), true);
|
||||
|
||||
return songCursor == null
|
||||
? null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue