funkwhale-app-android/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsGridFragment.kt

51 lines
1.6 KiB
Kotlin
Raw Normal View History

package audio.funkwhale.ffa.fragments
2019-08-19 16:50:33 +02:00
import android.os.Bundle
2021-07-16 10:03:52 +02:00
import android.view.LayoutInflater
2019-08-19 16:50:33 +02:00
import android.view.View
2021-07-16 10:03:52 +02:00
import android.view.ViewGroup
2023-01-10 13:56:20 +01:00
import androidx.navigation.fragment.findNavController
2019-08-19 16:50:33 +02:00
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import audio.funkwhale.ffa.adapters.AlbumsGridAdapter
2021-07-16 10:03:52 +02:00
import audio.funkwhale.ffa.databinding.FragmentAlbumsGridBinding
import audio.funkwhale.ffa.model.Album
2021-09-09 09:56:15 +02:00
import audio.funkwhale.ffa.repositories.AlbumsRepository
2019-08-19 16:50:33 +02:00
2021-07-16 10:03:52 +02:00
class AlbumsGridFragment : FFAFragment<Album, AlbumsGridAdapter>() {
private var _binding: FragmentAlbumsGridBinding? = null
private val binding get() = _binding!!
override val recycler: RecyclerView get() = binding.albums
2019-08-19 16:50:33 +02:00
override val layoutManager get() = GridLayoutManager(context, 3)
override val alwaysRefresh = false
2019-08-19 16:50:33 +02:00
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
repository = AlbumsRepository(context)
}
2021-07-16 10:03:52 +02:00
override fun onCreateView(
inflater: LayoutInflater,
parent: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentAlbumsGridBinding.inflate(inflater)
adapter = AlbumsGridAdapter(inflater, OnAlbumClickListener())
swiper = binding.swiper
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
2019-08-19 16:50:33 +02:00
inner class OnAlbumClickListener : AlbumsGridAdapter.OnAlbumClickListener {
2019-10-21 11:51:32 +02:00
override fun onClick(view: View?, album: Album) {
2023-01-10 13:56:20 +01:00
findNavController().navigate(BrowseFragmentDirections.browseToTracks(album))
2019-08-19 16:50:33 +02:00
}
}
2021-07-02 13:55:49 +02:00
}