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