Browse Source

Pulled some fixes from dev/chromecast (080cce00eec84f1be724d34daa597c406bb1a63a).

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
f7a5a29eea
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 21
      app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt
  2. 6
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt
  3. 7
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

21
app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt

@ -158,8 +158,6 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -158,8 +158,6 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
}
notifyItemMoved(oldPosition, newPosition)
CommandBus.send(Command.MoveFromQueue(oldPosition, newPosition))
}
inner class ViewHolder(view: View, val context: Context?) : RecyclerView.ViewHolder(view), View.OnClickListener {
@ -186,6 +184,9 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -186,6 +184,9 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
}
inner class TouchHelperCallback : ItemTouchHelper.Callback() {
var from = -1
var to = -1
override fun isLongPressDragEnabled() = false
override fun isItemViewSwipeEnabled() = false
@ -194,7 +195,9 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -194,7 +195,9 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
makeMovementFlags(ItemTouchHelper.UP or ItemTouchHelper.DOWN, 0)
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
onItemMove(viewHolder.adapterPosition, target.adapterPosition)
to = target.adapterPosition
onItemMove(viewHolder.adapterPosition, to)
return true
}
@ -204,7 +207,10 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -204,7 +207,10 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
context?.let {
viewHolder?.itemView?.background = ColorDrawable(context.getColor(R.color.colorSelected))
viewHolder?.let {
from = viewHolder.adapterPosition
viewHolder.itemView.background = ColorDrawable(context.getColor(R.color.colorSelected))
}
}
}
@ -212,6 +218,13 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -212,6 +218,13 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
}
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
if (from != -1 && to != -1) {
CommandBus.send(Command.MoveFromQueue(from, to))
from = -1
to = -1
}
viewHolder.itemView.background = ColorDrawable(Color.TRANSPARENT)
super.clearView(recyclerView, viewHolder)

6
app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt

@ -1,12 +1,7 @@ @@ -1,12 +1,7 @@
package com.github.apognu.otter.fragments
import android.content.Context
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.style.DynamicDrawableSpan
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
@ -24,7 +19,6 @@ import com.github.apognu.otter.repositories.AlbumsRepository @@ -24,7 +19,6 @@ import com.github.apognu.otter.repositories.AlbumsRepository
import com.github.apognu.otter.repositories.ArtistTracksRepository
import com.github.apognu.otter.repositories.Repository
import com.github.apognu.otter.utils.*
import com.github.apognu.otter.views.LoadingFlotingActionButton
import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.fragment_albums.*

7
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -50,7 +50,7 @@ class PlayerService : Service() { @@ -50,7 +50,7 @@ class PlayerService : Service() {
private lateinit var radioPlayer: RadioPlayer
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
watchEventBus()
if (jobs.isEmpty()) watchEventBus()
return START_STICKY
}
@ -222,7 +222,10 @@ class PlayerService : Service() { @@ -222,7 +222,10 @@ class PlayerService : Service() {
@SuppressLint("NewApi")
override fun onDestroy() {
jobs.forEach { it.cancel() }
jobs.forEach {
it.cancel()
jobs.remove(it)
}
try {
unregisterReceiver(headphonesUnpluggedReceiver)

Loading…
Cancel
Save