all: reformat
This commit is contained in:
@@ -395,8 +395,7 @@ constructor(
|
|||||||
val storage = Storage(cache, covers, storedPlaylists)
|
val storage = Storage(cache, covers, storedPlaylists)
|
||||||
val query = Query(source = locations, exclude = emptyList())
|
val query = Query(source = locations, exclude = emptyList())
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ 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(
|
||||||
|
|||||||
@@ -116,27 +116,25 @@ 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
|
var exploredCount = 0
|
||||||
) = coroutineScope {
|
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) }
|
LibraryResultImpl(storage, library)
|
||||||
val library = evaluateStep.evaluate(extracted)
|
}
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,20 +28,18 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.asFlow
|
import kotlinx.coroutines.flow.asFlow
|
||||||
import kotlinx.coroutines.flow.emitAll
|
import kotlinx.coroutines.flow.emitAll
|
||||||
import org.oxycblt.musikr.Query
|
|
||||||
import kotlinx.coroutines.flow.flatMapMerge
|
import kotlinx.coroutines.flow.flatMapMerge
|
||||||
import kotlinx.coroutines.flow.flattenMerge
|
import kotlinx.coroutines.flow.flattenMerge
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import org.oxycblt.musikr.Query
|
||||||
import org.oxycblt.musikr.fs.Path
|
import org.oxycblt.musikr.fs.Path
|
||||||
|
|
||||||
internal interface DeviceFS {
|
internal interface DeviceFS {
|
||||||
fun explore(query: Query): Flow<DeviceFile>
|
fun explore(query: Query): Flow<DeviceFile>
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +57,6 @@ private class DeviceFSImpl(
|
|||||||
null)
|
null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun exploreDirectoryImpl(
|
private fun exploreDirectoryImpl(
|
||||||
rootUri: Uri,
|
rootUri: Uri,
|
||||||
treeDocumentId: String,
|
treeDocumentId: String,
|
||||||
@@ -97,8 +94,7 @@ private class DeviceFSImpl(
|
|||||||
|
|
||||||
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
|
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
|
||||||
recursive.add(
|
recursive.add(
|
||||||
exploreDirectoryImpl(rootUri, childId, newPath, directoryDeferred)
|
exploreDirectoryImpl(rootUri, childId, newPath, directoryDeferred))
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
val size = cursor.getLong(sizeIndex)
|
val size = cursor.getLong(sizeIndex)
|
||||||
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
val childUri = DocumentsContract.buildDocumentUriUsingTree(rootUri, childId)
|
||||||
@@ -109,8 +105,7 @@ private class DeviceFSImpl(
|
|||||||
path = newPath,
|
path = newPath,
|
||||||
size = size,
|
size = size,
|
||||||
modifiedMs = lastModified,
|
modifiedMs = lastModified,
|
||||||
parent = directoryDeferred
|
parent = directoryDeferred)
|
||||||
)
|
|
||||||
children.add(file)
|
children.add(file)
|
||||||
emit(file)
|
emit(file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import kotlinx.coroutines.flow.asFlow
|
|||||||
import kotlinx.coroutines.flow.buffer
|
import kotlinx.coroutines.flow.buffer
|
||||||
import kotlinx.coroutines.flow.emitAll
|
import kotlinx.coroutines.flow.emitAll
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.flatMapMerge
|
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
@@ -40,7 +39,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.playlist.db.StoredPlaylists
|
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||||
import org.oxycblt.musikr.playlist.m3u.M3U
|
import org.oxycblt.musikr.playlist.m3u.M3U
|
||||||
@@ -51,9 +49,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.storedPlaylists)
|
storage.storedPlaylists)
|
||||||
|
|||||||
Reference in New Issue
Block a user