music: ignore third party system mode filters

This commit is contained in:
Alexander Capehart
2026-01-17 09:37:43 -07:00
parent c20b342545
commit ef3bd6e3cf
@@ -40,6 +40,7 @@ import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
import org.oxycblt.auxio.util.getAttrColorCompat import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.showToast import org.oxycblt.auxio.util.showToast
import org.oxycblt.musikr.fs.Location import org.oxycblt.musikr.fs.Location
import org.oxycblt.musikr.fs.Volume
import org.oxycblt.musikr.fs.mediastore.MediaStore import org.oxycblt.musikr.fs.mediastore.MediaStore
import org.oxycblt.musikr.fs.saf.SAF import org.oxycblt.musikr.fs.saf.SAF
import timber.log.Timber as L import timber.log.Timber as L
@@ -78,6 +79,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
private val filterLocationAdapter: LocationAdapter<Location.Unopened> = private val filterLocationAdapter: LocationAdapter<Location.Unopened> =
LocationAdapter(filterLocationListener) LocationAdapter(filterLocationListener)
private var openDocumentTreeLauncher: ActivityResultLauncher<Uri?>? = null private var openDocumentTreeLauncher: ActivityResultLauncher<Uri?>? = null
private var localOnlyOpenDocumentTreeLauncher: ActivityResultLauncher<Uri?>? = null
private var storagePermissionLauncher: ActivityResultLauncher<String>? = null private var storagePermissionLauncher: ActivityResultLauncher<String>? = null
@Inject lateinit var musicSettings: MusicSettings @Inject lateinit var musicSettings: MusicSettings
@@ -104,7 +106,13 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
) { ) {
openDocumentTreeLauncher = openDocumentTreeLauncher =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri -> registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
addDocumentTreeUriToDirs(uri) addDocumentTreeUriToDirs(uri, false)
}
// TODO: Add failure mode for introduction of third-party filters in system loader
localOnlyOpenDocumentTreeLauncher =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
addDocumentTreeUriToDirs(uri, true)
} }
storagePermissionLauncher = storagePermissionLauncher =
@@ -198,21 +206,21 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
updateSaveButtonState() updateSaveButtonState()
} }
} }
onNewLocation() onNewLocation(openDocumentTreeLauncher)
} }
binding.locationsExcludeAdd.setOnClickListener { binding.locationsExcludeAdd.setOnClickListener {
pendingLocationCallback = { location -> pendingLocationCallback = { location ->
excludeLocationAdapter.add(location) excludeLocationAdapter.add(location)
updateSaveButtonState() updateSaveButtonState()
} }
onNewLocation() onNewLocation(openDocumentTreeLauncher)
} }
binding.locationsFilterAdd.setOnClickListener { binding.locationsFilterAdd.setOnClickListener {
pendingLocationCallback = { location -> pendingLocationCallback = { location ->
filterLocationAdapter.add(location) filterLocationAdapter.add(location)
updateSaveButtonState() updateSaveButtonState()
} }
onNewLocation() onNewLocation(localOnlyOpenDocumentTreeLauncher)
} }
// Set up grant permission card click // Set up grant permission card click
@@ -282,10 +290,10 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
binding.locationsFilterRecycler.adapter = null binding.locationsFilterRecycler.adapter = null
} }
private fun onNewLocation() { private fun onNewLocation(launcher: ActivityResultLauncher<Uri?>?) {
L.d("Opening launcher") L.d("Opening launcher")
val launcher = val launcher =
requireNotNull(openDocumentTreeLauncher) { "Document tree launcher was not available" } requireNotNull(launcher) { "Document tree launcher was not available" }
try { try {
launcher.launch(null) launcher.launch(null)
@@ -294,7 +302,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
} }
} }
private fun addDocumentTreeUriToDirs(uri: Uri?) { private fun addDocumentTreeUriToDirs(uri: Uri?, disableThirdParty: Boolean) {
if (uri == null) { if (uri == null) {
L.d("No URI given (user closed the dialog)") L.d("No URI given (user closed the dialog)")
pendingLocationCallback = null pendingLocationCallback = null
@@ -303,11 +311,12 @@ 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 != null) { if (location.path.volume is Volume.ThirdParty && disableThirdParty) {
pendingLocationCallback?.invoke(location)
} else {
requireContext().showToast(R.string.err_bad_location) requireContext().showToast(R.string.err_bad_location)
pendingLocationCallback = null
return
} }
pendingLocationCallback?.invoke(location)
pendingLocationCallback = null pendingLocationCallback = null
} }