rework MediaItemAdapter to use ItemMedia instead of Media
This allows us to get the media onClick directly from the AoDParser. Media inforamtion are now only stored in the parsers mediaList.
This commit is contained in:
@ -8,21 +8,31 @@ class DataTypes {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO the episodes workflow could use a clean up/rework
|
||||
data class Media(
|
||||
/**
|
||||
* this class is used to represent the item media
|
||||
* it is uses in the ItemMediaAdapter (RecyclerView)
|
||||
*/
|
||||
data class ItemMedia(
|
||||
val id: Int,
|
||||
val title: String,
|
||||
val posterUrl: String
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* TODO the episodes workflow could use a clean up/rework
|
||||
*/
|
||||
data class Media(
|
||||
val id: Int,
|
||||
val link: String,
|
||||
val type: DataTypes.MediaType,
|
||||
val info: Info = Info(),
|
||||
var episodes: List<Episode> = listOf()
|
||||
) {
|
||||
override fun toString(): String {
|
||||
return title
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
data class Info(
|
||||
var posterLink: String = "",
|
||||
var title: String = "",
|
||||
var posterUrl: String = "",
|
||||
var shortDesc: String = "",
|
||||
var description: String = "",
|
||||
var year: Int = 0,
|
||||
@ -34,7 +44,7 @@ data class Episode(
|
||||
val id: Int = 0,
|
||||
var title: String = "",
|
||||
var streamUrl: String = "",
|
||||
var posterLink: String = "",
|
||||
var posterUrl: String = "",
|
||||
var description: String = "",
|
||||
var shortDesc: String = "",
|
||||
var number: Int = 0,
|
||||
|
@ -14,7 +14,7 @@ object StorageController {
|
||||
|
||||
private const val fileNameMyList = "my_list.json"
|
||||
|
||||
val myList = ArrayList<String>() // a list of saved links
|
||||
val myList = ArrayList<Int>() // a list of saved mediaIds
|
||||
|
||||
fun load(context: Context) {
|
||||
val file = File(context.filesDir, fileNameMyList)
|
||||
@ -23,7 +23,7 @@ object StorageController {
|
||||
|
||||
myList.clear()
|
||||
myList.addAll(
|
||||
GsonBuilder().create().fromJson(file.readText(), ArrayList<String>().javaClass)
|
||||
GsonBuilder().create().fromJson(file.readText(), ArrayList<Int>().javaClass)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ class EpisodeItemAdapter(private val episodes: List<Episode>) : RecyclerView.Ada
|
||||
)
|
||||
holder.view.text_episode_desc.text = episodes[position].shortDesc
|
||||
|
||||
if (episodes[position].posterLink.isNotEmpty()) {
|
||||
Glide.with(context).load(episodes[position].posterLink)
|
||||
if (episodes[position].posterUrl.isNotEmpty()) {
|
||||
Glide.with(context).load(episodes[position].posterUrl)
|
||||
.apply(RequestOptions.bitmapTransform(RoundedCornersTransformation(10, 0)))
|
||||
.into(holder.view.image_episode)
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.android.synthetic.main.item_media.view.*
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.util.Media
|
||||
import org.mosad.teapod.util.ItemMedia
|
||||
import java.util.*
|
||||
|
||||
class MediaItemAdapter(private val media: List<Media>) : RecyclerView.Adapter<MediaItemAdapter.ViewHolder>(), Filterable {
|
||||
class MediaItemAdapter(private val media: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.ViewHolder>(), Filterable {
|
||||
|
||||
var onItemClick: ((Media, Int) -> Unit)? = null
|
||||
var onItemClick: ((Int, Int) -> Unit)? = null
|
||||
private val filter = MediaFilter()
|
||||
private var filteredMedia = media.map { it.copy() }
|
||||
|
||||
@ -27,7 +27,7 @@ class MediaItemAdapter(private val media: List<Media>) : RecyclerView.Adapter<Me
|
||||
override fun onBindViewHolder(holder: MediaItemAdapter.ViewHolder, position: Int) {
|
||||
holder.view.apply {
|
||||
text_title.text = filteredMedia[position].title
|
||||
Glide.with(context).load(filteredMedia[position].info.posterLink).into(image_poster)
|
||||
Glide.with(context).load(filteredMedia[position].posterUrl).into(image_poster)
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ class MediaItemAdapter(private val media: List<Media>) : RecyclerView.Adapter<Me
|
||||
inner class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition], adapterPosition)
|
||||
onItemClick?.invoke(filteredMedia[adapterPosition].id, adapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,7 @@ class MediaItemAdapter(private val media: List<Media>) : RecyclerView.Adapter<Me
|
||||
* suppressing unchecked cast is safe, since we only use Media
|
||||
*/
|
||||
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
|
||||
filteredMedia = results?.values as List<Media>
|
||||
filteredMedia = results?.values as List<ItemMedia>
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user