From bfdac03d0c39ee0cef14e59808cb3a0a4ddaa4de Mon Sep 17 00:00:00 2001 From: Ryan Harg <3821-ryan_harg@users.noreply.dev.funkwhale.audio> Date: Fri, 26 Aug 2022 12:06:41 +0000 Subject: [PATCH] Upgrade to Kotlin 1.7.0 --- app/build.gradle.kts | 2 +- .../funkwhale/ffa/activities/MainActivity.kt | 164 ++++++++---------- .../ffa/activities/SearchActivity.kt | 12 +- .../funkwhale/ffa/adapters/RadiosAdapter.kt | 11 +- .../ffa/fragments/FavoritesFragment.kt | 11 +- .../ffa/fragments/LandscapeQueueFragment.kt | 8 +- .../ffa/fragments/PlaylistTracksFragment.kt | 11 +- .../funkwhale/ffa/fragments/QueueFragment.kt | 8 +- .../funkwhale/ffa/fragments/RadiosFragment.kt | 11 +- .../funkwhale/ffa/fragments/TracksFragment.kt | 8 +- .../funkwhale/ffa/playback/PinService.kt | 14 +- .../funkwhale/ffa/playback/PlayerService.kt | 104 +++++------ .../ffa/repositories/PlaylistsRepository.kt | 12 +- .../funkwhale/ffa/repositories/Repository.kt | 2 - .../ffa/repositories/SearchRepository.kt | 10 +- .../audio/funkwhale/ffa/utils/Extensions.kt | 4 +- .../audio/funkwhale/ffa/utils/FFACache.kt | 2 +- .../java/audio/funkwhale/ffa/utils/OAuth.kt | 15 +- build.gradle.kts | 2 +- 19 files changed, 204 insertions(+), 207 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c7cbfa5..ac01d0c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -153,7 +153,7 @@ play { dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar")))) - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.21") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt index aadcac0..14d8939 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt @@ -326,77 +326,67 @@ class MainActivity : AppCompatActivity() { @SuppressLint("NewApi") private fun watchEventBus() { lifecycleScope.launch(Main) { - EventBus.get().collect { message -> - when (message) { - is Event.LogOut -> { - FFA.get().deleteAllData(this@MainActivity) - startActivity( - Intent(this@MainActivity, LoginActivity::class.java).apply { - flags = Intent.FLAG_ACTIVITY_NO_HISTORY - } - ) - - finish() - } - - is Event.PlaybackError -> toast(message.message) - - is Event.Buffering -> { - when (message.value) { - true -> binding.nowPlayingContainer?.nowPlayingBuffering?.visibility = View.VISIBLE - false -> binding.nowPlayingContainer?.nowPlayingBuffering?.visibility = View.GONE + EventBus.get().collect { event -> + if (event is Event.LogOut) { + FFA.get().deleteAllData(this@MainActivity) + startActivity( + Intent(this@MainActivity, LoginActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NO_HISTORY } - } + ) - is Event.PlaybackStopped -> { - if (binding.nowPlaying.visibility == View.VISIBLE) { - (binding.container.layoutParams as? ViewGroup.MarginLayoutParams)?.let { + finish() + } else if (event is Event.PlaybackError) { + toast(event.message) + } else if (event is Event.Buffering) { + when (event.value) { + true -> binding.nowPlayingContainer?.nowPlayingBuffering?.visibility = View.VISIBLE + false -> binding.nowPlayingContainer?.nowPlayingBuffering?.visibility = View.GONE + } + } else if (event is Event.PlaybackStopped) { + if (binding.nowPlaying.visibility == View.VISIBLE) { + (binding.container.layoutParams as? ViewGroup.MarginLayoutParams)?.let { + it.bottomMargin = it.bottomMargin / 2 + } + + binding.landscapeQueue?.let { landscape_queue -> + (landscape_queue.layoutParams as? ViewGroup.MarginLayoutParams)?.let { it.bottomMargin = it.bottomMargin / 2 } + } - binding.landscapeQueue?.let { landscape_queue -> - (landscape_queue.layoutParams as? ViewGroup.MarginLayoutParams)?.let { - it.bottomMargin = it.bottomMargin / 2 + binding.nowPlaying.animate() + .alpha(0.0f) + .setDuration(400) + .setListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animator: Animator?) { + binding.nowPlaying.visibility = View.GONE } - } + }) + .start() + } + } else if (event is Event.TrackFinished) { + incrementListenCount(event.track) + } else if (event is Event.StateChanged) { + when (event.playing) { + true -> { + binding.nowPlayingContainer?.nowPlayingToggle?.icon = getDrawable(R.drawable.pause) + binding.nowPlayingContainer?.nowPlayingDetailsToggle?.icon = + getDrawable(R.drawable.pause) + } - binding.nowPlaying.animate() - .alpha(0.0f) - .setDuration(400) - .setListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animator: Animator?) { - binding.nowPlaying.visibility = View.GONE - } - }) - .start() + false -> { + binding.nowPlayingContainer?.nowPlayingToggle?.icon = getDrawable(R.drawable.play) + binding.nowPlayingContainer?.nowPlayingDetailsToggle?.icon = + getDrawable(R.drawable.play) } } - - is Event.TrackFinished -> incrementListenCount(message.track) - - is Event.StateChanged -> { - when (message.playing) { - true -> { - binding.nowPlayingContainer?.nowPlayingToggle?.icon = getDrawable(R.drawable.pause) - binding.nowPlayingContainer?.nowPlayingDetailsToggle?.icon = - getDrawable(R.drawable.pause) - } - - false -> { - binding.nowPlayingContainer?.nowPlayingToggle?.icon = getDrawable(R.drawable.play) - binding.nowPlayingContainer?.nowPlayingDetailsToggle?.icon = - getDrawable(R.drawable.play) - } - } - } - - is Event.QueueChanged -> { - findViewById(R.id.nav_queue)?.let { view -> - ObjectAnimator.ofFloat(view, View.ROTATION, 0f, 360f).let { - it.duration = 500 - it.interpolator = AccelerateDecelerateInterpolator() - it.start() - } + } else if (event is Event.QueueChanged) { + findViewById(R.id.nav_queue)?.let { view -> + ObjectAnimator.ofFloat(view, View.ROTATION, 0f, 360f).let { + it.duration = 500 + it.interpolator = AccelerateDecelerateInterpolator() + it.start() } } } @@ -405,32 +395,30 @@ class MainActivity : AppCompatActivity() { lifecycleScope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.StartService -> { - Build.VERSION_CODES.O.onApi( - { - startForegroundService( - Intent( - this@MainActivity, - PlayerService::class.java - ).apply { - putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) - } - ) - }, - { - startService( - Intent(this@MainActivity, PlayerService::class.java).apply { - putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) - } - ) - } - ) - } - - is Command.RefreshTrack -> refreshCurrentTrack(command.track) - - is Command.AddToPlaylist -> if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + if (command is Command.StartService) { + Build.VERSION_CODES.O.onApi( + { + startForegroundService( + Intent( + this@MainActivity, + PlayerService::class.java + ).apply { + putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) + } + ) + }, + { + startService( + Intent(this@MainActivity, PlayerService::class.java).apply { + putExtra(PlayerService.INITIAL_COMMAND_KEY, command.command.toString()) + } + ) + } + ) + } else if (command is Command.RefreshTrack) { + refreshCurrentTrack(command.track) + } else if (command is Command.AddToPlaylist) { + if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { AddToPlaylistDialog.show( layoutInflater, this@MainActivity, diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt index d0b8c8b..d5ac646 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/SearchActivity.kt @@ -28,7 +28,6 @@ import audio.funkwhale.ffa.utils.getMetadata import audio.funkwhale.ffa.utils.untilNetwork import com.google.android.exoplayer2.offline.Download import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.net.URLEncoder @@ -65,8 +64,9 @@ class SearchActivity : AppCompatActivity() { lifecycleScope.launch(Dispatchers.Main) { CommandBus.get().collect { command -> - when (command) { - is Command.AddToPlaylist -> if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + if (command is Command.AddToPlaylist) { + + if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { AddToPlaylistDialog.show( layoutInflater, this@SearchActivity, @@ -79,10 +79,8 @@ class SearchActivity : AppCompatActivity() { } lifecycleScope.launch(Dispatchers.IO) { - EventBus.get().collect { message -> - when (message) { - is Event.DownloadChanged -> refreshDownloadedTrack(message.download) - } + EventBus.get().collect { event -> + if (event is Event.DownloadChanged) refreshDownloadedTrack(event.download) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt index cb9dbf9..4dc2765 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/RadiosAdapter.kt @@ -17,7 +17,6 @@ import audio.funkwhale.ffa.views.LoadingImageView import com.preference.PowerPreference import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch class RadiosAdapter( @@ -190,12 +189,10 @@ class RadiosAdapter( art.setColorFilter(context.getColor(R.color.controlForeground)) scope.launch(Main) { - EventBus.get().collect { message -> - when (message) { - is Event.RadioStarted -> { - art.colorFilter = originalColorFilter - LoadingImageView.stop(context, originalDrawable, art, imageAnimator) - } + EventBus.get().collect { event -> + if (event is Event.RadioStarted) { + art.colorFilter = originalColorFilter + LoadingImageView.stop(context, originalDrawable, art, imageAnimator) } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt index 3daf536..bd5b53d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/FavoritesFragment.kt @@ -25,7 +25,6 @@ import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadManager import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koin.java.KoinJavaComponent.inject @@ -84,18 +83,14 @@ class FavoritesFragment : FFAFragment() { private fun watchEventBus() { lifecycleScope.launch(Main) { - EventBus.get().collect { message -> - when (message) { - is Event.DownloadChanged -> refreshDownloadedTrack(message.download) - } + EventBus.get().collect { event -> + if (event is Event.DownloadChanged) refreshDownloadedTrack(event.download) } } lifecycleScope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshTrack -> refreshCurrentTrack(command.track) - } + if (command is Command.RefreshTrack) refreshCurrentTrack(command.track) } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/LandscapeQueueFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/LandscapeQueueFragment.kt index 97a78e8..9087c22 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/LandscapeQueueFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/LandscapeQueueFragment.kt @@ -110,17 +110,13 @@ class LandscapeQueueFragment : Fragment() { private fun watchEventBus() { activity?.lifecycleScope?.launch(Main) { EventBus.get().collect { message -> - when (message) { - is Event.QueueChanged -> refresh() - } + if (message is Event.QueueChanged) refresh() } } activity?.lifecycleScope?.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshTrack -> refresh() - } + if (command is Command.RefreshTrack) refresh() } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt index 5622c7d..f3aa86f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt @@ -75,7 +75,12 @@ class PlaylistTracksFragment : FFAFragment favoritesRepository = FavoritesRepository(context) playlistsRepository = ManagementPlaylistsRepository(context) - adapter = PlaylistTracksAdapter(layoutInflater, context, FavoriteListener(favoritesRepository), PlaylistListener()) + adapter = PlaylistTracksAdapter( + layoutInflater, + context, + FavoriteListener(favoritesRepository), + PlaylistListener() + ) repository = PlaylistTracksRepository(context, albumId) watchEventBus() @@ -199,8 +204,8 @@ class PlaylistTracksFragment : FFAFragment private fun watchEventBus() { lifecycleScope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshTrack -> refreshCurrentTrack(command.track) + if (command is Command.RefreshTrack) { + refreshCurrentTrack(command.track) } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt index 99c5c47..2287e80 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt @@ -127,16 +127,16 @@ class QueueFragment : BottomSheetDialogFragment() { private fun watchEventBus() { lifecycleScope.launch(Main) { EventBus.get().collect { message -> - when (message) { - is Event.QueueChanged -> refresh() + if (message is Event.QueueChanged) { + refresh() } } } lifecycleScope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshTrack -> refresh() + if (command is Command.RefreshTrack) { + refresh() } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt index cf9c764..e14a6a6 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/RadiosFragment.kt @@ -62,12 +62,11 @@ class RadiosFragment : FFAFragment() { lifecycleScope.launch(Main) { EventBus.get().collect { message -> - when (message) { - is Event.RadioStarted -> - recycler.forEach { - it.isEnabled = true - it.isClickable = true - } + if (message is Event.RadioStarted) { + recycler.forEach { + it.isEnabled = true + it.isClickable = true + } } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt index 5e02657..8794a5b 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt @@ -250,16 +250,16 @@ class TracksFragment : FFAFragment() { private fun watchEventBus() { lifecycleScope.launch(IO) { EventBus.get().collect { message -> - when (message) { - is Event.DownloadChanged -> refreshDownloadedTrack(message.download) + if (message is Event.DownloadChanged) { + refreshDownloadedTrack(message.download) } } } lifecycleScope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshTrack -> refreshCurrentTrack(command.track) + if (command is Command.RefreshTrack) { + refreshCurrentTrack(command.track) } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt index 691d637..f3bd1ce 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PinService.kt @@ -7,7 +7,13 @@ import androidx.core.net.toUri import audio.funkwhale.ffa.R import audio.funkwhale.ffa.model.DownloadInfo import audio.funkwhale.ffa.model.Track -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.utils.AppContext +import audio.funkwhale.ffa.utils.Event +import audio.funkwhale.ffa.utils.EventBus +import audio.funkwhale.ffa.utils.Request +import audio.funkwhale.ffa.utils.RequestBus +import audio.funkwhale.ffa.utils.Response +import audio.funkwhale.ffa.utils.mustNormalizeUrl import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadRequest @@ -20,7 +26,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job import kotlinx.coroutines.launch import org.koin.java.KoinJavaComponent -import java.util.* +import java.util.Collections class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { @@ -57,8 +63,8 @@ class PinService : DownloadService(AppContext.NOTIFICATION_DOWNLOADS) { scope.launch(Main) { RequestBus.get().collect { request -> - when (request) { - is Request.GetDownloads -> request.channel?.trySend(Response.Downloads(getDownloads()))?.isSuccess + if (request is Request.GetDownloads) { + request.channel?.trySend(Response.Downloads(getDownloads()))?.isSuccess } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt index 2254476..9c74da5 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/PlayerService.kt @@ -171,61 +171,59 @@ class PlayerService : Service() { private fun watchEventBus() { scope.launch(Main) { CommandBus.get().collect { command -> - when (command) { - is Command.RefreshService -> { - if (queue.metadata.isNotEmpty()) { - CommandBus.send(Command.RefreshTrack(queue.current())) - EventBus.send(Event.StateChanged(player.playWhenReady)) - } - } - - is Command.ReplaceQueue -> { - if (!command.fromRadio) radioPlayer.stop() - - queue.replace(command.queue) - player.prepare(queue.dataSources, true, true) - - setPlaybackState(true) - + if (command is Command.RefreshService) { + if (queue.metadata.isNotEmpty()) { CommandBus.send(Command.RefreshTrack(queue.current())) + EventBus.send(Event.StateChanged(player.playWhenReady)) } + } else if (command is Command.ReplaceQueue) { + if (!command.fromRadio) radioPlayer.stop() - is Command.AddToQueue -> queue.append(command.tracks) - is Command.PlayNext -> queue.insertNext(command.track) - is Command.RemoveFromQueue -> queue.remove(command.track) - is Command.MoveFromQueue -> queue.move(command.oldPosition, command.newPosition) + queue.replace(command.queue) + player.prepare(queue.dataSources, true, true) - is Command.PlayTrack -> { - queue.current = command.index - player.seekTo(command.index, C.TIME_UNSET) + setPlaybackState(true) - setPlaybackState(true) + CommandBus.send(Command.RefreshTrack(queue.current())) + } else if (command is Command.AddToQueue) { + queue.append(command.tracks) + } else if (command is Command.PlayNext) { + queue.insertNext(command.track) + } else if (command is Command.RemoveFromQueue) { + queue.remove(command.track) + } else if (command is Command.MoveFromQueue) { + queue.move(command.oldPosition, command.newPosition) + } else if (command is Command.PlayTrack) { + queue.current = command.index + player.seekTo(command.index, C.TIME_UNSET) - CommandBus.send(Command.RefreshTrack(queue.current())) - } + setPlaybackState(true) - is Command.ToggleState -> togglePlayback() - is Command.SetState -> setPlaybackState(command.state) - - is Command.NextTrack -> skipToNextTrack() - is Command.PreviousTrack -> skipToPreviousTrack() - is Command.Seek -> seek(command.progress) - - is Command.ClearQueue -> { - queue.clear() - player.stop() - } - is Command.ShuffleQueue -> queue.shuffle() - - is Command.PlayRadio -> { - queue.clear() - radioPlayer.play(command.radio) - } - - is Command.SetRepeatMode -> player.repeatMode = command.mode - - is Command.PinTrack -> PinService.download(this@PlayerService, command.track) - is Command.PinTracks -> command.tracks.forEach { + CommandBus.send(Command.RefreshTrack(queue.current())) + } else if (command is Command.ToggleState) { + togglePlayback() + } else if (command is Command.SetState) { + setPlaybackState(command.state) + } else if (command is Command.NextTrack) { + skipToNextTrack() + } else if (command is Command.PreviousTrack) { + skipToPreviousTrack() + } else if (command is Command.Seek) { + seek(command.progress) + } else if (command is Command.ClearQueue) { + queue.clear() + player.stop() + } else if (command is Command.ShuffleQueue) { + queue.shuffle() + } else if (command is Command.PlayRadio) { + queue.clear() + radioPlayer.play(command.radio) + } else if (command is Command.SetRepeatMode) { + player.repeatMode = command.mode + } else if (command is Command.PinTrack) { + PinService.download(this@PlayerService, command.track) + } else if (command is Command.PinTracks) { + command.tracks.forEach { PinService.download( this@PlayerService, it @@ -237,10 +235,12 @@ class PlayerService : Service() { scope.launch(Main) { RequestBus.get().collect { request -> - when (request) { - is Request.GetCurrentTrack -> request.channel?.trySend(Response.CurrentTrack(queue.current()))?.isSuccess - is Request.GetState -> request.channel?.trySend(Response.State(player.playWhenReady))?.isSuccess - is Request.GetQueue -> request.channel?.trySend(Response.Queue(queue.get()))?.isSuccess + if (request is Request.GetCurrentTrack) { + request.channel?.trySend(Response.CurrentTrack(queue.current()))?.isSuccess + } else if (request is Request.GetState) { + request.channel?.trySend(Response.State(player.playWhenReady))?.isSuccess + } else if (request is Request.GetQueue) { + request.channel?.trySend(Response.Queue(queue.get()))?.isSuccess } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt index 3b59d2c..b6862ab 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt @@ -1,8 +1,16 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.model.* -import audio.funkwhale.ffa.utils.* +import audio.funkwhale.ffa.model.FFAResponse +import audio.funkwhale.ffa.model.Playlist +import audio.funkwhale.ffa.model.PlaylistsCache +import audio.funkwhale.ffa.model.PlaylistsResponse +import audio.funkwhale.ffa.model.Track +import audio.funkwhale.ffa.utils.OAuth +import audio.funkwhale.ffa.utils.Settings +import audio.funkwhale.ffa.utils.authorize +import audio.funkwhale.ffa.utils.gsonDeserializerOf +import audio.funkwhale.ffa.utils.mustNormalizeUrl import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt index 2d9e2c3..9ec1768 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/Repository.kt @@ -8,11 +8,9 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map -import java.io.BufferedReader import kotlin.math.ceil interface Upstream { diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt index a93ceb9..02c39cd 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt @@ -1,7 +1,15 @@ package audio.funkwhale.ffa.repositories import android.content.Context -import audio.funkwhale.ffa.model.* +import audio.funkwhale.ffa.model.Album +import audio.funkwhale.ffa.model.AlbumsCache +import audio.funkwhale.ffa.model.AlbumsResponse +import audio.funkwhale.ffa.model.Artist +import audio.funkwhale.ffa.model.ArtistsCache +import audio.funkwhale.ffa.model.ArtistsResponse +import audio.funkwhale.ffa.model.Track +import audio.funkwhale.ffa.model.TracksCache +import audio.funkwhale.ffa.model.TracksResponse import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.gsonDeserializerOf import audio.funkwhale.ffa.utils.mustNormalizeUrl diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt index 0ea41df..6e1d3e8 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt @@ -25,7 +25,7 @@ import kotlinx.coroutines.runBlocking import net.openid.appauth.ClientSecretPost import java.io.Reader import java.text.SimpleDateFormat -import java.util.* +import java.util.Date import kotlin.coroutines.CoroutineContext inline fun Flow>.untilNetwork( @@ -82,7 +82,7 @@ fun Request.authorize(context: Context, oAuth: OAuth): Request { state.performActionWithFreshTokens(tokenService, auth) { token, _, e -> if (e != null) { - Log.e("Request.authorize()", "performActionWithFreshToken failed: ${e}") + Log.e("Request.authorize()", "performActionWithFreshToken failed: $e") Log.e("Request.authorize()", Log.getStackTraceString(e)) } if (token == old) { diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt b/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt index dd06e49..7756066 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/FFACache.kt @@ -15,7 +15,7 @@ object FFACache { return digest.fold("") { acc, it -> acc + "%02x".format(it) } } - fun set(context: Context?, key:String, value: String){ + fun set(context: Context?, key: String, value: String) { set(context, key, value.toByteArray()) } diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt index 9a637a0..9e21669 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt @@ -71,9 +71,8 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory } else { false } - ).also { - it.logInfo("isAuthorized()") - } + ) + .also { it.logInfo("isAuthorized()") } } private fun AuthState.validAuthorization() = this.isAuthorized && !this.needsTokenRefresh @@ -102,7 +101,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory runBlocking { refreshService.performTokenRequest(refreshRequest, auth) { response, e -> if (e != null) { - Log.e("OAuth", "performTokenRequest failed: ${e}") + Log.e("OAuth", "performTokenRequest failed: $e") Log.e("OAuth", Log.getStackTraceString(e)) } else { state.apply { @@ -213,13 +212,13 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory requestService.performTokenRequest(it.createTokenExchangeRequest(), auth) { response, e -> if (e != null) { - Log.e("FFA", "performTokenRequest failed: ${e}") + Log.e("FFA", "performTokenRequest failed: $e") Log.e("FFA", Log.getStackTraceString(e)) } else { state.apply { - update(response, e) - save() - } + update(response, e) + save() + } } if (response != null) success() diff --git a/build.gradle.kts b/build.gradle.kts index 020a1ce..d3506fe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ buildscript { dependencies { classpath("com.android.tools.build:gradle:7.2.2") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10") classpath("com.github.bjoernq:unmockplugin:0.7.9") classpath("com.github.ben-manes:gradle-versions-plugin:0.42.0") classpath("org.jacoco:org.jacoco.core:0.8.7")