Code refactor ArrayList to List

This commit is contained in:
h4h13 2020-02-17 16:50:08 +05:30
parent 67f4b4ecf2
commit 87954b43f2
43 changed files with 236 additions and 305 deletions

View file

@ -29,7 +29,6 @@ import android.os.Environment
import android.os.IBinder
import android.provider.DocumentsContract
import android.provider.MediaStore
import android.util.Log
import android.widget.Toast
import androidx.core.content.ContextCompat
import code.name.monkey.retromusic.loaders.SongLoader
@ -158,7 +157,7 @@ object MusicPlayerRemote {
return cursor.getString(columnIndex)
}
} catch (e: Exception) {
Log.e(TAG, e.message)
println(e.message)
} finally {
cursor?.close()
}
@ -166,65 +165,51 @@ object MusicPlayerRemote {
}
fun getQueueDurationSongs(): Int {
return if (musicService != null) {
musicService!!.playingQueue!!.size
} else -1
return musicService?.playingQueue?.size ?: -1
}
/**
* Async
*/
fun playSongAt(position: Int) {
if (musicService != null) {
musicService!!.playSongAt(position)
}
musicService?.playSongAt(position)
}
fun pauseSong() {
if (musicService != null) {
musicService!!.pause()
}
musicService?.pause()
}
/**
* Async
*/
fun playNextSong() {
if (musicService != null) {
musicService!!.playNextSong(true)
}
musicService?.playNextSong(true)
}
/**
* Async
*/
fun playPreviousSong() {
if (musicService != null) {
musicService!!.playPreviousSong(true)
}
musicService?.playPreviousSong(true)
}
/**
* Async
*/
fun back() {
if (musicService != null) {
musicService!!.back(true)
}
musicService?.back(true)
}
fun resumePlaying() {
if (musicService != null) {
musicService!!.play()
}
musicService?.play()
}
/**
* Async
*/
fun openQueue(queue: ArrayList<Song>, startPosition: Int, startPlaying: Boolean) {
fun openQueue(queue: List<Song>, startPosition: Int, startPlaying: Boolean) {
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
musicService!!.openQueue(queue, startPosition, startPlaying)
musicService?.openQueue(queue, startPosition, startPlaying)
if (PreferenceUtil.getInstance(musicService).isShuffleModeOn)
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
}
@ -233,7 +218,7 @@ object MusicPlayerRemote {
/**
* Async
*/
fun openAndShuffleQueue(queue: ArrayList<Song>, startPlaying: Boolean) {
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
var startPosition = 0
if (queue.isNotEmpty()) {
startPosition = Random().nextInt(queue.size)
@ -246,7 +231,7 @@ object MusicPlayerRemote {
}
private fun tryToHandleOpenPlayingQueue(
queue: ArrayList<Song>,
queue: List<Song>,
startPosition: Int,
startPlaying: Boolean
): Boolean {
@ -275,7 +260,7 @@ object MusicPlayerRemote {
fun cycleRepeatMode(): Boolean {
if (musicService != null) {
musicService!!.cycleRepeatMode()
musicService?.cycleRepeatMode()
return true
}
return false
@ -283,7 +268,7 @@ object MusicPlayerRemote {
fun toggleShuffleMode(): Boolean {
if (musicService != null) {
musicService!!.toggleShuffle()
musicService?.toggleShuffle()
return true
}
return false
@ -300,7 +285,7 @@ object MusicPlayerRemote {
fun playNext(song: Song): Boolean {
if (musicService != null) {
if (playingQueue.size > 0) {
musicService!!.addSong(position + 1, song)
musicService?.addSong(position + 1, song)
} else {
val queue = ArrayList<Song>()
queue.add(song)
@ -316,10 +301,10 @@ object MusicPlayerRemote {
return false
}
fun playNext(songs: ArrayList<Song>): Boolean {
fun playNext(songs: List<Song>): Boolean {
if (musicService != null) {
if (playingQueue.size > 0) {
musicService!!.addSongs(position + 1, songs)
musicService?.addSongs(position + 1, songs)
} else {
openQueue(songs, 0, false)
}
@ -337,7 +322,7 @@ object MusicPlayerRemote {
fun enqueue(song: Song): Boolean {
if (musicService != null) {
if (playingQueue.size > 0) {
musicService!!.addSong(song)
musicService?.addSong(song)
} else {
val queue = ArrayList<Song>()
queue.add(song)
@ -353,10 +338,10 @@ object MusicPlayerRemote {
return false
}
fun enqueue(songs: ArrayList<Song>): Boolean {
fun enqueue(songs: List<Song>): Boolean {
if (musicService != null) {
if (playingQueue.size > 0) {
musicService!!.addSongs(songs)
musicService?.addSongs(songs)
} else {
openQueue(songs, 0, false)
}
@ -407,7 +392,7 @@ object MusicPlayerRemote {
fun playFromUri(uri: Uri) {
if (musicService != null) {
var songs: ArrayList<Song>? = null
var songs: List<Song>? = null
if (uri.scheme != null && uri.authority != null) {
if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
var songId: String? = null
@ -455,6 +440,7 @@ object MusicPlayerRemote {
openQueue(songs, 0, true)
} else {
//TODO the file is not listed in the media store
println("The file is not listed in the media store")
}
}
}