2022-04-10 17:46:02 +02:00
/ * *
* 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 .
*
* /
2021-02-06 19:02:12 +01:00
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
2022-04-03 16:55:54 +02:00
import androidx.fragment.app.viewModels
2021-02-06 19:02:12 +01:00
import org.mosad.teapod.databinding.FragmentMediaSimilarBinding
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
2022-04-10 17:46:02 +02:00
import org.mosad.teapod.util.adapter.MediaItemListAdapter
2021-02-06 19:02:12 +01:00
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
2022-04-03 16:14:22 +02:00
import org.mosad.teapod.util.toItemMediaList
2021-02-06 19:02:12 +01:00
class MediaFragmentSimilar : Fragment ( ) {
2022-04-03 16:55:54 +02:00
private val model : MediaFragmentViewModel by viewModels ( { requireParentFragment ( ) } )
2022-04-10 17:46:02 +02:00
private lateinit var binding : FragmentMediaSimilarBinding
2021-02-06 19:02:12 +01:00
override fun onCreateView ( inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ) : View {
binding = FragmentMediaSimilarBinding . inflate ( inflater , container , false )
return binding . root
}
override fun onViewCreated ( view : View , savedInstanceState : Bundle ? ) {
super . onViewCreated ( view , savedInstanceState )
2022-12-22 18:08:32 +01:00
2022-04-10 17:46:02 +02:00
binding . recyclerMediaSimilar . adapter = MediaItemListAdapter (
MediaItemListAdapter . OnClickListener {
activity ?. showFragment ( MediaFragment ( it . id ) )
2021-02-06 19:02:12 +01:00
}
2022-04-10 17:46:02 +02:00
)
val adapterSimilar = binding . recyclerMediaSimilar . adapter as MediaItemListAdapter
adapterSimilar . submitList ( model . similarTo . toItemMediaList ( ) )
2021-02-06 19:02:12 +01:00
}
}