From 86448068d4e862ae0e8134618235fd6e7775978e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 3 Dec 2016 17:36:42 +0100 Subject: [PATCH] fix #14, add an indicator for the currently played song1 --- .../musicplayer/activities/MainActivity.kt | 4 ++++ .../musicplayer/adapters/SongAdapter.kt | 19 ++++++++++++++++++- app/src/main/res/layout/song.xml | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt index 49a19b1e..b03cfc57 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt index 294674f6..6bc6f81a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/SongAdapter.kt @@ -32,6 +32,7 @@ class SongAdapter(val activity: SimpleActivity, var songs: ArrayList, val var actMode: ActionMode? = null val markedItems = HashSet() 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, val fun updateSongs(newSongs: ArrayList) { 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, 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) } diff --git a/app/src/main/res/layout/song.xml b/app/src/main/res/layout/song.xml index a7219d2a..47090bfc 100644 --- a/app/src/main/res/layout/song.xml +++ b/app/src/main/res/layout/song.xml @@ -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"> + android:src="@mipmap/music_note" + android:visibility="invisible"/>