fix #14, add an indicator for the currently played song1
This commit is contained in:
parent
02f85b2054
commit
86448068d4
3 changed files with 24 additions and 3 deletions
|
@ -170,6 +170,10 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
|
|||
@Subscribe
|
||||
fun songChangedEvent(event: Events.SongChanged) {
|
||||
updateSongInfo(event.song)
|
||||
val newSongId = event.song?.id ?: -1L
|
||||
val cnt = mSongs.size - 1
|
||||
val songIndex = (0..cnt).firstOrNull { mSongs[it].id == newSongId } ?: -1
|
||||
(songs_list.adapter as SongAdapter).updateCurrentSongIndex(songIndex)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -32,6 +32,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
var actMode: ActionMode? = null
|
||||
val markedItems = HashSet<Int>()
|
||||
var iconColor = 0
|
||||
var currentSongIndex = 0
|
||||
|
||||
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
|
||||
itemView.song_frame.isSelected = select
|
||||
|
@ -135,9 +136,20 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
|
||||
fun updateSongs(newSongs: ArrayList<Song>) {
|
||||
songs = newSongs
|
||||
currentSongIndex = -1
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun updateCurrentSongIndex(index: Int) {
|
||||
val prevIndex = currentSongIndex
|
||||
currentSongIndex = -1
|
||||
notifyItemChanged(prevIndex)
|
||||
|
||||
currentSongIndex = index
|
||||
if (index >= 0)
|
||||
notifyItemChanged(index)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent?.context).inflate(R.layout.song, parent, false)
|
||||
return ViewHolder(activity, view, itemClick)
|
||||
|
@ -154,7 +166,12 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList<Song>, val
|
|||
itemView.apply {
|
||||
song_title.text = song.title
|
||||
song_artist.text = song.artist
|
||||
song_note_image.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN)
|
||||
if (currentSongIndex == pos) {
|
||||
song_note_image.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN)
|
||||
song_note_image.visibility = View.VISIBLE
|
||||
} else {
|
||||
song_note_image.visibility = View.INVISIBLE
|
||||
}
|
||||
toggleItemSelection(itemView, markedItems.contains(pos), pos)
|
||||
|
||||
setOnClickListener { viewClicked(multiSelector, pos) }
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
android:id="@+id/song_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/song_item_vertical_margin">
|
||||
|
||||
<TextView
|
||||
|
@ -38,7 +37,8 @@
|
|||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="@dimen/medium_padding"
|
||||
android:layout_marginRight="@dimen/medium_padding"
|
||||
android:src="@mipmap/music_note"/>
|
||||
android:src="@mipmap/music_note"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in a new issue