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