use MediaItemListAdapter in MediaFragmentSimilar instead of MediaItemAdapter

This commit is contained in:
Jannik 2022-04-10 17:46:02 +02:00
parent f852600dc7
commit e80e81af0f
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
2 changed files with 32 additions and 12 deletions

View File

@ -1,3 +1,25 @@
/**
* Teapod
*
* Copyright 2020-2022 <seil0@mosad.xyz>
*
* This program 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 program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
@ -8,17 +30,15 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import org.mosad.teapod.databinding.FragmentMediaSimilarBinding
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.adapter.MediaItemListAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
import org.mosad.teapod.util.toItemMediaList
class MediaFragmentSimilar : Fragment() {
private lateinit var binding: FragmentMediaSimilarBinding
private val model: MediaFragmentViewModel by viewModels({requireParentFragment()})
private lateinit var adapterSimilar: MediaItemAdapter
private lateinit var binding: FragmentMediaSimilarBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentMediaSimilarBinding.inflate(inflater, container, false)
@ -28,15 +48,14 @@ class MediaFragmentSimilar : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapterSimilar = MediaItemAdapter(model.similarTo.toItemMediaList())
binding.recyclerMediaSimilar.adapter = adapterSimilar
binding.recyclerMediaSimilar.addItemDecoration(MediaItemDecoration(9))
// set onItemClick only in adapter is initialized
if (this::adapterSimilar.isInitialized) {
adapterSimilar.onItemClick = { mediaId, _ ->
activity?.showFragment(MediaFragment(mediaId))
binding.recyclerMediaSimilar.adapter = MediaItemListAdapter(
MediaItemListAdapter.OnClickListener {
activity?.showFragment(MediaFragment(it.id))
}
}
)
val adapterSimilar = binding.recyclerMediaSimilar.adapter as MediaItemListAdapter
adapterSimilar.submitList(model.similarTo.toItemMediaList())
}
}

View File

@ -7,6 +7,7 @@ import com.bumptech.glide.Glide
import org.mosad.teapod.databinding.ItemMediaBinding
import org.mosad.teapod.util.ItemMedia
@Deprecated("Use MediaItemListAdapter instead")
class MediaItemAdapter(private val items: List<ItemMedia>) : RecyclerView.Adapter<MediaItemAdapter.MediaViewHolder>() {
var onItemClick: ((id: String, position: Int) -> Unit)? = null