Code Cleanup

This commit is contained in:
Prathamesh More 2022-04-13 00:03:27 +05:30
parent 818703c573
commit ad90694879
61 changed files with 236 additions and 495 deletions

View file

@ -1,3 +1,5 @@
@file:Suppress("unused")
package code.name.monkey.retromusic.cast
import android.content.Context

View file

@ -3,7 +3,7 @@ package code.name.monkey.retromusic.cast
import com.google.android.gms.cast.framework.CastSession
import com.google.android.gms.cast.framework.SessionManagerListener
interface RetroSessionManager : SessionManagerListener<CastSession> {
interface RetroSessionManagerListener : SessionManagerListener<CastSession> {
override fun onSessionResuming(p0: CastSession, p1: String) {
}

View file

@ -26,15 +26,9 @@ class RetroWebServer(val context: Context) : NanoHTTPD(SERVER_PORT) {
}
}
override fun serve(
uri: String?,
method: Method?,
headers: MutableMap<String, String>?,
parms: MutableMap<String, String>?,
files: MutableMap<String, String>?
): Response {
if (uri?.contains(PART_COVER_ART) == true) {
val albumId = parms?.get(PARAM_ID) ?: return errorResponse()
override fun serve(session: IHTTPSession?): Response {
if (session?.uri?.contains(PART_COVER_ART) == true) {
val albumId = session.parameters?.get(PARAM_ID)?.get(0) ?: return errorResponse()
val albumArtUri = MusicUtil.getMediaStoreAlbumCoverUri(albumId.toLong())
val fis: InputStream?
try {
@ -43,12 +37,12 @@ class RetroWebServer(val context: Context) : NanoHTTPD(SERVER_PORT) {
return errorResponse()
}
return newChunkedResponse(Status.OK, MIME_TYPE_IMAGE, fis)
} else if (uri?.contains(PART_SONG) == true) {
val songId = parms?.get(PARAM_ID) ?: return errorResponse()
} else if (session?.uri?.contains(PART_SONG) == true) {
val songId = session.parameters?.get(PARAM_ID)?.get(0) ?: return errorResponse()
val songUri = MusicUtil.getSongFileUri(songId.toLong())
val songPath = MusicUtil.getSongFilePath(context, songUri)
val song = File(songPath)
return serveFile(headers!!, song, MIME_TYPE_AUDIO)
return serveFile(session.headers!!, song, MIME_TYPE_AUDIO)
}
return newFixedLengthResponse(Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found")
}