all: track correct fs backend
This commit is contained in:
@@ -42,7 +42,7 @@ import org.oxycblt.musikr.Playlist
|
||||
import org.oxycblt.musikr.Song
|
||||
import org.oxycblt.musikr.Storage
|
||||
import org.oxycblt.musikr.cache.MutableCache
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStore
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||
import org.oxycblt.musikr.tag.interpret.Naming
|
||||
@@ -397,7 +397,7 @@ constructor(
|
||||
when (musicSettings.locationMode) {
|
||||
LocationMode.SAF -> SAF.from(context, musicSettings.safQuery)
|
||||
LocationMode.MEDIA_STORE ->
|
||||
MediaStoreFS.from(context, musicSettings.mediaStoreQuery)
|
||||
MediaStore.from(context, musicSettings.mediaStoreQuery)
|
||||
}
|
||||
val storage = Storage(cache, covers, storedPlaylists)
|
||||
val interpretation = Interpretation(nameFactory, separators)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* 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
|
||||
|
||||
import android.content.Context
|
||||
@@ -30,7 +30,7 @@ import org.oxycblt.auxio.music.locations.LocationMode
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
import org.oxycblt.musikr.fs.Location
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStore
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
import timber.log.Timber as L
|
||||
|
||||
@@ -50,7 +50,7 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
||||
var safQuery: SAF.Query
|
||||
|
||||
/** The currently configured MediaStore query (if any) * */
|
||||
var mediaStoreQuery: MediaStoreFS.Query
|
||||
var mediaStoreQuery: MediaStore.Query
|
||||
|
||||
/** Whether to be actively watching for changes in the music library. */
|
||||
val shouldBeObserving: Boolean
|
||||
@@ -115,8 +115,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
get() {
|
||||
val mode =
|
||||
sharedPreferences.getInt(
|
||||
getString(R.string.set_key_locations_mode), IntegerTable.LOCATION_MODE_SAF
|
||||
)
|
||||
getString(R.string.set_key_locations_mode), IntegerTable.LOCATION_MODE_SAF)
|
||||
return LocationMode.fromInt(mode) ?: LocationMode.SAF
|
||||
}
|
||||
set(value) {
|
||||
@@ -130,22 +129,19 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
get() {
|
||||
val locations =
|
||||
unlikelyToBeNull(
|
||||
sharedPreferences
|
||||
.getString(getString(R.string.set_key_music_locations), "")
|
||||
.also { L.d("$it") })
|
||||
sharedPreferences
|
||||
.getString(getString(R.string.set_key_music_locations), "")
|
||||
.also { L.d("$it") })
|
||||
.toOpenedLocations()
|
||||
val excludedLocations =
|
||||
unlikelyToBeNull(
|
||||
sharedPreferences.getString(
|
||||
getString(R.string.set_key_excluded_locations), ""
|
||||
)
|
||||
)
|
||||
sharedPreferences.getString(
|
||||
getString(R.string.set_key_excluded_locations), ""))
|
||||
.toUnopenedLocations()
|
||||
val withHidden =
|
||||
sharedPreferences.getBoolean(getString(R.string.set_key_with_hidden), false)
|
||||
return SAF.Query(
|
||||
source = locations, exclude = excludedLocations, withHidden = withHidden
|
||||
)
|
||||
source = locations, exclude = excludedLocations, withHidden = withHidden)
|
||||
}
|
||||
set(value) {
|
||||
sharedPreferences.edit {
|
||||
@@ -156,44 +152,39 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
}
|
||||
}
|
||||
|
||||
override var mediaStoreQuery: MediaStoreFS.Query
|
||||
override var mediaStoreQuery: MediaStore.Query
|
||||
get() {
|
||||
val filterMode =
|
||||
sharedPreferences.getInt(
|
||||
getString(R.string.set_key_filter_mode), IntegerTable.FILTER_MODE_EXCLUDE
|
||||
)
|
||||
getString(R.string.set_key_filter_mode), IntegerTable.FILTER_MODE_EXCLUDE)
|
||||
val filteredLocations =
|
||||
unlikelyToBeNull(
|
||||
sharedPreferences.getString(
|
||||
getString(R.string.set_key_filtered_locations), ""
|
||||
)
|
||||
)
|
||||
sharedPreferences.getString(
|
||||
getString(R.string.set_key_filtered_locations), ""))
|
||||
.toUnopenedLocations()
|
||||
val excludeNonMusic =
|
||||
sharedPreferences.getBoolean(getString(R.string.set_key_exclude_non_music), true)
|
||||
L.d("${excludeNonMusic}")
|
||||
return MediaStoreFS.Query(
|
||||
return MediaStore.Query(
|
||||
mode =
|
||||
when (filterMode) {
|
||||
IntegerTable.FILTER_MODE_INCLUDE -> MediaStoreFS.FilterMode.INCLUDE
|
||||
IntegerTable.FILTER_MODE_EXCLUDE -> MediaStoreFS.FilterMode.EXCLUDE
|
||||
else -> MediaStoreFS.FilterMode.EXCLUDE
|
||||
IntegerTable.FILTER_MODE_INCLUDE -> MediaStore.FilterMode.INCLUDE
|
||||
IntegerTable.FILTER_MODE_EXCLUDE -> MediaStore.FilterMode.EXCLUDE
|
||||
else -> MediaStore.FilterMode.EXCLUDE
|
||||
},
|
||||
filtered = filteredLocations,
|
||||
excludeNonMusic = excludeNonMusic
|
||||
)
|
||||
excludeNonMusic = excludeNonMusic)
|
||||
}
|
||||
set(value) {
|
||||
sharedPreferences.edit {
|
||||
val filterMode =
|
||||
when (value.mode) {
|
||||
MediaStoreFS.FilterMode.INCLUDE -> IntegerTable.FILTER_MODE_INCLUDE
|
||||
MediaStoreFS.FilterMode.EXCLUDE -> IntegerTable.FILTER_MODE_EXCLUDE
|
||||
MediaStore.FilterMode.INCLUDE -> IntegerTable.FILTER_MODE_INCLUDE
|
||||
MediaStore.FilterMode.EXCLUDE -> IntegerTable.FILTER_MODE_EXCLUDE
|
||||
}
|
||||
putInt(getString(R.string.set_key_filter_mode), filterMode)
|
||||
putString(
|
||||
getString(R.string.set_key_filtered_locations), value.filtered.stringify()
|
||||
)
|
||||
getString(R.string.set_key_filtered_locations), value.filtered.stringify())
|
||||
putBoolean(getString(R.string.set_key_exclude_non_music), value.excludeNonMusic)
|
||||
apply()
|
||||
}
|
||||
@@ -208,19 +199,16 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
L.d("Dispatching music locations change")
|
||||
listener.onMusicLocationsChanged()
|
||||
}
|
||||
|
||||
getString(R.string.set_key_excluded_locations),
|
||||
getString(R.string.set_key_with_hidden),
|
||||
getString(R.string.set_key_filter_mode),
|
||||
getString(R.string.set_key_filtered_locations),
|
||||
getString(R.string.set_key_exclude_non_music),
|
||||
getString(R.string.set_key_separators),
|
||||
getString(R.string.set_key_auto_sort_names),
|
||||
-> {
|
||||
getString(R.string.set_key_auto_sort_names), -> {
|
||||
L.d("Dispatching indexing setting change for $key")
|
||||
listener.onIndexingSettingChanged()
|
||||
}
|
||||
|
||||
getString(R.string.set_key_observing) -> {
|
||||
L.d("Dispatching observing setting change")
|
||||
listener.onObservingChanged()
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
||||
import org.oxycblt.auxio.util.getAttrColorCompat
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.musikr.fs.Location
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStoreFS
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStore
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
import timber.log.Timber as L
|
||||
|
||||
@@ -251,7 +251,7 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
||||
L.d("${query.excludeNonMusic}")
|
||||
binding.locationsExcludeNonMusic.isChecked = query.excludeNonMusic
|
||||
|
||||
isIncludeMode = query.mode == MediaStoreFS.FilterMode.INCLUDE
|
||||
isIncludeMode = query.mode == MediaStore.FilterMode.INCLUDE
|
||||
binding.locationsExcludeModeGroup.check(
|
||||
if (isIncludeMode) R.id.locations_exclude_mode_exclude
|
||||
else R.id.locations_exclude_mode_include)
|
||||
@@ -509,13 +509,13 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
||||
// System database mode - create and save MediaStore query
|
||||
val filterMode =
|
||||
if (isIncludeMode) {
|
||||
MediaStoreFS.FilterMode.INCLUDE
|
||||
MediaStore.FilterMode.INCLUDE
|
||||
} else {
|
||||
MediaStoreFS.FilterMode.EXCLUDE
|
||||
MediaStore.FilterMode.EXCLUDE
|
||||
}
|
||||
|
||||
val mediaStoreQuery =
|
||||
MediaStoreFS.Query(
|
||||
MediaStore.Query(
|
||||
mode = filterMode,
|
||||
filtered = filterLocationAdapter.locations,
|
||||
excludeNonMusic = binding.locationsExcludeNonMusic.isChecked)
|
||||
|
||||
@@ -32,9 +32,11 @@ import org.oxycblt.auxio.ForegroundServiceNotification
|
||||
import org.oxycblt.auxio.music.IndexingState
|
||||
import org.oxycblt.auxio.music.MusicRepository
|
||||
import org.oxycblt.auxio.music.MusicSettings
|
||||
import org.oxycblt.auxio.music.locations.LocationMode
|
||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||
import org.oxycblt.auxio.util.getSystemServiceCompat
|
||||
import org.oxycblt.musikr.MusicParent
|
||||
import org.oxycblt.musikr.fs.mediastore.MediaStore
|
||||
import org.oxycblt.musikr.fs.saf.SAF
|
||||
import timber.log.Timber as L
|
||||
|
||||
@@ -159,15 +161,14 @@ private constructor(
|
||||
|
||||
private fun startTracking() {
|
||||
stopTracking()
|
||||
val safQuery = musicSettings.safQuery
|
||||
if (safQuery == null || safQuery.source.isEmpty()) return
|
||||
|
||||
val fs = when (musicSettings.locationMode) {
|
||||
LocationMode.MEDIA_STORE -> MediaStore.from(workerContext, musicSettings.mediaStoreQuery)
|
||||
LocationMode.SAF -> SAF.from(workerContext, musicSettings.safQuery)
|
||||
}
|
||||
trackingJob =
|
||||
indexScope.launch {
|
||||
SAF.from(workerContext, safQuery).track().collect {
|
||||
if (musicSettings.shouldBeObserving) {
|
||||
musicRepository.requestIndex(true)
|
||||
}
|
||||
fs.track().collect {
|
||||
requestIndex(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.oxycblt.musikr.fs.mediastore
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore as AOSPMediaStore
|
||||
import androidx.core.database.getStringOrNull
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@@ -45,7 +45,7 @@ import org.oxycblt.musikr.fs.track.LocationObserver
|
||||
* MediaStore implementation of [FS] that queries the Android MediaStore database for audio files
|
||||
* and yields them as [File] instances.
|
||||
*/
|
||||
class MediaStoreFS
|
||||
class MediaStore
|
||||
private constructor(
|
||||
private val context: Context,
|
||||
private val volumeManager: VolumeManager,
|
||||
@@ -61,7 +61,7 @@ private constructor(
|
||||
|
||||
// Filter out audio that is not music, if enabled
|
||||
if (query.excludeNonMusic) {
|
||||
selector += " AND ${MediaStore.Audio.AudioColumns.IS_MUSIC}=1"
|
||||
selector += " AND ${AOSPMediaStore.Audio.AudioColumns.IS_MUSIC}=1"
|
||||
}
|
||||
|
||||
// Handle include/exclude directories
|
||||
@@ -88,17 +88,17 @@ private constructor(
|
||||
val allFiles = mutableListOf<File>()
|
||||
|
||||
context.contentResolverSafe.useQuery(
|
||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
projection,
|
||||
selector,
|
||||
args.toTypedArray()) { cursor ->
|
||||
val pathInterpreter = pathInterpreterFactory.wrap(cursor)
|
||||
val idIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns._ID)
|
||||
val idIndex = cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns._ID)
|
||||
val mimeTypeIndex =
|
||||
cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
val sizeIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.SIZE)
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
val sizeIndex = cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.SIZE)
|
||||
val dateModifiedIndex =
|
||||
cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DATE_MODIFIED)
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.DATE_MODIFIED)
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
val path = pathInterpreter.extract() ?: continue
|
||||
@@ -106,7 +106,7 @@ private constructor(
|
||||
val id = cursor.getLong(idIndex)
|
||||
val uri =
|
||||
Uri.withAppendedPath(
|
||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id.toString())
|
||||
AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id.toString())
|
||||
val mimeType = cursor.getStringOrNull(mimeTypeIndex) ?: "audio/*"
|
||||
val size = cursor.getLong(sizeIndex)
|
||||
val dateModified =
|
||||
@@ -135,7 +135,7 @@ private constructor(
|
||||
|
||||
override fun track(): Flow<FSUpdate> = callbackFlow {
|
||||
val observer =
|
||||
LocationObserver(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI) {
|
||||
LocationObserver(context, AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI) {
|
||||
trySend(FSUpdate.LocationChanged(null))
|
||||
}
|
||||
awaitClose { observer.release() }
|
||||
@@ -230,21 +230,21 @@ private constructor(
|
||||
|
||||
companion object {
|
||||
fun from(context: Context, query: Query) =
|
||||
MediaStoreFS(
|
||||
MediaStore(
|
||||
context = context, volumeManager = VolumeManager.from(context), query = query)
|
||||
|
||||
/**
|
||||
* The base selector that works across all versions of android. Excludes files with zero
|
||||
* size.
|
||||
*/
|
||||
private const val BASE_SELECTOR = "NOT ${MediaStore.Audio.Media.SIZE}=0"
|
||||
private const val BASE_SELECTOR = "NOT ${AOSPMediaStore.Audio.Media.SIZE}=0"
|
||||
|
||||
/** The base projection that works across all versions of android. */
|
||||
private val BASE_PROJECTION =
|
||||
arrayOf(
|
||||
MediaStore.Audio.AudioColumns._ID,
|
||||
MediaStore.Audio.AudioColumns.DATE_MODIFIED,
|
||||
MediaStore.Audio.AudioColumns.SIZE,
|
||||
MediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
AOSPMediaStore.Audio.AudioColumns._ID,
|
||||
AOSPMediaStore.Audio.AudioColumns.DATE_MODIFIED,
|
||||
AOSPMediaStore.Audio.AudioColumns.SIZE,
|
||||
AOSPMediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user