67 lines
2.2 KiB
Kotlin
67 lines
2.2 KiB
Kotlin
/*
|
|
* Copyright (c) 2019 Hemanth Savarala.
|
|
*
|
|
* Licensed under the GNU General Public License v3
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
package code.name.monkey.retromusic.fragments.genres
|
|
|
|
import android.os.Bundle
|
|
import android.view.View
|
|
import androidx.lifecycle.Observer
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import code.name.monkey.retromusic.R
|
|
import code.name.monkey.retromusic.adapter.GenreAdapter
|
|
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
|
|
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
|
|
|
|
class GenresFragment : AbsRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(),
|
|
MainActivityFragmentCallbacks {
|
|
|
|
override fun handleBackPress(): Boolean {
|
|
return false
|
|
}
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
super.onViewCreated(view, savedInstanceState)
|
|
libraryViewModel.genresLiveData
|
|
.observe(viewLifecycleOwner, Observer { genres ->
|
|
if (genres.isNotEmpty()) {
|
|
adapter?.swapDataSet(genres)
|
|
} else {
|
|
adapter?.swapDataSet(listOf())
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
override fun createLayoutManager(): LinearLayoutManager {
|
|
return LinearLayoutManager(activity)
|
|
}
|
|
|
|
override fun createAdapter(): GenreAdapter {
|
|
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
|
|
return GenreAdapter(mainActivity, dataSet, R.layout.item_list_no_image)
|
|
}
|
|
|
|
override val emptyMessage: Int
|
|
get() = R.string.no_genres
|
|
|
|
companion object {
|
|
@JvmField
|
|
val TAG: String = GenresFragment::class.java.simpleName
|
|
|
|
@JvmStatic
|
|
fun newInstance(): GenresFragment {
|
|
return GenresFragment()
|
|
}
|
|
}
|
|
} |