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-11-23 20:38:26 +01:00
|
|
|
import android.view.View
|
2021-05-12 13:28:33 +02:00
|
|
|
import androidx.fragment.app.viewModels
|
|
|
|
import androidx.lifecycle.LiveData
|
2021-11-30 20:53:10 +01:00
|
|
|
import androidx.navigation.NavController
|
2021-11-23 20:38:26 +01:00
|
|
|
import androidx.navigation.fragment.findNavController
|
2020-11-16 19:14:44 +01:00
|
|
|
import org.moire.ultrasonic.R
|
2021-11-23 20:38:26 +01:00
|
|
|
import org.moire.ultrasonic.adapters.ArtistRowBinder
|
|
|
|
import org.moire.ultrasonic.domain.Artist
|
2021-06-20 16:31:08 +02:00
|
|
|
import org.moire.ultrasonic.domain.ArtistOrIndex
|
2021-11-28 18:26:44 +01:00
|
|
|
import org.moire.ultrasonic.domain.Index
|
2021-11-23 20:38:26 +01:00
|
|
|
import org.moire.ultrasonic.model.ArtistListModel
|
2020-11-16 19:14:44 +01:00
|
|
|
import org.moire.ultrasonic.util.Constants
|
|
|
|
|
2021-03-01 17:24:25 +01:00
|
|
|
/**
|
2021-11-30 20:53:10 +01:00
|
|
|
* Displays the list of Artists or Indexes (folders) from the media library
|
2021-03-01 17:24:25 +01:00
|
|
|
*/
|
2021-11-16 17:58:15 +01:00
|
|
|
class ArtistListFragment : EntryListFragment<ArtistOrIndex>() {
|
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
|
|
|
|
*/
|
2021-11-27 00:51:41 +01:00
|
|
|
override val mainLayout = R.layout.list_layout_generic
|
2021-05-12 13:28:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The central function to pass a query to the model and return a LiveData object
|
|
|
|
*/
|
2021-11-30 00:46:48 +01:00
|
|
|
override fun getLiveData(args: Bundle?, refresh: Boolean): LiveData<List<ArtistOrIndex>> {
|
2021-11-30 21:50:53 +01:00
|
|
|
val refresh2 = args?.getBoolean(Constants.INTENT_REFRESH) ?: false || refresh
|
|
|
|
return listModel.getItems(refresh2, refreshListView!!)
|
2021-02-04 20:15:58 +01:00
|
|
|
}
|
2020-11-16 19:14:44 +01:00
|
|
|
|
2021-11-23 20:38:26 +01:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
|
|
viewAdapter.register(
|
|
|
|
ArtistRowBinder(
|
|
|
|
{ entry -> onItemClick(entry) },
|
|
|
|
{ menuItem, entry -> onContextMenuItemSelected(menuItem, entry) },
|
|
|
|
imageLoaderProvider.getImageLoader()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-11-28 18:26:44 +01:00
|
|
|
/**
|
|
|
|
* There are different targets depending on what list we show.
|
|
|
|
* If we are showing indexes, we need to go to TrackCollection
|
|
|
|
* If we are showing artists, we need to go to AlbumList
|
|
|
|
*/
|
2021-11-23 20:38:26 +01:00
|
|
|
override fun onItemClick(item: ArtistOrIndex) {
|
2021-11-30 20:53:10 +01:00
|
|
|
Companion.onItemClick(item, findNavController())
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
fun onItemClick(item: ArtistOrIndex, navController: NavController) {
|
|
|
|
val bundle = Bundle()
|
2021-11-28 18:26:44 +01:00
|
|
|
|
2021-11-30 20:53:10 +01:00
|
|
|
// Common arguments
|
2021-11-30 21:21:50 +01:00
|
|
|
bundle.putString(Constants.INTENT_ID, item.id)
|
|
|
|
bundle.putString(Constants.INTENT_NAME, item.name)
|
|
|
|
bundle.putString(Constants.INTENT_PARENT_ID, item.id)
|
|
|
|
bundle.putBoolean(Constants.INTENT_ARTIST, (item is Artist))
|
2021-11-28 18:26:44 +01:00
|
|
|
|
2021-11-30 20:53:10 +01:00
|
|
|
// Check type
|
|
|
|
if (item is Index) {
|
|
|
|
navController.navigate(R.id.artistsListToTrackCollection, bundle)
|
|
|
|
} else {
|
2021-11-30 21:21:50 +01:00
|
|
|
bundle.putString(Constants.INTENT_ALBUM_LIST_TYPE, Constants.ALBUMS_OF_ARTIST)
|
|
|
|
bundle.putString(Constants.INTENT_ALBUM_LIST_TITLE, item.name)
|
|
|
|
bundle.putInt(Constants.INTENT_ALBUM_LIST_SIZE, 1000)
|
|
|
|
bundle.putInt(Constants.INTENT_ALBUM_LIST_OFFSET, 0)
|
2021-11-30 20:53:10 +01:00
|
|
|
navController.navigate(R.id.artistsListToAlbumsList, bundle)
|
|
|
|
}
|
2021-11-28 18:26:44 +01:00
|
|
|
}
|
2021-11-23 20:38:26 +01:00
|
|
|
}
|
2021-02-14 15:55:16 +01:00
|
|
|
}
|