mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
- Fixed track item layout when track number is missing
- Fixed Rx unsubscribing - Fixed drag handle usage in playlist
This commit is contained in:
parent
de04f4cbe6
commit
0d24c87eef
@ -1,9 +1,13 @@
|
|||||||
package org.moire.ultrasonic.adapters
|
package org.moire.ultrasonic.adapters
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.MotionEventCompat
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import com.drakeet.multitype.ItemViewBinder
|
import com.drakeet.multitype.ItemViewBinder
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
@ -23,6 +27,8 @@ class TrackViewBinder(
|
|||||||
val lifecycleOwner: LifecycleOwner,
|
val lifecycleOwner: LifecycleOwner,
|
||||||
) : ItemViewBinder<Identifiable, TrackViewHolder>(), KoinComponent {
|
) : ItemViewBinder<Identifiable, TrackViewHolder>(), KoinComponent {
|
||||||
|
|
||||||
|
var startDrag: ((TrackViewHolder) -> Unit)? = null
|
||||||
|
|
||||||
// Set our layout files
|
// Set our layout files
|
||||||
val layout = R.layout.list_item_track
|
val layout = R.layout.list_item_track
|
||||||
val contextMenuLayout = R.menu.context_menu_track
|
val contextMenuLayout = R.menu.context_menu_track
|
||||||
@ -34,6 +40,7 @@ class TrackViewBinder(
|
|||||||
return TrackViewHolder(inflater.inflate(layout, parent, false))
|
return TrackViewHolder(inflater.inflate(layout, parent, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
override fun onBindViewHolder(holder: TrackViewHolder, item: Identifiable) {
|
override fun onBindViewHolder(holder: TrackViewHolder, item: Identifiable) {
|
||||||
val downloadFile: DownloadFile?
|
val downloadFile: DownloadFile?
|
||||||
@ -89,6 +96,13 @@ class TrackViewBinder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.drag.setOnTouchListener { _, event ->
|
||||||
|
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||||
|
startDrag?.invoke(holder)
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
// Notify the adapter of selection changes
|
// Notify the adapter of selection changes
|
||||||
holder.observableChecked.observe(
|
holder.observableChecked.observe(
|
||||||
lifecycleOwner,
|
lifecycleOwner,
|
||||||
@ -127,4 +141,9 @@ class TrackViewBinder(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewRecycled(holder: TrackViewHolder) {
|
||||||
|
holder.dispose()
|
||||||
|
super.onViewRecycled(holder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import android.widget.TextView
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
import org.moire.ultrasonic.R
|
import org.moire.ultrasonic.R
|
||||||
@ -56,6 +57,8 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
|
|||||||
private var statusImage: Drawable? = null
|
private var statusImage: Drawable? = null
|
||||||
private var isPlayingCached = false
|
private var isPlayingCached = false
|
||||||
|
|
||||||
|
private var rxSubscription: Disposable? = null
|
||||||
|
|
||||||
var observableChecked = MutableLiveData(false)
|
var observableChecked = MutableLiveData(false)
|
||||||
|
|
||||||
private val useFiveStarRating: Boolean by lazy {
|
private val useFiveStarRating: Boolean by lazy {
|
||||||
@ -112,11 +115,15 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
|
|||||||
progress.isVisible = false
|
progress.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
RxBus.playerStateObservable.subscribe {
|
rxSubscription = RxBus.playerStateObservable.subscribe {
|
||||||
setPlayIcon(it.track == downloadFile)
|
setPlayIcon(it.track == downloadFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dispose() {
|
||||||
|
rxSubscription?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
private fun setPlayIcon(isPlaying: Boolean) {
|
private fun setPlayIcon(isPlaying: Boolean) {
|
||||||
if (isPlaying && !isPlayingCached) {
|
if (isPlaying && !isPlayingCached) {
|
||||||
isPlayingCached = true
|
isPlayingCached = true
|
||||||
|
@ -864,7 +864,9 @@ class PlayerFragment :
|
|||||||
draggable = true,
|
draggable = true,
|
||||||
context = requireContext(),
|
context = requireContext(),
|
||||||
lifecycleOwner = viewLifecycleOwner,
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
)
|
).apply { this.startDrag = { holder ->
|
||||||
|
dragTouchHelper.startDrag(holder)
|
||||||
|
} }
|
||||||
)
|
)
|
||||||
|
|
||||||
dragTouchHelper = ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(
|
dragTouchHelper = ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(
|
||||||
@ -923,6 +925,10 @@ class PlayerFragment :
|
|||||||
|
|
||||||
viewHolder.itemView.alpha = 1.0f
|
viewHolder.itemView.alpha = 1.0f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isLongPressDragEnabled(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,12 +16,14 @@
|
|||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:paddingEnd="6dip"
|
a:paddingEnd="6dip"
|
||||||
a:textAppearance="?android:attr/textAppearanceMedium"
|
a:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
a:visibility="visible"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/song_artist"
|
app:layout_constraintBottom_toTopOf="@+id/song_artist"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/song_title"
|
app:layout_constraintEnd_toStartOf="@+id/song_title"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
tools:text="Track" />
|
tools:text="Track"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:id="@+id/song_title"
|
a:id="@+id/song_title"
|
||||||
@ -62,7 +64,7 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/song_duration"
|
app:layout_constraintEnd_toStartOf="@+id/song_duration"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/song_track"
|
app:layout_constraintTop_toBottomOf="@+id/song_title"
|
||||||
tools:text="Artist" />
|
tools:text="Artist" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
Loading…
x
Reference in New Issue
Block a user