2019-07-22 15:26:37 +00:00
|
|
|
/*
|
2020-10-06 08:46:04 +00:00
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
2019-07-22 15:26:37 +00:00
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
2020-10-06 08:46:04 +00:00
|
|
|
* 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.
|
2019-07-22 15:26:37 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2020-10-06 08:46:04 +00:00
|
|
|
*
|
2019-07-22 15:26:37 +00:00
|
|
|
*/
|
2020-04-25 15:59:52 +00:00
|
|
|
package code.name.monkey.retromusic.fragments.genres
|
2019-07-22 15:26:37 +00:00
|
|
|
|
|
|
|
import android.os.Bundle
|
2019-09-29 02:10:25 +00:00
|
|
|
import android.view.View
|
2020-10-17 08:54:01 +00:00
|
|
|
import androidx.core.os.bundleOf
|
2020-04-25 15:59:52 +00:00
|
|
|
import androidx.lifecycle.Observer
|
2020-10-17 08:54:01 +00:00
|
|
|
import androidx.navigation.fragment.FragmentNavigatorExtras
|
|
|
|
import androidx.navigation.fragment.findNavController
|
2019-07-22 15:26:37 +00:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2020-10-17 08:54:01 +00:00
|
|
|
import code.name.monkey.retromusic.EXTRA_GENRE
|
2019-07-22 15:26:37 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.adapter.GenreAdapter
|
2020-07-30 14:11:19 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
|
2020-10-17 08:54:01 +00:00
|
|
|
import code.name.monkey.retromusic.interfaces.IGenreClickListener
|
|
|
|
import code.name.monkey.retromusic.model.Genre
|
2020-12-03 15:01:27 +00:00
|
|
|
import com.google.android.material.transition.MaterialElevationScale
|
2019-07-22 15:26:37 +00:00
|
|
|
|
2020-10-17 08:54:01 +00:00
|
|
|
class GenresFragment : AbsRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(),
|
|
|
|
IGenreClickListener {
|
2020-04-25 15:59:52 +00:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2020-09-05 14:03:12 +00:00
|
|
|
libraryViewModel.getGenre().observe(viewLifecycleOwner, Observer {
|
2020-08-13 08:24:36 +00:00
|
|
|
if (it.isNotEmpty())
|
|
|
|
adapter?.swapDataSet(it)
|
|
|
|
else
|
|
|
|
adapter?.swapDataSet(listOf())
|
|
|
|
})
|
2019-07-22 15:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun createLayoutManager(): LinearLayoutManager {
|
|
|
|
return LinearLayoutManager(activity)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun createAdapter(): GenreAdapter {
|
|
|
|
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
2020-10-17 08:54:01 +00:00
|
|
|
return GenreAdapter(requireActivity(), dataSet, R.layout.item_list_no_image, this)
|
2019-07-22 15:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override val emptyMessage: Int
|
|
|
|
get() = R.string.no_genres
|
|
|
|
|
|
|
|
companion object {
|
2019-09-16 18:02:40 +00:00
|
|
|
@JvmField
|
2019-10-09 12:52:02 +00:00
|
|
|
val TAG: String = GenresFragment::class.java.simpleName
|
2020-02-26 16:49:24 +00:00
|
|
|
|
2020-02-19 07:08:12 +00:00
|
|
|
@JvmStatic
|
2019-07-22 15:26:37 +00:00
|
|
|
fun newInstance(): GenresFragment {
|
|
|
|
return GenresFragment()
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 08:54:01 +00:00
|
|
|
|
|
|
|
override fun onClickGenre(genre: Genre, view: View) {
|
2020-12-03 15:01:27 +00:00
|
|
|
exitTransition = MaterialElevationScale(false).apply {
|
|
|
|
duration = 300L
|
|
|
|
}
|
|
|
|
reenterTransition = MaterialElevationScale(true).apply {
|
|
|
|
duration = 300L
|
|
|
|
}
|
2020-10-17 08:54:01 +00:00
|
|
|
findNavController().navigate(
|
|
|
|
R.id.genreDetailsFragment,
|
|
|
|
bundleOf(EXTRA_GENRE to genre),
|
|
|
|
null,
|
|
|
|
FragmentNavigatorExtras(
|
|
|
|
view to "genre"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2020-10-06 08:46:04 +00:00
|
|
|
}
|