refresh TracksActivity on resume
This commit is contained in:
parent
0968afefad
commit
9a0d983601
2 changed files with 28 additions and 9 deletions
|
@ -241,19 +241,31 @@ class TracksActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
runOnUiThread {
|
||||
val adapter = if (tracksType == TYPE_ALBUM) {
|
||||
TracksHeaderAdapter(this, listItems, tracks_list) {
|
||||
itemClicked(it as Track)
|
||||
if (tracksType == TYPE_ALBUM) {
|
||||
val currAdapter = tracks_list.adapter
|
||||
if (currAdapter == null) {
|
||||
TracksHeaderAdapter(this, listItems, tracks_list) {
|
||||
itemClicked(it as Track)
|
||||
}.apply {
|
||||
tracks_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as TracksHeaderAdapter).updateItems(listItems)
|
||||
}
|
||||
} else {
|
||||
val isPlaylistContent = tracksType == TYPE_PLAYLIST
|
||||
TracksAdapter(this, tracks, isPlaylistContent, tracks_list) {
|
||||
itemClicked(it as Track)
|
||||
val currAdapter = tracks_list.adapter
|
||||
if (currAdapter == null) {
|
||||
TracksAdapter(this, tracks, isPlaylistContent, tracks_list) {
|
||||
itemClicked(it as Track)
|
||||
}.apply {
|
||||
tracks_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as TracksAdapter).updateItems(tracks)
|
||||
}
|
||||
}
|
||||
|
||||
tracks_list.adapter = adapter
|
||||
|
||||
if (areSystemAnimationsEnabled) {
|
||||
tracks_list.scheduleLayoutAnimation()
|
||||
}
|
||||
|
|
|
@ -26,9 +26,8 @@ import com.simplemobiletools.musicplayer.models.ListItem
|
|||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import kotlinx.android.synthetic.main.item_album_header.view.*
|
||||
import kotlinx.android.synthetic.main.item_track.view.*
|
||||
import java.util.*
|
||||
|
||||
class TracksHeaderAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
class TracksHeaderAdapter(activity: SimpleActivity, var items: ArrayList<ListItem>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
|
||||
|
||||
private val ITEM_HEADER = 0
|
||||
|
@ -154,6 +153,14 @@ class TracksHeaderAdapter(activity: SimpleActivity, val items: ArrayList<ListIte
|
|||
|
||||
private fun getSelectedTracks(): List<Track> = items.filter { it is Track && selectedKeys.contains(it.hashCode()) }.toList() as List<Track>
|
||||
|
||||
fun updateItems(newItems: ArrayList<ListItem>) {
|
||||
if (newItems.hashCode() != items.hashCode()) {
|
||||
items = newItems.clone() as ArrayList<ListItem>
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupTrack(view: View, track: Track) {
|
||||
view.apply {
|
||||
track_frame?.isSelected = selectedKeys.contains(track.hashCode())
|
||||
|
|
Loading…
Reference in a new issue