From d906b87d766d6c2acfacbdf5153a0ec12be2ac0c Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sat, 8 Jun 2024 19:20:18 -0600 Subject: [PATCH] all: reformat --- .../org/oxycblt/auxio/music/external/M3U.kt | 95 ++++++------------- 1 file changed, 30 insertions(+), 65 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/external/M3U.kt b/app/src/main/java/org/oxycblt/auxio/music/external/M3U.kt index 908ced355..211f6cea6 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/external/M3U.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/external/M3U.kt @@ -20,6 +20,12 @@ package org.oxycblt.auxio.music.external import android.content.Context 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.fs.Components 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.util.logE 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. @@ -75,7 +75,9 @@ interface M3U { } } -class M3UImpl @Inject constructor( +class M3UImpl +@Inject +constructor( @ApplicationContext private val context: Context, private val volumeManager: VolumeManager ) : 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 // interpretation as valid. val interpretations = interpretPath(path) - val possibilities = interpretations.flatMap { - expandInterpretation(it, workingDirectory, volumes) - } + val possibilities = + interpretations.flatMap { expandInterpretation(it, workingDirectory, volumes) } paths.add(possibilities) } @@ -137,49 +138,20 @@ class M3UImpl @Inject constructor( } } - private data class InterpretedPath( - val components: Components, - val likelyAbsolute: Boolean - ) + private data class InterpretedPath(val components: Components, val likelyAbsolute: Boolean) private fun interpretPath(path: String): List = when { - path.startsWith('/') -> - listOf(InterpretedPath(Components.parseUnix(path), true)) - - path.startsWith("./") -> listOf( - InterpretedPath( - Components.parseUnix(path), - false - ) - ) - - 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.parseWindows(path), true) - ) + path.startsWith('/') -> listOf(InterpretedPath(Components.parseUnix(path), true)) + path.startsWith("./") -> listOf(InterpretedPath(Components.parseUnix(path), false)) + 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.parseWindows(path), true)) } private fun expandInterpretation( @@ -191,23 +163,16 @@ class M3UImpl @Inject constructor( val relativeInterpretation = Path(workingDirectory.volume, path.components.absoluteTo(workingDirectory.components)) val volumeExactMatch = volumes.find { it.components?.contains(path.components) == true } - val volumeInterpretation = volumeExactMatch?.let { - val components = unlikelyToBeNull(volumeExactMatch.components) - .containing(path.components) - Path(volumeExactMatch, components) - } + val volumeInterpretation = + volumeExactMatch?.let { + val components = + unlikelyToBeNull(volumeExactMatch.components).containing(path.components) + Path(volumeExactMatch, components) + } return if (path.likelyAbsolute) { - listOfNotNull( - volumeInterpretation, - absoluteInterpretation, - relativeInterpretation - ) + listOfNotNull(volumeInterpretation, absoluteInterpretation, relativeInterpretation) } else { - listOfNotNull( - relativeInterpretation, - volumeInterpretation, - absoluteInterpretation - ) + listOfNotNull(relativeInterpretation, volumeInterpretation, absoluteInterpretation) } }