all: reformat

This commit is contained in:
Alexander Capehart 2024-06-08 19:20:18 -06:00
parent 8b2634df4d
commit d906b87d76
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -20,6 +20,12 @@ package org.oxycblt.auxio.music.external
import android.content.Context import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStream
import java.io.InputStreamReader
import java.io.OutputStream
import javax.inject.Inject
import org.oxycblt.auxio.music.Playlist import org.oxycblt.auxio.music.Playlist
import org.oxycblt.auxio.music.fs.Components import org.oxycblt.auxio.music.fs.Components
import org.oxycblt.auxio.music.fs.Path import org.oxycblt.auxio.music.fs.Path
@ -29,12 +35,6 @@ import org.oxycblt.auxio.music.metadata.correctWhitespace
import org.oxycblt.auxio.music.resolveNames import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.util.logE import org.oxycblt.auxio.util.logE
import org.oxycblt.auxio.util.unlikelyToBeNull import org.oxycblt.auxio.util.unlikelyToBeNull
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStream
import java.io.InputStreamReader
import java.io.OutputStream
import javax.inject.Inject
/** /**
* Minimal M3U file format implementation. * Minimal M3U file format implementation.
@ -75,7 +75,9 @@ interface M3U {
} }
} }
class M3UImpl @Inject constructor( class M3UImpl
@Inject
constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
private val volumeManager: VolumeManager private val volumeManager: VolumeManager
) : M3U { ) : M3U {
@ -122,9 +124,8 @@ class M3UImpl @Inject constructor(
// based on the programs that generated it. I more or less have to consider any possible // based on the programs that generated it. I more or less have to consider any possible
// interpretation as valid. // interpretation as valid.
val interpretations = interpretPath(path) val interpretations = interpretPath(path)
val possibilities = interpretations.flatMap { val possibilities =
expandInterpretation(it, workingDirectory, volumes) interpretations.flatMap { expandInterpretation(it, workingDirectory, volumes) }
}
paths.add(possibilities) paths.add(possibilities)
} }
@ -137,49 +138,20 @@ class M3UImpl @Inject constructor(
} }
} }
private data class InterpretedPath( private data class InterpretedPath(val components: Components, val likelyAbsolute: Boolean)
val components: Components,
val likelyAbsolute: Boolean
)
private fun interpretPath(path: String): List<InterpretedPath> = private fun interpretPath(path: String): List<InterpretedPath> =
when { when {
path.startsWith('/') -> path.startsWith('/') -> listOf(InterpretedPath(Components.parseUnix(path), true))
listOf(InterpretedPath(Components.parseUnix(path), true)) path.startsWith("./") -> listOf(InterpretedPath(Components.parseUnix(path), false))
path.matches(WINDOWS_VOLUME_PREFIX_REGEX) ->
path.startsWith("./") -> listOf( listOf(InterpretedPath(Components.parseWindows(path.substring(2)), true))
InterpretedPath( path.startsWith("\\") -> listOf(InterpretedPath(Components.parseWindows(path), true))
Components.parseUnix(path), path.startsWith(".\\") -> listOf(InterpretedPath(Components.parseWindows(path), false))
false else ->
) listOf(
)
path.matches(WINDOWS_VOLUME_PREFIX_REGEX) -> listOf(
InterpretedPath(
Components.parseWindows(
path.substring(2)
), true
)
)
path.startsWith("\\") -> listOf(
InterpretedPath(
Components.parseWindows(path),
true
)
)
path.startsWith(".\\") -> listOf(
InterpretedPath(
Components.parseWindows(path),
false
)
)
else -> listOf(
InterpretedPath(Components.parseUnix(path), false), InterpretedPath(Components.parseUnix(path), false),
InterpretedPath(Components.parseWindows(path), true) InterpretedPath(Components.parseWindows(path), true))
)
} }
private fun expandInterpretation( private fun expandInterpretation(
@ -191,23 +163,16 @@ class M3UImpl @Inject constructor(
val relativeInterpretation = val relativeInterpretation =
Path(workingDirectory.volume, path.components.absoluteTo(workingDirectory.components)) Path(workingDirectory.volume, path.components.absoluteTo(workingDirectory.components))
val volumeExactMatch = volumes.find { it.components?.contains(path.components) == true } val volumeExactMatch = volumes.find { it.components?.contains(path.components) == true }
val volumeInterpretation = volumeExactMatch?.let { val volumeInterpretation =
val components = unlikelyToBeNull(volumeExactMatch.components) volumeExactMatch?.let {
.containing(path.components) val components =
unlikelyToBeNull(volumeExactMatch.components).containing(path.components)
Path(volumeExactMatch, components) Path(volumeExactMatch, components)
} }
return if (path.likelyAbsolute) { return if (path.likelyAbsolute) {
listOfNotNull( listOfNotNull(volumeInterpretation, absoluteInterpretation, relativeInterpretation)
volumeInterpretation,
absoluteInterpretation,
relativeInterpretation
)
} else { } else {
listOfNotNull( listOfNotNull(relativeInterpretation, volumeInterpretation, absoluteInterpretation)
relativeInterpretation,
volumeInterpretation,
absoluteInterpretation
)
} }
} }