all: reformat
This commit is contained in:
@@ -400,8 +400,7 @@ constructor(
|
||||
val query = Query(source = locations, exclude = emptyList())
|
||||
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
|
||||
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
||||
val result =
|
||||
Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
|
||||
val result = Musikr.new(context, storage, interpretation).run(query, ::emitIndexingProgress)
|
||||
// Music loading completed, update the revision right now so we re-use this work
|
||||
// later.
|
||||
musicSettings.revision = newRevision
|
||||
|
||||
@@ -85,8 +85,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
}
|
||||
set(value) {
|
||||
sharedPreferences.edit {
|
||||
putString(
|
||||
getString(R.string.set_key_music_locations), value.stringify())
|
||||
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.
|
||||
@@ -139,7 +138,6 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun List<OpenedLocation>.stringify(): String =
|
||||
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.oxycblt.auxio.databinding.ItemMusicLocationBinding
|
||||
import org.oxycblt.auxio.list.recycler.DialogRecyclerView
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
import org.oxycblt.musikr.fs.Location
|
||||
import org.oxycblt.musikr.fs.OpenedLocation
|
||||
import timber.log.Timber as L
|
||||
|
||||
@@ -38,7 +37,8 @@ import timber.log.Timber as L
|
||||
class LocationAdapter(private val listener: Listener) : RecyclerView.Adapter<MusicDirViewHolder>() {
|
||||
private val _locations = mutableListOf<OpenedLocation>()
|
||||
/**
|
||||
* The current list of [OpenedLocation]s, may not line up with [OpenedLocation]s due to removals.
|
||||
* The current list of [OpenedLocation]s, may not line up with [OpenedLocation]s due to
|
||||
* removals.
|
||||
*/
|
||||
val locations: List<OpenedLocation> = _locations
|
||||
|
||||
|
||||
@@ -16,4 +16,5 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/locations_list_header"
|
||||
tools:listitem="@layout/item_music_location" />
|
||||
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
@@ -23,16 +23,12 @@ import org.oxycblt.musikr.covers.Cover
|
||||
import org.oxycblt.musikr.covers.MutableCovers
|
||||
import org.oxycblt.musikr.fs.Location
|
||||
import org.oxycblt.musikr.fs.OpenedLocation
|
||||
import org.oxycblt.musikr.fs.Path
|
||||
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
|
||||
|
||||
data class Query(
|
||||
val source: List<OpenedLocation>,
|
||||
val exclude: List<Location>
|
||||
)
|
||||
data class Query(val source: List<OpenedLocation>, val exclude: List<Location>)
|
||||
|
||||
/** Side-effect laden [Storage] for use during music loading and [MutableLibrary] operation. */
|
||||
data class Storage(
|
||||
|
||||
@@ -117,31 +117,29 @@ private class MusikrImpl(
|
||||
private val extractStep: ExtractStep,
|
||||
private val evaluateStep: EvaluateStep
|
||||
) : Musikr {
|
||||
override suspend fun run(
|
||||
query: Query,
|
||||
onProgress: suspend (IndexingProgress) -> Unit
|
||||
) = coroutineScope {
|
||||
val start = System.currentTimeMillis()
|
||||
var exploredCount = 0
|
||||
var extractedCount = 0
|
||||
val explored =
|
||||
exploreStep
|
||||
.explore(query)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onStart { onProgress(IndexingProgress.Songs(0, 0)) }
|
||||
.onEach { onProgress(IndexingProgress.Songs(extractedCount, ++exploredCount)) }
|
||||
val extracted =
|
||||
extractStep
|
||||
.extract(explored)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onEach { onProgress(IndexingProgress.Songs(++extractedCount, exploredCount)) }
|
||||
.onCompletion { onProgress(IndexingProgress.Indeterminate) }
|
||||
val library = evaluateStep.evaluate(extracted)
|
||||
Log.d(
|
||||
"Musikr",
|
||||
"Loaded ${library.songs.size} songs in ${System.currentTimeMillis() - start}ms")
|
||||
LibraryResultImpl(storage, library)
|
||||
}
|
||||
override suspend fun run(query: Query, onProgress: suspend (IndexingProgress) -> Unit) =
|
||||
coroutineScope {
|
||||
val start = System.currentTimeMillis()
|
||||
var exploredCount = 0
|
||||
var extractedCount = 0
|
||||
val explored =
|
||||
exploreStep
|
||||
.explore(query)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onStart { onProgress(IndexingProgress.Songs(0, 0)) }
|
||||
.onEach { onProgress(IndexingProgress.Songs(extractedCount, ++exploredCount)) }
|
||||
val extracted =
|
||||
extractStep
|
||||
.extract(explored)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
.onEach { onProgress(IndexingProgress.Songs(++extractedCount, exploredCount)) }
|
||||
.onCompletion { onProgress(IndexingProgress.Indeterminate) }
|
||||
val library = evaluateStep.evaluate(extracted)
|
||||
Log.d(
|
||||
"Musikr",
|
||||
"Loaded ${library.songs.size} songs in ${System.currentTimeMillis() - start}ms")
|
||||
LibraryResultImpl(storage, library)
|
||||
}
|
||||
}
|
||||
|
||||
private class LibraryResultImpl(
|
||||
|
||||
@@ -37,8 +37,7 @@ class Location private constructor(val uri: Uri, val path: Path) {
|
||||
try {
|
||||
context.contentResolverSafe.takePersistableUriPermission(
|
||||
uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
)
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
} catch (e: Exception) {
|
||||
// Not fully sure what happens if I'm disallowed to take the permission,
|
||||
// check for both circumstances (error or no-op)
|
||||
@@ -68,7 +67,10 @@ class Location private constructor(val uri: Uri, val path: Path) {
|
||||
}
|
||||
|
||||
class OpenedLocation internal constructor(val uri: Uri, val path: Path) {
|
||||
override fun equals(other: Any?) = other is OpenedLocation && uri == other.uri && path == other.path
|
||||
override fun equals(other: Any?) =
|
||||
other is OpenedLocation && uri == other.uri && path == other.path
|
||||
|
||||
override fun hashCode() = 31 * uri.hashCode() + path.hashCode()
|
||||
|
||||
override fun toString(): String = uri.toString()
|
||||
}
|
||||
|
||||
@@ -51,10 +51,8 @@ internal interface DeviceFS {
|
||||
fun explore(query: Query, fileTree: FileTree): Flow<DeviceDirectory>
|
||||
|
||||
companion object {
|
||||
fun from(
|
||||
context: Context,
|
||||
withHidden: Boolean
|
||||
): DeviceFS = DeviceFSImpl(context.contentResolverSafe, withHidden)
|
||||
fun from(context: Context, withHidden: Boolean): DeviceFS =
|
||||
DeviceFSImpl(context.contentResolverSafe, withHidden)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +63,15 @@ private class DeviceFSImpl(
|
||||
private val explorationScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
override fun explore(query: Query, fileTree: FileTree) =
|
||||
query.source.asFlow().mapNotNull { location -> queryRoot(location, fileTree, query.exclude) }
|
||||
query.source.asFlow().mapNotNull { location ->
|
||||
queryRoot(location, fileTree, query.exclude)
|
||||
}
|
||||
|
||||
private suspend fun queryRoot(location: OpenedLocation, fileTree: FileTree, exclude: List<Location>): DeviceDirectory? {
|
||||
private suspend fun queryRoot(
|
||||
location: OpenedLocation,
|
||||
fileTree: FileTree,
|
||||
exclude: List<Location>
|
||||
): DeviceDirectory? {
|
||||
val treeDocumentId = DocumentsContract.getTreeDocumentId(location.uri)
|
||||
val uri = DocumentsContract.buildDocumentUriUsingTree(location.uri, treeDocumentId)
|
||||
val modifiedMs =
|
||||
@@ -82,7 +86,8 @@ private class DeviceFSImpl(
|
||||
if (modifiedMs == null) {
|
||||
return null
|
||||
}
|
||||
return query(location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree, exclude)
|
||||
return query(
|
||||
location.uri, treeDocumentId, location.path, modifiedMs, null, fileTree, exclude)
|
||||
}
|
||||
|
||||
private suspend fun query(
|
||||
@@ -159,7 +164,7 @@ private class DeviceFSImpl(
|
||||
// Check if the current path matches the excluded path
|
||||
// exactly
|
||||
excluded.path.volume == newPath.volume &&
|
||||
excluded.path.components == newPath.components
|
||||
excluded.path.components == newPath.components
|
||||
}
|
||||
if (shouldExclude) {
|
||||
continue
|
||||
@@ -250,7 +255,7 @@ private class DeviceFSImpl(
|
||||
val shouldExclude =
|
||||
exclude.any { excluded ->
|
||||
excluded.path.volume == subdirPath.volume &&
|
||||
excluded.path.components ==
|
||||
excluded.path.components ==
|
||||
subdirPath.components
|
||||
}
|
||||
|
||||
@@ -258,7 +263,9 @@ private class DeviceFSImpl(
|
||||
return@transform
|
||||
}
|
||||
|
||||
emit(hydrateCached(cachedSubdir, dir, subdirPath, fileTree, exclude))
|
||||
emit(
|
||||
hydrateCached(
|
||||
cachedSubdir, dir, subdirPath, fileTree, exclude))
|
||||
}
|
||||
.filterNotNull(),
|
||||
cached.fileUris.asFlow().map {
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.oxycblt.musikr.cache.CachedSong
|
||||
import org.oxycblt.musikr.covers.Cover
|
||||
import org.oxycblt.musikr.covers.CoverResult
|
||||
import org.oxycblt.musikr.covers.Covers
|
||||
import org.oxycblt.musikr.fs.OpenedLocation
|
||||
import org.oxycblt.musikr.fs.device.DeviceFS
|
||||
import org.oxycblt.musikr.fs.device.FileTreeCache
|
||||
import org.oxycblt.musikr.fs.device.flatten
|
||||
@@ -55,9 +54,7 @@ internal interface ExploreStep {
|
||||
companion object {
|
||||
fun from(context: Context, storage: Storage, interpretation: Interpretation): ExploreStep =
|
||||
ExploreStepImpl(
|
||||
DeviceFS.from(
|
||||
context = context,
|
||||
withHidden = interpretation.withHidden),
|
||||
DeviceFS.from(context = context, withHidden = interpretation.withHidden),
|
||||
storage.cache,
|
||||
storage.covers,
|
||||
storage.fileTreeCache,
|
||||
|
||||
Reference in New Issue
Block a user