From ea286c2345142dac4487d26f81db78d496c4679a Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Fri, 27 Aug 2021 13:28:23 +0200 Subject: [PATCH] Minor adjustments to get rid of deprecation warnings --- .../ffa/adapters/FavoritesAdapter.kt | 2 +- .../ffa/adapters/PlaylistTracksAdapter.kt | 6 ++-- .../funkwhale/ffa/adapters/TracksAdapter.kt | 2 +- .../ffa/fragments/PlaylistTracksFragment.kt | 35 +++++++------------ .../funkwhale/ffa/fragments/QueueFragment.kt | 2 +- .../ffa/repositories/PlaylistsRepository.kt | 4 +-- .../java/audio/funkwhale/ffa/utils/Util.kt | 10 +++--- 7 files changed, 25 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt index ac9ceda..2a84024 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/FavoritesAdapter.kt @@ -106,7 +106,7 @@ class FavoritesAdapter( favoriteListener.onToggleFavorite(favorite.id, !favorite.favorite) data.remove(favorite) - notifyItemRemoved(holder.adapterPosition) + notifyItemRemoved(holder.bindingAdapterPosition) } } diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt index a51f502..734e850 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/PlaylistTracksAdapter.kt @@ -199,10 +199,10 @@ class PlaylistTracksAdapter( viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder ): Boolean { - if (from == -1) from = viewHolder.adapterPosition - to = target.adapterPosition + if (from == -1) from = viewHolder.bindingAdapterPosition + to = target.bindingAdapterPosition - onItemMove(viewHolder.adapterPosition, target.adapterPosition) + onItemMove(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition) return true } diff --git a/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt b/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt index 381b05f..c661460 100644 --- a/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt +++ b/app/src/main/java/audio/funkwhale/ffa/adapters/TracksAdapter.kt @@ -230,7 +230,7 @@ class TracksAdapter( if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { context?.let { viewHolder?.let { - from = viewHolder.adapterPosition + from = viewHolder.bindingAdapterPosition viewHolder.itemView.background = ColorDrawable(context.getColor(R.color.colorSelected)) } } 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 da40ee2..8255902 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/PlaylistTracksFragment.kt @@ -12,21 +12,13 @@ import androidx.recyclerview.widget.RecyclerView import audio.funkwhale.ffa.R import audio.funkwhale.ffa.adapters.PlaylistTracksAdapter import audio.funkwhale.ffa.databinding.FragmentTracksBinding -import audio.funkwhale.ffa.repositories.FavoritesRepository -import audio.funkwhale.ffa.repositories.ManagementPlaylistsRepository -import audio.funkwhale.ffa.repositories.PlaylistTracksRepository -import audio.funkwhale.ffa.utils.Command -import audio.funkwhale.ffa.utils.CommandBus import audio.funkwhale.ffa.model.Playlist import audio.funkwhale.ffa.model.PlaylistTrack -import audio.funkwhale.ffa.utils.Request -import audio.funkwhale.ffa.utils.RequestBus -import audio.funkwhale.ffa.utils.Response import audio.funkwhale.ffa.model.Track -import audio.funkwhale.ffa.utils.maybeLoad -import audio.funkwhale.ffa.utils.maybeNormalizeUrl -import audio.funkwhale.ffa.utils.toast -import audio.funkwhale.ffa.utils.wait +import audio.funkwhale.ffa.repositories.FavoritesRepository +import audio.funkwhale.ffa.repositories.ManagementPlaylistsRepository +import audio.funkwhale.ffa.repositories.PlaylistTracksRepository +import audio.funkwhale.ffa.utils.* import com.squareup.picasso.Picasso import jp.wasabeef.picasso.transformations.RoundedCornersTransformation import kotlinx.coroutines.Dispatchers.Main @@ -183,15 +175,14 @@ class PlaylistTracksFragment : FFAFragment else -> RoundedCornersTransformation.CornerType.TOP_LEFT } - imageView?.let { view -> - lifecycleScope.launch(Main) { - Picasso.get() - .maybeLoad(maybeNormalizeUrl(url)) - .fit() - .centerCrop() - .transform(RoundedCornersTransformation(16, 0, corner)) - .into(view) - } + + lifecycleScope.launch(Main) { + Picasso.get() + .maybeLoad(maybeNormalizeUrl(url)) + .fit() + .centerCrop() + .transform(RoundedCornersTransformation(16, 0, corner)) + .into(imageView) } } } @@ -229,7 +220,7 @@ class PlaylistTracksFragment : FFAFragment override fun onRemoveTrackFromPlaylist(track: Track, index: Int) { lifecycleScope.launch(Main) { - playlistsRepository.remove(albumId, track, index) + playlistsRepository.remove(albumId, index) update() } } 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 5fcf876..02e1b25 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/QueueFragment.kt @@ -78,7 +78,7 @@ class QueueFragment : BottomSheetDialogFragment() { super.onResume() binding.included.queue.visibility = View.GONE - binding.included.placeholder?.visibility = View.VISIBLE + binding.included.placeholder.visibility = View.VISIBLE binding.included.queueShuffle.setOnClickListener { CommandBus.send(Command.ShuffleQueue) 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 951f293..752d60f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt @@ -103,11 +103,11 @@ class ManagementPlaylistsRepository(override val context: Context?) : } } - suspend fun remove(id: Int, track: Track, index: Int) { + suspend fun remove(albumId: Int, index: Int) { context?.let { val body = mapOf("index" to index) - val request = Fuel.post(mustNormalizeUrl("/api/v1/playlists/$id/remove/")).apply { + val request = Fuel.post(mustNormalizeUrl("/api/v1/playlists/$albumId/remove/")).apply { if (!Settings.isAnonymous()) { authorize(context, oAuth) header("Authorization", "Bearer ${oAuth.state().accessToken}") diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Util.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Util.kt index 687b536..9769e71 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Util.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Util.kt @@ -3,8 +3,6 @@ package audio.funkwhale.ffa.utils import android.content.Context import android.widget.Toast import com.google.android.exoplayer2.util.Log -import com.google.android.exoplayer2.util.Log.LOG_LEVEL_ERROR -import com.google.android.exoplayer2.util.Log.LOG_LEVEL_INFO import com.preference.PowerPreference import java.net.URI @@ -33,10 +31,10 @@ private fun logClassName(): String { return "UNKNOWN" } -enum class LogLevel(value: Int) { - INFO(LOG_LEVEL_INFO), - DEBUG(Log.LOG_LEVEL_ALL), - ERROR(LOG_LEVEL_ERROR) +enum class LogLevel { + INFO, + DEBUG, + ERROR } fun Any?.logError(prefix: String? = null) = this.log(prefix, LogLevel.ERROR)