Revert "musikr.fs: prototype arbitrary saf locations"
This reverts commit c730091637.
This commit is contained in:
@@ -247,10 +247,10 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
|
|
||||||
private fun String.toOpenedLocations(): List<Location.Opened> =
|
private fun String.toOpenedLocations(): List<Location.Opened> =
|
||||||
splitEscaped { it == ';' }
|
splitEscaped { it == ';' }
|
||||||
.mapNotNull { Location.Unopened.from(context, it.toUri()).open(context) }
|
.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) }
|
||||||
|
|
||||||
private fun String.toUnopenedLocations(): List<Location.Unopened> =
|
private fun String.toUnopenedLocations(): List<Location.Unopened> =
|
||||||
splitEscaped { it == ';' }.map { Location.Unopened.from(context, it.toUri()) }
|
splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri()) }
|
||||||
|
|
||||||
private inline fun String.splitEscaped(selector: (Char) -> Boolean): List<String> {
|
private inline fun String.splitEscaped(selector: (Char) -> Boolean): List<String> {
|
||||||
val split = mutableListOf<String>()
|
val split = mutableListOf<String>()
|
||||||
|
|||||||
@@ -303,10 +303,11 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
|||||||
val context = requireContext()
|
val context = requireContext()
|
||||||
val location = Location.Unopened.from(context, uri)
|
val location = Location.Unopened.from(context, uri)
|
||||||
|
|
||||||
if (location.path.volume == null) {
|
if (location != null) {
|
||||||
requireContext().showToast(R.string.err_weird_location)
|
pendingLocationCallback?.invoke(location)
|
||||||
|
} else {
|
||||||
|
requireContext().showToast(R.string.err_bad_location)
|
||||||
}
|
}
|
||||||
pendingLocationCallback?.invoke(location)
|
|
||||||
pendingLocationCallback = null
|
pendingLocationCallback = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -347,7 +347,6 @@
|
|||||||
<string name="err_no_app">No app found that can handle this task</string>
|
<string name="err_no_app">No app found that can handle this task</string>
|
||||||
<!-- No folders in the "Music Folders" setting -->
|
<!-- No folders in the "Music Folders" setting -->
|
||||||
<string name="err_bad_location">This folder is not supported</string>
|
<string name="err_bad_location">This folder is not supported</string>
|
||||||
<string name="err_weird_location">Warning: This folder is managed by a 3rd-party</string>
|
|
||||||
<string name="lbl_no_folders">No folders</string>
|
<string name="lbl_no_folders">No folders</string>
|
||||||
|
|
||||||
<!-- Description Namespace | Accessibility Strings -->
|
<!-- Description Namespace | Accessibility Strings -->
|
||||||
|
|||||||
@@ -60,15 +60,11 @@ sealed class Location(val uri: Uri, val path: Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(context: Context, uri: Uri): Unopened {
|
fun from(context: Context, uri: Uri): Unopened? {
|
||||||
val path = getDocumentTreePath(context, uri) ?: Path(null, Components.root())
|
|
||||||
return Unopened(uri, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDocumentTreePath(context: Context, uri: Uri): Path? {
|
|
||||||
if (!DocumentsContract.isTreeUri(uri)) return null
|
if (!DocumentsContract.isTreeUri(uri)) return null
|
||||||
val documentPathFactory = DocumentPathFactory.from(context)
|
val documentPathFactory = DocumentPathFactory.from(context)
|
||||||
return documentPathFactory.unpackDocumentTreeUri(uri)
|
val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null
|
||||||
|
return Unopened(uri, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ import java.io.File
|
|||||||
/**
|
/**
|
||||||
* An abstraction of an android file system path, including the volume and relative path.
|
* An abstraction of an android file system path, including the volume and relative path.
|
||||||
*
|
*
|
||||||
* @param volume The volume that the path is on. Might be null if the Path is not associated with a
|
* @param volume The volume that the path is on.
|
||||||
* standard SAF document URI.
|
|
||||||
* @param components The components of the path of the file, relative to the root of the volume.
|
* @param components The components of the path of the file, relative to the root of the volume.
|
||||||
*/
|
*/
|
||||||
data class Path(val volume: Volume?, val components: Components) {
|
data class Path(val volume: Volume, val components: Components) {
|
||||||
/** The name of the file/directory. */
|
/** The name of the file/directory. */
|
||||||
val name: String?
|
val name: String?
|
||||||
get() = components.name
|
get() = components.name
|
||||||
@@ -52,8 +51,7 @@ data class Path(val volume: Volume?, val components: Components) {
|
|||||||
*
|
*
|
||||||
* @param context [Context] required to obtain human-readable strings.
|
* @param context [Context] required to obtain human-readable strings.
|
||||||
*/
|
*/
|
||||||
fun resolve(context: Context) =
|
fun resolve(context: Context) = "${volume.resolveName(context)}/$components"
|
||||||
volume?.let { "${volume.resolveName(context)}/$components" } ?: components.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface Volume {
|
sealed interface Volume {
|
||||||
@@ -172,8 +170,6 @@ value class Components private constructor(val components: List<String>) {
|
|||||||
fun parseWindows(path: String) =
|
fun parseWindows(path: String) =
|
||||||
Components(path.trimSlashes().split('\\').filter { it.isNotEmpty() })
|
Components(path.trimSlashes().split('\\').filter { it.isNotEmpty() })
|
||||||
|
|
||||||
fun root() = Components(emptyList())
|
|
||||||
|
|
||||||
private fun String.trimSlashes() = trimStart(File.separatorChar).trimEnd(File.separatorChar)
|
private fun String.trimSlashes() = trimStart(File.separatorChar).trimEnd(File.separatorChar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,14 @@ internal interface DocumentPathFactory {
|
|||||||
*/
|
*/
|
||||||
fun unpackDocumentTreeUri(uri: Uri): Path?
|
fun unpackDocumentTreeUri(uri: Uri): Path?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a [Path] instance into a document tree URI format path.
|
||||||
|
*
|
||||||
|
* @param path The [Path] instance to serialize.
|
||||||
|
* @return The serialized path.
|
||||||
|
*/
|
||||||
|
fun toDocumentId(path: Path): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserializes a document tree URI format path into a [Path] instance.
|
* Deserializes a document tree URI format path into a [Path] instance.
|
||||||
*
|
*
|
||||||
@@ -114,6 +122,15 @@ private class DocumentPathFactoryImpl(
|
|||||||
return fromDocumentId(treeUri)
|
return fromDocumentId(treeUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toDocumentId(path: Path): String =
|
||||||
|
when (val volume = path.volume) {
|
||||||
|
// The primary storage has a volume prefix of "primary", regardless
|
||||||
|
// of if it's internal or not.
|
||||||
|
is Volume.Internal -> "$DOCUMENT_URI_PRIMARY_NAME:${path.components}"
|
||||||
|
// Document tree URIs consist of a prefixed volume name followed by a relative path.
|
||||||
|
is Volume.External -> "${volume.id}:${path.components}"
|
||||||
|
}
|
||||||
|
|
||||||
override fun fromDocumentId(path: String): Path? {
|
override fun fromDocumentId(path: String): Path? {
|
||||||
// Document tree URIs consist of a prefixed volume name followed by a relative path,
|
// Document tree URIs consist of a prefixed volume name followed by a relative path,
|
||||||
// delimited with a colon.
|
// delimited with a colon.
|
||||||
|
|||||||
@@ -136,10 +136,6 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) :
|
|||||||
var template = ""
|
var template = ""
|
||||||
for (i in paths.indices) {
|
for (i in paths.indices) {
|
||||||
val path = paths[i]
|
val path = paths[i]
|
||||||
if (path.volume == null) {
|
|
||||||
// FIXME: This means we are silently ignoring third-party storage volumes
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val volume = path.volume.components ?: continue
|
val volume = path.volume.components ?: continue
|
||||||
template +=
|
template +=
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
@@ -220,11 +216,6 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) :
|
|||||||
var template = ""
|
var template = ""
|
||||||
for (i in paths.indices) {
|
for (i in paths.indices) {
|
||||||
val path = paths[i]
|
val path = paths[i]
|
||||||
if (path.volume == null) {
|
|
||||||
// FIXME: This means we are silently ignoring third-party storage volumes
|
|
||||||
// in MediaStore.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
template +=
|
template +=
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
"(${MediaStore.Audio.AudioColumns.VOLUME_NAME} LIKE ? " +
|
"(${MediaStore.Audio.AudioColumns.VOLUME_NAME} LIKE ? " +
|
||||||
|
|||||||
Reference in New Issue
Block a user