PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/adapter/song/SimpleSongAdapter.kt

53 lines
1.9 KiB
Kotlin
Raw Normal View History

2020-10-06 08:46:04 +00:00
/*
* Copyright (c) 2020 Hemanth Savarla.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
2019-04-20 05:29:45 +00:00
package code.name.monkey.retromusic.adapter.song
2018-11-30 01:06:16 +00:00
import android.view.LayoutInflater
import android.view.ViewGroup
2020-08-11 18:29:44 +00:00
import androidx.fragment.app.FragmentActivity
import code.name.monkey.retromusic.interfaces.ICabHolder
2018-11-30 01:06:16 +00:00
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
2020-02-25 13:15:23 +00:00
import java.util.*
2018-11-30 01:06:16 +00:00
2019-11-15 17:44:42 +00:00
class SimpleSongAdapter(
2020-08-11 18:29:44 +00:00
context: FragmentActivity,
2020-01-17 17:19:06 +00:00
songs: ArrayList<Song>,
layoutRes: Int,
ICabHolder: ICabHolder?
) : SongAdapter(context, songs, layoutRes, ICabHolder) {
2018-11-30 01:06:16 +00:00
2020-02-17 11:20:08 +00:00
override fun swapDataSet(dataSet: List<Song>) {
this.dataSet = dataSet.toMutableList()
notifyDataSetChanged()
}
2018-11-30 01:06:16 +00:00
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false))
}
2018-11-30 01:06:16 +00:00
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
val fixedTrackNumber = MusicUtil.getFixedTrackNumber(dataSet[position].trackNumber)
2018-11-30 01:06:16 +00:00
holder.imageText?.text = if (fixedTrackNumber > 0) fixedTrackNumber.toString() else "-"
holder.time?.text = MusicUtil.getReadableDurationString(dataSet[position].duration)
}
2018-11-30 01:06:16 +00:00
override fun getItemCount(): Int {
return dataSet.size
}
2018-11-30 01:06:16 +00:00
}