2021-02-04 20:15:58 +01:00
|
|
|
package org.moire.ultrasonic.fragment
|
2020-11-16 19:14:44 +01:00
|
|
|
|
|
|
|
import android.os.Bundle
|
2021-05-12 13:28:33 +02:00
|
|
|
import androidx.fragment.app.viewModels
|
|
|
|
import androidx.lifecycle.LiveData
|
2020-11-16 19:14:44 +01:00
|
|
|
import org.moire.ultrasonic.R
|
2021-06-20 16:31:08 +02:00
|
|
|
import org.moire.ultrasonic.domain.ArtistOrIndex
|
2020-11-16 19:14:44 +01:00
|
|
|
import org.moire.ultrasonic.util.Constants
|
|
|
|
|
2021-03-01 17:24:25 +01:00
|
|
|
/**
|
|
|
|
* Displays the list of Artists from the media library
|
|
|
|
*/
|
2021-10-14 19:25:25 +02:00
|
|
|
class ArtistListFragment : EntryListFragment<ArtistOrIndex, ArtistRowAdapter>() {
|
2021-05-12 13:28:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ViewModel to use to get the data
|
|
|
|
*/
|
|
|
|
override val listModel: ArtistListModel by viewModels()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the main layout
|
|
|
|
*/
|
|
|
|
override val mainLayout = R.layout.generic_list
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the refresh view
|
|
|
|
*/
|
|
|
|
override val refreshListId = R.id.generic_list_refresh
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the RecyclerView
|
|
|
|
*/
|
|
|
|
override val recyclerViewId = R.id.generic_list_recycler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the target in the navigation graph where we should go,
|
|
|
|
* after the user has clicked on an item
|
|
|
|
*/
|
|
|
|
override val itemClickTarget = R.id.selectArtistToSelectAlbum
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The central function to pass a query to the model and return a LiveData object
|
|
|
|
*/
|
2021-06-20 16:31:08 +02:00
|
|
|
override fun getLiveData(args: Bundle?): LiveData<List<ArtistOrIndex>> {
|
2021-05-12 13:28:33 +02:00
|
|
|
val refresh = args?.getBoolean(Constants.INTENT_EXTRA_NAME_REFRESH) ?: false
|
|
|
|
return listModel.getItems(refresh, refreshListView!!)
|
2021-02-04 20:15:58 +01:00
|
|
|
}
|
2020-11-16 19:14:44 +01:00
|
|
|
|
2021-05-12 13:28:33 +02:00
|
|
|
/**
|
|
|
|
* Provide the Adapter for the RecyclerView with a lazy delegate
|
|
|
|
*/
|
|
|
|
override val viewAdapter: ArtistRowAdapter by lazy {
|
|
|
|
ArtistRowAdapter(
|
|
|
|
liveDataItems.value ?: listOf(),
|
|
|
|
{ entry -> onItemClick(entry) },
|
|
|
|
{ menuItem, entry -> onContextMenuItemSelected(menuItem, entry) },
|
2021-05-17 17:14:04 +02:00
|
|
|
imageLoaderProvider.getImageLoader(),
|
|
|
|
onMusicFolderUpdate
|
2020-11-16 19:14:44 +01:00
|
|
|
)
|
|
|
|
}
|
2021-02-14 15:55:16 +01:00
|
|
|
}
|