Unify terminology also by renaming DownloadFile.song -> DownloadFile.track

This commit is contained in:
tzugen 2022-03-27 11:35:14 +02:00
parent 2de59b2206
commit e53da92dac
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
18 changed files with 60 additions and 60 deletions

View File

@ -1,5 +1,7 @@
package org.moire.ultrasonic.receiver;
import static org.koin.java.KoinJavaComponent.inject;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -9,8 +11,6 @@ import org.moire.ultrasonic.service.MediaPlayerController;
import kotlin.Lazy;
import static org.koin.java.KoinJavaComponent.inject;
public class A2dpIntentReceiver extends BroadcastReceiver
{
private static final String PLAYSTATUS_RESPONSE = "com.android.music.playstatusresponse";
@ -21,7 +21,7 @@ public class A2dpIntentReceiver extends BroadcastReceiver
{
if (mediaPlayerControllerLazy.getValue().getCurrentPlaying() == null) return;
Track song = mediaPlayerControllerLazy.getValue().getCurrentPlaying().getSong();
Track song = mediaPlayerControllerLazy.getValue().getCurrentPlaying().getTrack();
if (song == null) return;
Intent avrcpIntent = new Intent(PLAYSTATUS_RESPONSE);

View File

@ -234,7 +234,7 @@ public class JukeboxMediaPlayer
List<String> ids = new ArrayList<>();
for (DownloadFile file : downloader.getAll())
{
ids.add(file.getSong().getId());
ids.add(file.getTrack().getId());
}
tasks.add(new SetPlaylist(ids));

View File

@ -18,7 +18,7 @@ public class Scrobbler
{
if (song == null || !ActiveServerProvider.Companion.isScrobblingEnabled()) return;
final String id = song.getSong().getId();
final String id = song.getTrack().getId();
if (id == null) return;
// Avoid duplicate registrations.

View File

@ -180,7 +180,7 @@ public class StreamProxy implements Runnable
{
Timber.i("Streaming song in background");
DownloadFile downloadFile = currentPlaying == null? null : currentPlaying.get();
MusicDirectory.Track song = downloadFile.getSong();
MusicDirectory.Track song = downloadFile.getTrack();
long fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
Timber.i("Streaming fileSize: %d", fileSize);

View File

@ -77,7 +77,7 @@ class TrackViewBinder(
}
} else {
// Minimize or maximize the Text view (if song title is very long)
if (!downloadFile.song.isDirectory) {
if (!downloadFile.track.isDirectory) {
holder.maximizeOrMinimize()
}
}
@ -86,7 +86,7 @@ class TrackViewBinder(
}
holder.itemView.setOnClickListener {
if (checkable && !downloadFile.song.isVideo) {
if (checkable && !downloadFile.track.isVideo) {
val nowChecked = !holder.check.isChecked
holder.isChecked = nowChecked
} else {

View File

@ -67,7 +67,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
isSelected: Boolean = false
) {
val useFiveStarRating = Settings.useFiveStarRating
val song = file.song
val song = file.track
downloadFile = file
entry = song

View File

@ -105,7 +105,7 @@ class NowPlayingFragment : Fragment() {
val file = mediaPlayerController.currentPlaying
if (file != null) {
val song = file.song
val song = file.track
val title = song.title
val artist = song.artist

View File

@ -507,7 +507,7 @@ class PlayerFragment :
val downloadFile = mediaPlayerController.currentPlaying
if (downloadFile != null) {
currentSong = downloadFile.song
currentSong = downloadFile.track
}
if (useFiveStarRating) starMenuItem.isVisible = false
@ -546,7 +546,7 @@ class PlayerFragment :
menuInflater.inflate(R.menu.nowplaying_context, menu)
val song: MusicDirectory.Track?
song = downloadFile.song
song = downloadFile.track
if (song.parent == null) {
val menuItem = menu.findItem(R.id.menu_show_album)
@ -574,7 +574,7 @@ class PlayerFragment :
var track: MusicDirectory.Track? = null
val bundle: Bundle
if (song != null) {
track = song.song
track = song.track
}
when (menuItemId) {
@ -749,7 +749,7 @@ class PlayerFragment :
val tracks: MutableList<MusicDirectory.Track?> = ArrayList()
val downloadServiceSongs = mediaPlayerController.playList
for (downloadFile in downloadServiceSongs) {
val playlistEntry = downloadFile.song
val playlistEntry = downloadFile.track
tracks.add(playlistEntry)
}
shareHandler.createShare(this, tracks, null, cancellationToken)
@ -785,7 +785,7 @@ class PlayerFragment :
ioScope.launch {
val entries = mediaPlayerController.playList.map {
it.song
it.track
}
val musicService = getMusicService()
musicService.createPlaylist(null, playlistName, entries)
@ -903,7 +903,7 @@ class PlayerFragment :
val songRemoved = String.format(
resources.getString(R.string.download_song_removed),
file.song.title
file.track.title
)
Util.toast(context, songRemoved)
@ -980,7 +980,7 @@ class PlayerFragment :
val trackFormat =
String.format(Locale.getDefault(), "%d / %d", currentSongIndex, totalSongs)
if (currentPlaying != null) {
currentSong = currentPlaying!!.song
currentSong = currentPlaying!!.track
songTitleTextView.text = currentSong!!.title
artistTextView.text = currentSong!!.artist
albumTextView.text = currentSong!!.album

View File

@ -360,7 +360,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
when (menuItem.itemId) {
R.id.song_menu_play_now -> {
songs.add(item.song)
songs.add(item.track)
downloadHandler.download(
fragment = this,
append = false,
@ -372,7 +372,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
)
}
R.id.song_menu_play_next -> {
songs.add(item.song)
songs.add(item.track)
downloadHandler.download(
fragment = this,
append = true,
@ -384,7 +384,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
)
}
R.id.song_menu_play_last -> {
songs.add(item.song)
songs.add(item.track)
downloadHandler.download(
fragment = this,
append = true,
@ -396,7 +396,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
)
}
R.id.song_menu_pin -> {
songs.add(item.song)
songs.add(item.track)
toast(
context,
resources.getQuantityString(
@ -408,7 +408,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
downloadBackground(true, songs)
}
R.id.song_menu_download -> {
songs.add(item.song)
songs.add(item.track)
toast(
context,
resources.getQuantityString(
@ -420,7 +420,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
downloadBackground(false, songs)
}
R.id.song_menu_unpin -> {
songs.add(item.song)
songs.add(item.track)
toast(
context,
resources.getQuantityString(
@ -432,7 +432,7 @@ class SearchFragment : MultiListFragment<Identifiable>(), KoinComponent {
mediaPlayerController.unpin(songs)
}
R.id.song_menu_share -> {
songs.add(item.song)
songs.add(item.track)
shareHandler.createShare(this, songs, searchRefresh, cancellationToken!!)
}
}

View File

@ -122,8 +122,8 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
viewAdapter.register(
TrackViewBinder(
onItemClick = { onItemClick(it.song) },
onContextMenuClick = { menu, id -> onContextMenuItemSelected(menu, id.song) },
onItemClick = { onItemClick(it.track) },
onContextMenuClick = { menu, id -> onContextMenuItemSelected(menu, id.track) },
checkable = true,
draggable = false,
context = requireContext(),

View File

@ -38,12 +38,12 @@ import timber.log.Timber
*
*/
class DownloadFile(
val song: MusicDirectory.Track,
val track: MusicDirectory.Track,
save: Boolean
) : KoinComponent, Identifiable {
val partialFile: String
lateinit var completeFile: String
val saveFile: String = FileUtil.getSongFile(song)
val saveFile: String = FileUtil.getSongFile(track)
var shouldSave = save
private var downloadTask: CancellableTask? = null
var isFailed = false
@ -104,7 +104,7 @@ class DownloadFile(
* Returns the effective bit rate.
*/
fun getBitRate(): Int {
return if (song.bitRate == null) desiredBitRate else song.bitRate!!
return if (track.bitRate == null) desiredBitRate else track.bitRate!!
}
@Synchronized
@ -221,7 +221,7 @@ class DownloadFile(
}
override fun toString(): String {
return String.format("DownloadFile (%s)", song)
return String.format("DownloadFile (%s)", track)
}
private inner class DownloadTask : CancellableTask() {
@ -259,7 +259,7 @@ class DownloadFile(
// Some devices seem to throw error on partial file which doesn't exist
val needsDownloading: Boolean
val duration = song.duration
val duration = track.duration
val fileLength = Storage.getFromPath(partialFile)?.length ?: 0
needsDownloading = (
@ -269,7 +269,7 @@ class DownloadFile(
if (needsDownloading) {
// Attempt partial HTTP GET, appending to the file if it exists.
val (inStream, isPartial) = musicService.getDownloadInputStream(
song, fileLength, desiredBitRate, shouldSave
track, fileLength, desiredBitRate, shouldSave
)
inputStream = inStream
@ -293,11 +293,11 @@ class DownloadFile(
if (isCancelled) {
status.postValue(DownloadStatus.CANCELLED)
throw Exception(String.format("Download of '%s' was cancelled", song))
throw Exception(String.format("Download of '%s' was cancelled", track))
}
if (song.artistId != null) {
cacheMetadata(song.artistId!!)
if (track.artistId != null) {
cacheMetadata(track.artistId!!)
}
downloadAndSaveCoverArt()
@ -328,7 +328,7 @@ class DownloadFile(
status.postValue(DownloadStatus.FAILED)
--retryCount
}
Timber.w(all, "Failed to download '%s'.", song)
Timber.w(all, "Failed to download '%s'.", track)
}
} finally {
inputStream.safeClose()
@ -339,7 +339,7 @@ class DownloadFile(
}
override fun toString(): String {
return String.format("DownloadTask (%s)", song)
return String.format("DownloadTask (%s)", track)
}
private fun cacheMetadata(artistId: String) {
@ -367,9 +367,9 @@ class DownloadFile(
private fun downloadAndSaveCoverArt() {
try {
if (!TextUtils.isEmpty(song.coverArt)) {
if (!TextUtils.isEmpty(track.coverArt)) {
// Download the largest size that we can display in the UI
imageLoaderProvider.getImageLoader().cacheCoverArt(song)
imageLoaderProvider.getImageLoader().cacheCoverArt(track)
}
} catch (all: Exception) {
Timber.e(all, "Failed to get cover art.")
@ -392,8 +392,8 @@ class DownloadFile(
}
private fun setProgress(totalBytesCopied: Long) {
if (song.size != null) {
progress.postValue((totalBytesCopied * 100 / song.size!!).toInt())
if (track.size != null) {
progress.postValue((totalBytesCopied * 100 / track.size!!).toInt())
}
}
@ -404,7 +404,7 @@ class DownloadFile(
}
override val id: String
get() = song.id
get() = track.id
companion object {
const val MAX_RETRIES = 5

View File

@ -234,7 +234,7 @@ class Downloader(
get() {
var totalDuration: Long = 0
for (downloadFile in playlist) {
val song = downloadFile.song
val song = downloadFile.track
if (!song.isDirectory) {
if (song.artist != null) {
if (song.duration != null) {
@ -437,17 +437,17 @@ class Downloader(
@Suppress("ReturnCount")
fun getDownloadFileForSong(song: MusicDirectory.Track): DownloadFile {
for (downloadFile in playlist) {
if (downloadFile.song == song) {
if (downloadFile.track == song) {
return downloadFile
}
}
for (downloadFile in activelyDownloading) {
if (downloadFile.song == song) {
if (downloadFile.track == song) {
return downloadFile
}
}
for (downloadFile in downloadQueue) {
if (downloadFile.song == song) {
if (downloadFile.track == song) {
return downloadFile
}
}

View File

@ -303,7 +303,7 @@ class LocalMediaPlayer : KoinComponent {
val playerDuration: Int
get() {
if (currentPlaying != null) {
val duration = currentPlaying!!.song.duration
val duration = currentPlaying!!.track.duration
if (duration != null) {
return duration * 1000
}
@ -391,7 +391,7 @@ class LocalMediaPlayer : KoinComponent {
setPlayerState(PlayerState.PREPARING, downloadFile)
mediaPlayer.setOnBufferingUpdateListener { mp, percent ->
val song = downloadFile.song
val song = downloadFile.track
if (percent == 100) {
mp.setOnBufferingUpdateListener(null)
@ -512,8 +512,8 @@ class LocalMediaPlayer : KoinComponent {
}
var duration = 0
if (downloadFile.song.duration != null) {
duration = downloadFile.song.duration!! * 1000
if (downloadFile.track.duration != null) {
duration = downloadFile.track.duration!! * 1000
}
mediaPlayer.setOnCompletionListener(object : OnCompletionListener {

View File

@ -453,7 +453,7 @@ class MediaPlayerController(
fun toggleSongStarred() {
if (localMediaPlayer.currentPlaying == null) return
val song = localMediaPlayer.currentPlaying!!.song
val song = localMediaPlayer.currentPlaying!!.track
Thread {
val musicService = getMusicService()
@ -477,7 +477,7 @@ class MediaPlayerController(
fun setSongRating(rating: Int) {
if (!Settings.useFiveStarRating) return
if (localMediaPlayer.currentPlaying == null) return
val song = localMediaPlayer.currentPlaying!!.song
val song = localMediaPlayer.currentPlaying!!.track
song.userRating = rating
Thread {
try {

View File

@ -364,7 +364,7 @@ class MediaPlayerService : Service() {
Settings.isNotificationAlwaysEnabled
val show = playerState === PlayerState.STARTED || showWhenPaused
val song = currentPlaying?.song
val song = currentPlaying?.track
if (isStateChanged) {
when {
@ -396,7 +396,7 @@ class MediaPlayerService : Service() {
}
if (isTrackChanged) {
Util.broadcastNewTrackInfo(this@MediaPlayerService, currentPlaying?.song)
Util.broadcastNewTrackInfo(this@MediaPlayerService, currentPlaying?.track)
}
// Update widget
@ -424,7 +424,7 @@ class MediaPlayerService : Service() {
val index = downloader.currentPlayingIndex
if (currentPlaying != null) {
val song = currentPlaying.song
val song = currentPlaying.track
if (song.bookmarkPosition > 0 && Settings.shouldClearBookmark) {
val musicService = getMusicService()
try {
@ -523,7 +523,7 @@ class MediaPlayerService : Service() {
// Init
val context = applicationContext
val song = currentPlaying?.song
val song = currentPlaying?.track
val stopIntent = Util.getPendingIntentForMediaAction(
context,
KeyEvent.KEYCODE_MEDIA_STOP,

View File

@ -61,7 +61,7 @@ class PlaybackStateSerializer : KoinComponent {
val state = State()
for (downloadFile in songs) {
state.songs.add(downloadFile.song)
state.songs.add(downloadFile.track)
}
state.currentPlayingIndex = currentPlayingIndex

View File

@ -188,7 +188,7 @@ class MediaSessionHandler : KoinComponent {
val metadata = MediaMetadataCompat.Builder()
if (currentPlaying != null) {
try {
val song = currentPlaying.song
val song = currentPlaying.track
val cover = BitmapUtils.getAlbumArtBitmapFromDisk(
song, Util.getMinDisplayMetric()
)
@ -278,7 +278,7 @@ class MediaSessionHandler : KoinComponent {
val queue = playlist.mapIndexed { id, file ->
MediaSessionCompat.QueueItem(
Util.getMediaDescriptionForEntry(file.song),
Util.getMediaDescriptionForEntry(file.track),
id.toLong()
)
}

View File

@ -478,7 +478,7 @@ object Util {
var song: MusicDirectory.Track? = null
val avrcpIntent = Intent(CM_AVRCP_METADATA_CHANGED)
if (currentPlaying != null) song = currentPlaying.song
if (currentPlaying != null) song = currentPlaying.track
fillIntent(avrcpIntent, song, playerPosition, id, listSize)