all: reformat
This commit is contained in:
@@ -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