musikr: hard revert to pre-filetreecache system

This commit is contained in:
Alexander Capehart
2025-06-16 07:23:55 -06:00
parent 5f303b1be1
commit b3acb31008
43 changed files with 318 additions and 1864 deletions
@@ -29,7 +29,6 @@ import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield
import org.oxycblt.auxio.image.covers.SettingCovers
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
import org.oxycblt.auxio.music.shim.WriteOnlyFileTreeCache
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
import org.oxycblt.musikr.IndexingProgress
import org.oxycblt.musikr.Interpretation
@@ -38,11 +37,9 @@ import org.oxycblt.musikr.Music
import org.oxycblt.musikr.Musikr
import org.oxycblt.musikr.MutableLibrary
import org.oxycblt.musikr.Playlist
import org.oxycblt.musikr.Query
import org.oxycblt.musikr.Song
import org.oxycblt.musikr.Storage
import org.oxycblt.musikr.cache.MutableCache
import org.oxycblt.musikr.fs.device.FileTreeCache
import org.oxycblt.musikr.playlist.db.StoredPlaylists
import org.oxycblt.musikr.tag.interpret.Naming
import org.oxycblt.musikr.tag.interpret.Separators
@@ -388,20 +385,16 @@ constructor(
Naming.simple()
}
val locations = musicSettings.musicLocations
val excludedLocations = musicSettings.excludedLocations
val withHidden = musicSettings.withHidden
val currentRevision = musicSettings.revision
val newRevision = currentRevision?.takeIf { withCache } ?: UUID.randomUUID()
val cache = if (withCache) cache else WriteOnlyMutableCache(cache)
val covers = settingCovers.mutate(context, newRevision)
val fileTreeCache =
if (withCache) FileTreeCache.from(context)
else WriteOnlyFileTreeCache(FileTreeCache.from(context))
val query = Query(source = locations, exclude = excludedLocations)
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
val storage = Storage(cache, covers, storedPlaylists)
val interpretation = Interpretation(nameFactory, separators, withHidden)
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
val result =
Musikr.new(context, storage, interpretation).run(locations, ::emitIndexingProgress)
// Music loading completed, update the revision right now so we re-use this work
// later.
musicSettings.revision = newRevision
@@ -20,13 +20,12 @@ package org.oxycblt.auxio.music
import android.content.Context
import androidx.core.content.edit
import androidx.core.net.toUri
import dagger.hilt.android.qualifiers.ApplicationContext
import java.util.UUID
import javax.inject.Inject
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.Settings
import org.oxycblt.musikr.fs.Location
import org.oxycblt.musikr.fs.MusicLocation
import timber.log.Timber as L
/**
@@ -38,9 +37,7 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
/** The current library revision. */
var revision: UUID?
/** The locations of music to load. */
var musicLocations: List<Location.Opened>
/** The locations to exclude from music loading. */
var excludedLocations: List<Location.Unopened>
var musicLocations: List<MusicLocation>
/** Whether to exclude non-music audio files from the music library. */
val excludeNonMusic: Boolean
/** Whether to ignore hidden files and directories during music loading. */
@@ -77,35 +74,20 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
}
}
override var musicLocations: List<Location.Opened>
override var musicLocations: List<MusicLocation>
get() {
val locations =
sharedPreferences.getString(getString(R.string.set_key_music_locations), null)
?: return emptyList()
return locations.toOpenedLocations()
}
set(value) {
sharedPreferences.edit {
putString(getString(R.string.set_key_music_locations), value.stringify())
commit()
// Sometimes changing this setting just won't actually trigger the listener.
// Only this one. No idea why.
listener?.onMusicLocationsChanged()
}
}
override var excludedLocations: List<Location.Unopened>
get() {
val locations =
sharedPreferences.getString(getString(R.string.set_key_excluded_locations), null)
?: return emptyList()
return locations.toUnopenedLocations()
return MusicLocation.existing(context, locations)
}
set(value) {
sharedPreferences.edit {
putString(
getString(R.string.set_key_excluded_locations), value.stringifyLocations())
getString(R.string.set_key_music_locations), MusicLocation.toString(value))
commit()
// Sometimes changing this setting just won't actually trigger the listener.
// Only this one. No idea why.
listener?.onMusicLocationsChanged()
}
}
@@ -137,8 +119,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
// (just need to manipulate data)
when (key) {
getString(R.string.set_key_music_locations),
getString(R.string.set_key_excluded_locations) -> {
getString(R.string.set_key_music_locations) -> {
L.d("Dispatching music locations change")
listener.onMusicLocationsChanged()
}
@@ -155,55 +136,4 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
}
}
}
private fun List<Location.Opened>.stringify(): String =
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
private fun String.toOpenedLocations(): List<Location.Opened> =
splitEscaped { it == ';' }
.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) }
private fun List<Location>.stringifyLocations(): String =
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
private fun String.toUnopenedLocations(): List<Location.Unopened> =
splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri()) }
private inline fun String.splitEscaped(selector: (Char) -> Boolean): List<String> {
val split = mutableListOf<String>()
var currentString = ""
var i = 0
while (i < length) {
val a = get(i)
val b = getOrNull(i + 1)
if (selector(a)) {
// Non-escaped separator, split the string here, making sure any stray whitespace
// is removed.
split.add(currentString)
currentString = ""
i++
continue
}
if (b != null && a == '\\' && selector(b)) {
// Is an escaped character, add the non-escaped variant and skip two
// characters to move on to the next one.
currentString += b
i += 2
} else {
// Non-escaped, increment normally.
currentString += a
i++
}
}
if (currentString.isNotEmpty()) {
// Had an in-progress split string that is now terminated, add it.
split.add(currentString)
}
return split
}
}
@@ -1,57 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
* ExcludedLocationAdapter.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.locations
import android.view.ViewGroup
import org.oxycblt.auxio.databinding.ItemMusicLocationBinding
import org.oxycblt.auxio.util.inflater
import org.oxycblt.musikr.fs.Location
/**
* [LocationAdapter] that manages a list of [Location.Unopened] excluded directory instances.
*
* @param listener A [LocationAdapter.Listener] to bind interactions to.
* @author Alexander Capehart (OxygenCobalt)
*/
class ExcludedLocationAdapter(listener: LocationAdapter.Listener<Location.Unopened>) :
LocationAdapter<Location.Unopened>(listener) {
override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Unopened> =
ExcludedLocationViewHolder.from(parent)
}
/**
* A [LocationViewHolder] that displays a [Location.Unopened]. Use [from] to create an instance.
*
* @author Alexander Capehart (OxygenCobalt)
*/
class ExcludedLocationViewHolder private constructor(binding: ItemMusicLocationBinding) :
LocationViewHolder<Location.Unopened>(binding) {
companion object {
/**
* Create a new instance.
*
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: ViewGroup) =
ExcludedLocationViewHolder(
ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false))
}
}
@@ -1,63 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
* ExcludedLocationsDialog.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.locations
import android.content.Context
import android.net.Uri
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.musikr.fs.Location
/**
* Dialog that manages the excluded locations setting.
*
* @author Alexander Capehart (OxygenCobalt)
*/
@AndroidEntryPoint
class ExcludedLocationsDialog : LocationsDialog<Location.Unopened>() {
override val locationAdapter = ExcludedLocationAdapter(this)
@Inject override lateinit var musicSettings: MusicSettings
override fun getDialogTitle(): Int = R.string.set_excluded_locations
override fun getCurrentLocations(): List<Location.Unopened> = musicSettings.excludedLocations
override fun saveLocations(locations: List<Location.Unopened>) {
musicSettings.excludedLocations = locations
}
override fun getPendingLocationsKey(): String = KEY_PENDING_EXCLUDED_LOCATIONS
override fun convertUriToLocation(uri: Uri): Location.Unopened? {
return Location.Unopened.from(requireContext(), uri)
}
override fun createLocationFromUri(context: Context, uri: Uri): Location.Unopened? {
return Location.Unopened.from(context, uri)
}
private companion object {
const val KEY_PENDING_EXCLUDED_LOCATIONS =
BuildConfig.APPLICATION_ID + ".key.PENDING_EXCLUDED_LOCATIONS"
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Auxio Project
* Copyright (c) 2021 Auxio Project
* LocationAdapter.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
@@ -18,59 +18,106 @@
package org.oxycblt.auxio.music.locations
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.databinding.ItemMusicLocationBinding
import org.oxycblt.auxio.list.recycler.DialogRecyclerView
import org.oxycblt.auxio.util.context
import org.oxycblt.musikr.fs.Location
import org.oxycblt.auxio.util.inflater
import org.oxycblt.musikr.fs.MusicLocation
import timber.log.Timber as L
abstract class LocationAdapter<T : Location>(private val listener: Listener<T>) :
RecyclerView.Adapter<LocationViewHolder<T>>() {
private val _locations = mutableListOf<T>()
val locations: List<T> = _locations
/**
* [RecyclerView.Adapter] that manages a list of [MusicLocation] music directory instances.
*
* @param listener A [LocationAdapter.Listener] to bind interactions to.
* @author Alexander Capehart (OxygenCobalt)
*/
class LocationAdapter(private val listener: Listener) : RecyclerView.Adapter<MusicDirViewHolder>() {
private val _locations = mutableListOf<MusicLocation>()
/**
* The current list of [MusicLocation]s, may not line up with [MusicLocation]s due to removals.
*/
val locations: List<MusicLocation> = _locations
override fun getItemCount() = locations.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
MusicDirViewHolder.from(parent)
override fun onBindViewHolder(holder: LocationViewHolder<T>, position: Int) =
override fun onBindViewHolder(holder: MusicDirViewHolder, position: Int) =
holder.bind(locations[position], listener)
fun add(location: T) {
/**
* Add a [MusicLocation] to the end of the list.
*
* @param location The [MusicLocation] to add.
*/
fun add(location: MusicLocation) {
if (_locations.contains(location)) return
L.d("Adding $location")
_locations.add(location)
notifyItemInserted(_locations.lastIndex)
}
fun addAll(locations: List<T>) {
/**
* Add a list of [MusicLocation] instances to the end of the list.
*
* @param locations The [MusicLocation] instances to add.
*/
fun addAll(locations: List<MusicLocation>) {
L.d("Adding ${locations.size} locations")
val oldSize = _locations.size
val oldLastIndex = locations.lastIndex
_locations.addAll(locations)
notifyItemRangeInserted(oldSize, locations.size)
notifyItemRangeInserted(oldLastIndex, locations.size)
}
fun remove(location: T) {
/**
* Remove a [MusicLocation] from the list.
*
* @param location The [MusicLocation] to remove. Must exist in the list.
*/
fun remove(location: MusicLocation) {
L.d("Removing $location")
val idx = _locations.indexOf(location)
_locations.removeAt(idx)
notifyItemRemoved(idx)
}
protected abstract fun createViewHolder(parent: ViewGroup): LocationViewHolder<T>
interface Listener<T : Location> {
fun onRemoveLocation(location: T)
/** A Listener for [LocationAdapter] interactions. */
interface Listener {
/** Called when the delete button on a directory item is clicked. */
fun onRemoveLocation(location: MusicLocation)
}
}
abstract class LocationViewHolder<T : Location>(protected val binding: ItemMusicLocationBinding) :
/**
* A [RecyclerView.Recycler] that displays a [MusicLocation]. Use [from] to create an instance.
*
* @author Alexander Capehart (OxygenCobalt)
*/
class MusicDirViewHolder private constructor(private val binding: ItemMusicLocationBinding) :
DialogRecyclerView.ViewHolder(binding.root) {
fun bind(location: T, listener: LocationAdapter.Listener<T>) {
/**
* Bind new data to this instance.
*
* @param location The new [MusicLocation] to bind.
* @param listener A [LocationAdapter.Listener] to bind interactions to.
*/
fun bind(location: MusicLocation, listener: LocationAdapter.Listener) {
binding.locationPath.text = location.path.resolve(binding.context)
binding.locationDelete.setOnClickListener { listener.onRemoveLocation(location) }
}
companion object {
/**
* Create a new instance.
*
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
MusicDirViewHolder(ItemMusicLocationBinding.inflate(parent.context.inflater))
}
}
@@ -1,57 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
* MusicLocationAdapter.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.locations
import android.view.ViewGroup
import org.oxycblt.auxio.databinding.ItemMusicLocationBinding
import org.oxycblt.auxio.util.inflater
import org.oxycblt.musikr.fs.Location
/**
* [LocationAdapter] that manages a list of [Location.Opened] music directory instances.
*
* @param listener A [LocationAdapter.Listener] to bind interactions to.
* @author Alexander Capehart (OxygenCobalt)
*/
class MusicLocationAdapter(listener: LocationAdapter.Listener<Location.Opened>) :
LocationAdapter<Location.Opened>(listener) {
override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Opened> =
MusicLocationViewHolder.from(parent)
}
/**
* A [LocationViewHolder] that displays a [Location.Opened]. Use [from] to create an instance.
*
* @author Alexander Capehart (OxygenCobalt)
*/
class MusicLocationViewHolder private constructor(binding: ItemMusicLocationBinding) :
LocationViewHolder<Location.Opened>(binding) {
companion object {
/**
* Create a new instance.
*
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: ViewGroup) =
MusicLocationViewHolder(
ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false))
}
}
@@ -1,63 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
* MusicLocationsDialog.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.locations
import android.content.Context
import android.net.Uri
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.musikr.fs.Location
/**
* Dialog that manages the music locations setting.
*
* @author Alexander Capehart (OxygenCobalt)
*/
@AndroidEntryPoint
class MusicLocationsDialog : LocationsDialog<Location.Opened>() {
override val locationAdapter = MusicLocationAdapter(this)
@Inject override lateinit var musicSettings: MusicSettings
override fun getDialogTitle(): Int = R.string.set_locations
override fun getCurrentLocations(): List<Location.Opened> = musicSettings.musicLocations
override fun saveLocations(locations: List<Location.Opened>) {
musicSettings.musicLocations = locations
}
override fun getPendingLocationsKey(): String = KEY_PENDING_LOCATIONS
override fun convertUriToLocation(uri: Uri): Location.Opened? {
val context = requireContext()
return Location.Unopened.from(context, uri)?.open(context)
}
override fun createLocationFromUri(context: Context, uri: Uri): Location.Opened? {
return Location.Unopened.from(context, uri)?.open(context)
}
private companion object {
const val KEY_PENDING_LOCATIONS = BuildConfig.APPLICATION_ID + ".key.PENDING_LOCATIONS"
}
}
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2024 Auxio Project
* LocationsDialog.kt is part of Auxio.
* Copyright (c) 2021 Auxio Project
* MusicSourcesDialog.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,33 +27,42 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import androidx.recyclerview.widget.ConcatAdapter
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.DialogMusicLocationsBinding
import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
import org.oxycblt.auxio.util.showToast
import org.oxycblt.musikr.fs.Location
import org.oxycblt.musikr.fs.MusicLocation
import timber.log.Timber as L
abstract class LocationsDialog<T : Location> :
/**
* Dialog that manages the music locations setting.
*
* @author Alexander Capehart (OxygenCobalt)
*/
@AndroidEntryPoint
class MusicSourcesDialog :
ViewBindingMaterialDialogFragment<DialogMusicLocationsBinding>(),
LocationAdapter.Listener<T>,
LocationAdapter.Listener,
NewLocationFooterAdapter.Listener {
protected abstract val locationAdapter: LocationAdapter<T>
private val locationAdapter = LocationAdapter(this)
private val locationFooterAdapter = NewLocationFooterAdapter(this)
private var openDocumentTreeLauncher: ActivityResultLauncher<Uri?>? = null
abstract val musicSettings: MusicSettings
@Inject lateinit var musicSettings: MusicSettings
override fun onCreateBinding(inflater: LayoutInflater) =
DialogMusicLocationsBinding.inflate(inflater)
override fun onConfigDialog(builder: AlertDialog.Builder) {
builder
.setTitle(getDialogTitle())
.setTitle(R.string.set_locations)
.setNegativeButton(R.string.lbl_cancel, null)
.setPositiveButton(R.string.lbl_save) { _, _ ->
val newDirs = locationAdapter.locations
saveLocations(newDirs)
musicSettings.musicLocations = newDirs
}
}
@@ -71,9 +80,9 @@ abstract class LocationsDialog<T : Location> :
}
val locations =
savedInstanceState?.getStringArrayList(getPendingLocationsKey())?.mapNotNull {
convertUriToLocation(it.toUri())
} ?: getCurrentLocations()
savedInstanceState?.getStringArrayList(KEY_PENDING_LOCATIONS)?.mapNotNull {
MusicLocation.existing(requireContext(), it.toUri())
} ?: musicSettings.musicLocations
locationAdapter.addAll(locations)
}
@@ -81,8 +90,7 @@ abstract class LocationsDialog<T : Location> :
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putStringArrayList(
getPendingLocationsKey(),
ArrayList(locationAdapter.locations.map { it.uri.toString() }))
KEY_PENDING_LOCATIONS, ArrayList(locationAdapter.locations.map { it.uri.toString() }))
}
override fun onDestroyBinding(binding: DialogMusicLocationsBinding) {
@@ -91,6 +99,10 @@ abstract class LocationsDialog<T : Location> :
binding.locationsRecycler.adapter = null
}
override fun onRemoveLocation(location: MusicLocation) {
locationAdapter.remove(location)
}
override fun onNewLocation() {
L.d("Opening launcher")
val launcher =
@@ -99,17 +111,24 @@ abstract class LocationsDialog<T : Location> :
try {
launcher.launch(null)
} catch (e: ActivityNotFoundException) {
// User doesn't have a capable file manager.
requireContext().showToast(R.string.err_no_app)
}
}
/**
* Add a Document Tree [Uri] chosen by the user to the current [MusicLocation]s.
*
* @param uri The document tree [Uri] to add, chosen by the user. Will do nothing if the [Uri]
* is null or not valid.
*/
private fun addDocumentTreeUriToDirs(uri: Uri?) {
if (uri == null) {
// A null URI means that the user left the file picker without picking a locationectory
L.d("No URI given (user closed the dialog)")
return
}
val context = requireContext()
val location = createLocationFromUri(context, uri)
val location = MusicLocation.new(requireContext(), uri)
if (location != null) {
locationAdapter.add(location)
@@ -118,19 +137,7 @@ abstract class LocationsDialog<T : Location> :
}
}
override fun onRemoveLocation(location: T) {
locationAdapter.remove(location)
private companion object {
const val KEY_PENDING_LOCATIONS = BuildConfig.APPLICATION_ID + ".key.PENDING_LOCATIONS"
}
protected abstract fun getDialogTitle(): Int
protected abstract fun getCurrentLocations(): List<T>
protected abstract fun saveLocations(locations: List<T>)
protected abstract fun getPendingLocationsKey(): String
protected abstract fun convertUriToLocation(uri: Uri): T?
protected abstract fun createLocationFromUri(context: android.content.Context, uri: Uri): T?
}
@@ -36,7 +36,7 @@ import org.oxycblt.auxio.music.shim.UpdateTrackerFactory
import org.oxycblt.auxio.playback.state.PlaybackStateManager
import org.oxycblt.auxio.util.getSystemServiceCompat
import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.fs.Location
import org.oxycblt.musikr.fs.MusicLocation
import org.oxycblt.musikr.track.UpdateTracker
import timber.log.Timber as L
@@ -168,7 +168,7 @@ private constructor(
}
}
override fun onUpdate(location: Location.Opened) {
override fun onUpdate(location: MusicLocation) {
if (musicSettings.shouldBeObserving) {
musicRepository.requestIndex(true)
}
@@ -1,59 +0,0 @@
/*
* Copyright (c) 2025 Auxio Project
* WriteOnlyFileTreeCache.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.music.shim
import android.net.Uri
import org.oxycblt.musikr.fs.device.CachedDirectory
import org.oxycblt.musikr.fs.device.CachedFile
import org.oxycblt.musikr.fs.device.FileTree
import org.oxycblt.musikr.fs.device.FileTreeCache
class WriteOnlyFileTreeCache(private val inner: FileTreeCache) : FileTreeCache {
override fun read(): FileTree {
val innerTree = inner.read()
return WriteOnlyFileTree(innerTree)
}
}
class WriteOnlyFileTree(private val innerTree: FileTree) : FileTree {
override suspend fun queryDirectory(uri: Uri): CachedDirectory? {
// Always return null to simulate a cache miss
return null
}
override suspend fun updateDirectory(uri: Uri, directory: CachedDirectory) {
// Forward update operations to the inner tree
innerTree.updateDirectory(uri, directory)
}
override suspend fun queryFile(uri: Uri): CachedFile? {
// Always return null to simulate a cache miss
return null
}
override suspend fun updateFile(uri: Uri, file: CachedFile) {
// Forward update operations to the inner tree
innerTree.updateFile(uri, file)
}
override suspend fun write() {
// Forward write operations to the inner tree
innerTree.write()
}
}
@@ -51,15 +51,9 @@ class RootPreferenceFragment : BasePreferenceFragment(R.xml.preferences_root) {
}
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
when (preference.key) {
getString(R.string.set_key_music_dirs) -> {
findNavController()
.navigateSafe(RootPreferenceFragmentDirections.musicLocationsSettings())
}
getString(R.string.set_key_excluded_dirs) -> {
findNavController()
.navigateSafe(RootPreferenceFragmentDirections.excludedLocationsSettings())
}
if (preference.key == getString(R.string.set_key_music_dirs)) {
findNavController()
.navigateSafe(RootPreferenceFragmentDirections.musicLocationsSettings())
}
}