Commit 76479b00 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais

Add covers to player playlists and fix items reorder

parent 7970e94e
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0,-0.0416h24v24h-24z"
android:fillColor="?attr/background_default"
android:fillAlpha="1"/>
<path
android:pathData="m17.75,4.0006c-2.8709,1.2764 -5.5458,2.4607 -8.2578,3.6699 -0.7422,0.331 -0.7422,1.3301 -0.7422,1.3301l0,6.5156c-0.083,-0.01 -0.1664,-0.015 -0.25,-0.016 -1.2426,0 -2.25,1.0074 -2.25,2.25 0,1.2427 1.0074,2.25 2.25,2.25 1.2426,0 2.25,-1.0073 2.25,-2.25l0,-7.75 5,-2 0,5.7656c-0.083,-0.01 -0.1664,-0.015 -0.25,-0.016 -1.2426,0 -2.25,1.0074 -2.25,2.25 0,1.2427 1.0074,2.25 2.25,2.25 1.2426,0 2.25,-1.0073 2.25,-2.25l0,-12z"
android:strokeAlpha="1"
android:strokeLineJoin="round"
android:strokeWidth="1.77165353"
android:fillColor="#bdbdbd"
android:strokeColor="#00000000"
android:fillType="nonZero"
android:fillAlpha="1"
android:strokeLineCap="round"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
......@@ -14,9 +15,14 @@
name="holder"
type="org.videolan.vlc.gui.audio.PlaylistAdapter.ViewHolder"/>
<variable
name="cover"
type="android.graphics.drawable.BitmapDrawable"/>
<variable
name="media"
type="org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper"/>
type="org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper"/>
<variable
name="subTitle"
type="String"/>
......@@ -25,8 +31,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="40dp">
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
......@@ -39,24 +44,44 @@
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:onClick="@{(view) -> holder.onClick(view, media)}"
android:longClickable="true"
android:layout_toStartOf="@+id/item_more"
android:orientation="vertical"
android:id="@+id/selector"
app:layout_constraintEnd_toStartOf="@+id/playing"
app:layout_constraintEnd_toStartOf="@+id/item_more"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
android:layout_marginEnd="8dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="40dp"
android:id="@+id/coverImage"
android:layout_weight="1"
tools:src="@tools:sample/avatars[0]"
app:layout_constraintStart_toStartOf="@+id/selector"
app:layout_constraintDimensionRatio="1"
android:layout_marginStart="8dp"
app:media="@{media}"
android:background="@{cover}"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"/>
<org.videolan.vlc.gui.view.MiniVisualizer
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/playing"
app:bar_color="?attr/player_icon_color"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/item_more"
android:layout_marginEnd="8dp"/>
app:layout_constraintTop_toTopOf="@+id/coverImage"
app:layout_constraintBottom_toBottomOf="@+id/coverImage"
app:layout_constraintStart_toStartOf="@+id/coverImage"
app:layout_constraintEnd_toEndOf="@+id/coverImage"
/>
<TextView
android:id="@+id/audio_item_title"
......@@ -66,18 +91,18 @@
android:paddingRight="8dp"
android:singleLine="true"
android:ellipsize="middle"
android:maxLines="1"
android:text="@{media.title}"
android:textSize="16sp"
android:textColor="?attr/font_default"
app:layout_constraintEnd_toStartOf="@+id/playing"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintBottom_toTopOf="@+id/audio_item_subtitle"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="4dp"
app:layout_constraintStart_toStartOf="@+id/selector"/>
tools:text="Symphonie n°1"
app:layout_constraintStart_toEndOf="@+id/coverImage"
app:layout_constraintEnd_toEndOf="@+id/selector"/>
<TextView
android:id="@+id/audio_item_subtitle"
......@@ -88,7 +113,6 @@
android:paddingRight="8dp"
android:singleLine="true"
android:ellipsize="middle"
android:maxLines="1"
android:textColor="?attr/font_default"
android:fontFamily="sans-serif"
android:textSize="12sp"
......@@ -99,8 +123,9 @@
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/playing"/>
tools:text="Beethoven"
app:layout_constraintStart_toEndOf="@+id/coverImage"
app:layout_constraintEnd_toEndOf="@+id/selector"/>
<ImageButton
android:id="@+id/item_more"
......
......@@ -139,7 +139,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, CoroutineS
binding.coverMediaSwitcher.setAudioMediaSwitcherListener(mCoverMediaSwitcherListener)
binding.playlistSearchText.editText?.addTextChangedListener(this)
val callback = SwipeDragItemTouchHelperCallback(playlistAdapter)
val callback = SwipeDragItemTouchHelperCallback(playlistAdapter, true)
val touchHelper = ItemTouchHelper(callback)
touchHelper.attachToRecyclerView(binding.songsList)
......
......@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.audio
import android.annotation.TargetApi
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.os.Build
import android.os.Message
import android.view.LayoutInflater
......@@ -32,6 +33,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.annotation.MainThread
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
......@@ -44,6 +46,7 @@ import org.videolan.vlc.VLCApplication
import org.videolan.vlc.databinding.PlaylistItemBinding
import org.videolan.vlc.gui.DiffUtilAdapter
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
import org.videolan.vlc.gui.view.MiniVisualizer
import org.videolan.vlc.interfaces.SwipeDragHelperAdapter
import org.videolan.vlc.media.MediaUtils
......@@ -56,9 +59,22 @@ import java.util.*
@UseExperimental(ObsoleteCoroutinesApi::class)
class PlaylistAdapter(private val player: IPlayer) : DiffUtilAdapter<AbstractMediaWrapper, PlaylistAdapter.ViewHolder>(), SwipeDragHelperAdapter {
private var defaultCoverVideo: BitmapDrawable
private var defaultCoverAudio: BitmapDrawable
private var mModel: PlaylistModel? = null
private var currentPlayingVisu: MiniVisualizer? = null
init {
val ctx = when (player) {
is Context -> player
is Fragment -> player.requireContext()
else -> VLCApplication.appContext
}
defaultCoverAudio = BitmapDrawable(ctx.resources, getBitmapFromDrawable(ctx, R.drawable.ic_no_song_background))
defaultCoverVideo = UiTools.getDefaultVideoDrawable(ctx)
}
var currentIndex = 0
set(position) {
if (position == currentIndex || position >= itemCount) return
......@@ -92,12 +108,20 @@ class PlaylistAdapter(private val player: IPlayer) : DiffUtilAdapter<AbstractMed
if (currentIndex == position) {
if (mModel?.playing != false) holder.binding.playing.start() else holder.binding.playing.stop()
holder.binding.playing.visibility = View.VISIBLE
holder.binding.coverImage.visibility = View.INVISIBLE
currentPlayingVisu = holder.binding.playing
} else {
holder.binding.playing.stop()
holder.binding.playing.visibility = View.INVISIBLE
holder.binding.coverImage.visibility = View.VISIBLE
}
if (media.type == AbstractMediaWrapper.TYPE_VIDEO) {
(holder.binding.coverImage.layoutParams as ConstraintLayout.LayoutParams).dimensionRatio = "16:9"
holder.binding.cover = defaultCoverVideo
} else
holder.binding.cover = defaultCoverAudio
holder.binding.executePendingBindings()
}
......
......@@ -27,7 +27,7 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import org.videolan.vlc.interfaces.SwipeDragHelperAdapter
class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdapter) : ItemTouchHelper.Callback() {
class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdapter, private val longPressDragEnable: Boolean = false) : ItemTouchHelper.Callback() {
private var dragFrom = -1
private var dragTo = -1
......@@ -52,7 +52,7 @@ class SwipeDragItemTouchHelperCallback(private val mAdapter: SwipeDragHelperAdap
}
override fun isLongPressDragEnabled(): Boolean {
return false
return longPressDragEnable
}
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment