parent
dca26f14eb
commit
25f072a5d5
|
@ -26,9 +26,12 @@ import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import java.util.Collections
|
||||||
|
import java.util.Random
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import org.koin.android.viewmodel.ext.android.viewModel
|
import org.koin.core.component.KoinApiExtension
|
||||||
import org.moire.ultrasonic.R
|
import org.moire.ultrasonic.R
|
||||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||||
|
@ -52,13 +55,12 @@ import org.moire.ultrasonic.view.EntryAdapter
|
||||||
import org.moire.ultrasonic.view.SelectMusicFolderView
|
import org.moire.ultrasonic.view.SelectMusicFolderView
|
||||||
import org.moire.ultrasonic.view.SongView
|
import org.moire.ultrasonic.view.SongView
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.security.SecureRandom
|
|
||||||
import java.util.Collections
|
|
||||||
import java.util.Random
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a group of playable media from the library, which can be an Album, a Playlist, etc.
|
* Displays a group of playable media from the library, which can be an Album, a Playlist, etc.
|
||||||
|
* TODO: Break up this class into smaller more specific classes, extending a base class if necessary
|
||||||
*/
|
*/
|
||||||
|
@KoinApiExtension
|
||||||
class SelectAlbumFragment : Fragment() {
|
class SelectAlbumFragment : Fragment() {
|
||||||
|
|
||||||
private var refreshAlbumListView: SwipeRefreshLayout? = null
|
private var refreshAlbumListView: SwipeRefreshLayout? = null
|
||||||
|
@ -89,11 +91,10 @@ class SelectAlbumFragment : Fragment() {
|
||||||
private val shareHandler: ShareHandler by inject()
|
private val shareHandler: ShareHandler by inject()
|
||||||
private var cancellationToken: CancellationToken? = null
|
private var cancellationToken: CancellationToken? = null
|
||||||
private val activeServerProvider: ActiveServerProvider by inject()
|
private val activeServerProvider: ActiveServerProvider by inject()
|
||||||
private val serverSettingsModel: ServerSettingsModel by viewModel()
|
|
||||||
|
|
||||||
|
private val serverSettingsModel: ServerSettingsModel by viewModels()
|
||||||
private val model: SelectAlbumModel by viewModels()
|
private val model: SelectAlbumModel by viewModels()
|
||||||
|
|
||||||
|
|
||||||
private val random: Random = SecureRandom()
|
private val random: Random = SecureRandom()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -154,8 +155,8 @@ class SelectAlbumFragment : Fragment() {
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.title)
|
bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.title)
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.parent)
|
bundle.putString(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.parent)
|
||||||
Navigation.findNavController(theView).navigate(
|
Navigation.findNavController(theView).navigate(
|
||||||
R.id.selectAlbumFragment,
|
R.id.selectAlbumFragment,
|
||||||
bundle
|
bundle
|
||||||
)
|
)
|
||||||
} else if (entry != null && entry.isVideo) {
|
} else if (entry != null && entry.isVideo) {
|
||||||
videoPlayer.playVideo(requireContext(), entry)
|
videoPlayer.playVideo(requireContext(), entry)
|
||||||
|
@ -167,7 +168,7 @@ class SelectAlbumFragment : Fragment() {
|
||||||
|
|
||||||
albumListView!!.setOnItemLongClickListener { _, theView, _, _ ->
|
albumListView!!.setOnItemLongClickListener { _, theView, _, _ ->
|
||||||
if (theView is AlbumView) {
|
if (theView is AlbumView) {
|
||||||
return@setOnItemLongClickListener false
|
return@setOnItemLongClickListener false
|
||||||
}
|
}
|
||||||
if (theView is SongView) {
|
if (theView is SongView) {
|
||||||
theView.maximizeOrMinimize()
|
theView.maximizeOrMinimize()
|
||||||
|
@ -195,9 +196,9 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
playNextButton!!.setOnClickListener {
|
playNextButton!!.setOnClickListener {
|
||||||
downloadHandler.download(
|
downloadHandler.download(
|
||||||
this@SelectAlbumFragment, append = true,
|
this@SelectAlbumFragment, append = true,
|
||||||
save = false, autoPlay = false, playNext = true, shuffle = false,
|
save = false, autoPlay = false, playNext = true, shuffle = false,
|
||||||
songs = getSelectedSongs(albumListView)
|
songs = getSelectedSongs(albumListView)
|
||||||
)
|
)
|
||||||
selectAll(selected = false, toast = false)
|
selectAll(selected = false, toast = false)
|
||||||
}
|
}
|
||||||
|
@ -210,15 +211,15 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
unpinButton!!.setOnClickListener {
|
unpinButton!!.setOnClickListener {
|
||||||
unpin()
|
unpin()
|
||||||
selectAll(false, false)
|
selectAll(selected = false, toast = false)
|
||||||
}
|
}
|
||||||
downloadButton!!.setOnClickListener {
|
downloadButton!!.setOnClickListener {
|
||||||
downloadBackground(false)
|
downloadBackground(false)
|
||||||
selectAll(false, false)
|
selectAll(selected = false, toast = false)
|
||||||
}
|
}
|
||||||
deleteButton!!.setOnClickListener {
|
deleteButton!!.setOnClickListener {
|
||||||
delete()
|
delete()
|
||||||
selectAll(false, false)
|
selectAll(selected = false, toast = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
registerForContextMenu(albumListView!!)
|
registerForContextMenu(albumListView!!)
|
||||||
|
@ -256,30 +257,14 @@ class SelectAlbumFragment : Fragment() {
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
||||||
)
|
)
|
||||||
|
|
||||||
triggerLoad(refresh, id, name, playlistId, playlistName, podcastChannelId, shareId, shareName, albumListType, albumListTitle, albumListSize, albumListOffset, genreName, getStarredTracks, getVideos, getRandomTracks, isAlbum, parentId)
|
fun setTitle(name: String?) {
|
||||||
|
setTitle(this@SelectAlbumFragment, name)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
fun setTitle(name: Int) {
|
||||||
|
setTitle(this@SelectAlbumFragment, name)
|
||||||
|
}
|
||||||
|
|
||||||
private fun triggerLoad(
|
|
||||||
refresh: Boolean,
|
|
||||||
id: String?,
|
|
||||||
name: String?,
|
|
||||||
playlistId: String?,
|
|
||||||
playlistName: String?,
|
|
||||||
podcastChannelId: String?,
|
|
||||||
shareId: String?,
|
|
||||||
shareName: String?,
|
|
||||||
albumListType: String?,
|
|
||||||
albumListTitle: Int,
|
|
||||||
albumListSize: Int,
|
|
||||||
albumListOffset: Int,
|
|
||||||
genreName: String?,
|
|
||||||
getStarredTracks: Int,
|
|
||||||
getVideos: Int,
|
|
||||||
getRandomTracks: Int,
|
|
||||||
isAlbum: Boolean,
|
|
||||||
parentId: String?
|
|
||||||
) {
|
|
||||||
serverSettingsModel.viewModelScope.launch {
|
serverSettingsModel.viewModelScope.launch {
|
||||||
refreshAlbumListView!!.isRefreshing = true
|
refreshAlbumListView!!.isRefreshing = true
|
||||||
|
|
||||||
|
@ -295,7 +280,7 @@ class SelectAlbumFragment : Fragment() {
|
||||||
setTitle(shareName)
|
setTitle(shareName)
|
||||||
model.getShare(shareId, shareName)
|
model.getShare(shareId, shareName)
|
||||||
} else if (albumListType != null) {
|
} else if (albumListType != null) {
|
||||||
setTitle(this@SelectAlbumFragment, albumListTitle)
|
setTitle(albumListTitle)
|
||||||
model.getAlbumList(albumListType, albumListSize, albumListOffset)
|
model.getAlbumList(albumListType, albumListSize, albumListOffset)
|
||||||
} else if (genreName != null) {
|
} else if (genreName != null) {
|
||||||
setTitle(genreName)
|
setTitle(genreName)
|
||||||
|
@ -304,10 +289,10 @@ class SelectAlbumFragment : Fragment() {
|
||||||
setTitle(getString(R.string.main_songs_starred))
|
setTitle(getString(R.string.main_songs_starred))
|
||||||
model.getStarred()
|
model.getStarred()
|
||||||
} else if (getVideos != 0) {
|
} else if (getVideos != 0) {
|
||||||
setTitle(this@SelectAlbumFragment, R.string.main_videos)
|
setTitle(R.string.main_videos)
|
||||||
model.getVideos(refresh)
|
model.getVideos(refresh)
|
||||||
} else if (getRandomTracks != 0) {
|
} else if (getRandomTracks != 0) {
|
||||||
setTitle(this@SelectAlbumFragment, R.string.main_songs_random)
|
setTitle(R.string.main_songs_random)
|
||||||
model.getRandom(albumListSize)
|
model.getRandom(albumListSize)
|
||||||
} else {
|
} else {
|
||||||
setTitle(name)
|
setTitle(name)
|
||||||
|
@ -326,11 +311,6 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setTitle(name: String?) {
|
|
||||||
setTitle(this@SelectAlbumFragment, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateContextMenu(menu: ContextMenu, view: View, menuInfo: ContextMenuInfo?) {
|
override fun onCreateContextMenu(menu: ContextMenu, view: View, menuInfo: ContextMenuInfo?) {
|
||||||
super.onCreateContextMenu(menu, view, menuInfo)
|
super.onCreateContextMenu(menu, view, menuInfo)
|
||||||
val info = menuInfo as AdapterContextMenuInfo?
|
val info = menuInfo as AdapterContextMenuInfo?
|
||||||
|
@ -366,32 +346,44 @@ class SelectAlbumFragment : Fragment() {
|
||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.album_menu_play_now -> {
|
R.id.album_menu_play_now -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = false, append = false, autoPlay = true, shuffle = false, background = false, playNext = false, unpin = false, isArtist = false
|
this, entryId, save = false, append = false,
|
||||||
|
autoPlay = true, shuffle = false, background = false,
|
||||||
|
playNext = false, unpin = false, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.album_menu_play_next -> {
|
R.id.album_menu_play_next -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = false, append = false, autoPlay = false, shuffle = false, background = false, playNext = true, unpin = false, isArtist = false
|
this, entryId, save = false, append = false,
|
||||||
|
autoPlay = false, shuffle = false, background = false,
|
||||||
|
playNext = true, unpin = false, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.album_menu_play_last -> {
|
R.id.album_menu_play_last -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = false, append = true, autoPlay = false, shuffle = false, background = false, playNext = false, unpin = false, isArtist = false
|
this, entryId, save = false, append = true,
|
||||||
|
autoPlay = false, shuffle = false, background = false,
|
||||||
|
playNext = false, unpin = false, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.album_menu_pin -> {
|
R.id.album_menu_pin -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = true, append = true, autoPlay = false, shuffle = false, background = false, playNext = false, unpin = false, isArtist = false
|
this, entryId, save = true, append = true,
|
||||||
|
autoPlay = false, shuffle = false, background = false,
|
||||||
|
playNext = false, unpin = false, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.album_menu_unpin -> {
|
R.id.album_menu_unpin -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = false, append = false, autoPlay = false, shuffle = false, background = false, playNext = false, unpin = true, isArtist = false
|
this, entryId, save = false, append = false,
|
||||||
|
autoPlay = false, shuffle = false, background = false,
|
||||||
|
playNext = false, unpin = true, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.album_menu_download -> {
|
R.id.album_menu_download -> {
|
||||||
downloadHandler.downloadRecursively(
|
downloadHandler.downloadRecursively(
|
||||||
this, entryId, save = false, append = false, autoPlay = false, shuffle = false, background = true, playNext = false, unpin = false, isArtist = false
|
this, entryId, save = false, append = false,
|
||||||
|
autoPlay = false, shuffle = false, background = true,
|
||||||
|
playNext = false, unpin = false, isArtist = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
R.id.select_album_play_all -> {
|
R.id.select_album_play_all -> {
|
||||||
|
@ -401,8 +393,8 @@ class SelectAlbumFragment : Fragment() {
|
||||||
val entries: MutableList<MusicDirectory.Entry?> = ArrayList(1)
|
val entries: MutableList<MusicDirectory.Entry?> = ArrayList(1)
|
||||||
entries.add(entry)
|
entries.add(entry)
|
||||||
shareHandler.createShare(
|
shareHandler.createShare(
|
||||||
this, entries, refreshAlbumListView,
|
this, entries, refreshAlbumListView,
|
||||||
cancellationToken!!
|
cancellationToken!!
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -460,7 +452,7 @@ class SelectAlbumFragment : Fragment() {
|
||||||
if (selectedSongs.isNotEmpty()) {
|
if (selectedSongs.isNotEmpty()) {
|
||||||
downloadHandler.download(
|
downloadHandler.download(
|
||||||
this, append, false, !append, playNext = false,
|
this, append, false, !append, playNext = false,
|
||||||
shuffle = false, songs = selectedSongs
|
shuffle = false, songs = selectedSongs
|
||||||
)
|
)
|
||||||
selectAll(selected = false, toast = false)
|
selectAll(selected = false, toast = false)
|
||||||
} else {
|
} else {
|
||||||
|
@ -497,8 +489,6 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun selectAllOrNone() {
|
private fun selectAllOrNone() {
|
||||||
var someUnselected = false
|
var someUnselected = false
|
||||||
val count = albumListView!!.count
|
val count = albumListView!!.count
|
||||||
|
@ -610,7 +600,7 @@ class SelectAlbumFragment : Fragment() {
|
||||||
var songs = getSelectedSongs(albumListView)
|
var songs = getSelectedSongs(albumListView)
|
||||||
|
|
||||||
if (songs.isEmpty()) {
|
if (songs.isEmpty()) {
|
||||||
selectAll(true, false)
|
selectAll(selected = true, toast = false)
|
||||||
songs = getSelectedSongs(albumListView)
|
songs = getSelectedSongs(albumListView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +618,16 @@ class SelectAlbumFragment : Fragment() {
|
||||||
mediaPlayerController.unpin(songs)
|
mediaPlayerController.unpin(songs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val albumListObserver = Observer<MusicDirectory> { musicDirectory ->
|
private val musicFolderObserver = Observer<List<MusicFolder>> { changedFolders ->
|
||||||
|
if (changedFolders != null) {
|
||||||
|
selectFolderHeader!!.setData(
|
||||||
|
activeServerProvider.getActiveServer().musicFolderId,
|
||||||
|
changedFolders
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val albumListObserver = Observer<MusicDirectory> { musicDirectory ->
|
||||||
if (musicDirectory.getChildren().isNotEmpty()) {
|
if (musicDirectory.getChildren().isNotEmpty()) {
|
||||||
pinButton!!.visibility = View.GONE
|
pinButton!!.visibility = View.GONE
|
||||||
unpinButton!!.visibility = View.GONE
|
unpinButton!!.visibility = View.GONE
|
||||||
|
@ -637,35 +636,35 @@ class SelectAlbumFragment : Fragment() {
|
||||||
|
|
||||||
// Hide more button when results are less than album list size
|
// Hide more button when results are less than album list size
|
||||||
if (musicDirectory.getChildren().size < requireArguments().getInt(
|
if (musicDirectory.getChildren().size < requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
moreButton!!.visibility = View.GONE
|
moreButton!!.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
moreButton!!.visibility = View.VISIBLE
|
moreButton!!.visibility = View.VISIBLE
|
||||||
moreButton!!.setOnClickListener {
|
moreButton!!.setOnClickListener {
|
||||||
val theAlbumListTitle = requireArguments().getInt(
|
val theAlbumListTitle = requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0
|
||||||
)
|
)
|
||||||
val type = requireArguments().getString(
|
val type = requireArguments().getString(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE
|
||||||
)
|
)
|
||||||
val theSize = requireArguments().getInt(
|
val theSize = requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
||||||
)
|
)
|
||||||
val theOffset = requireArguments().getInt(
|
val theOffset = requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
||||||
) + theSize
|
) + theSize
|
||||||
|
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putInt(
|
bundle.putInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, theAlbumListTitle
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, theAlbumListTitle
|
||||||
)
|
)
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type)
|
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type)
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, theSize)
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, theSize)
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, theOffset)
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, theOffset)
|
||||||
Navigation.findNavController(requireView()).navigate(
|
Navigation.findNavController(requireView()).navigate(
|
||||||
R.id.selectAlbumFragment, bundle
|
R.id.selectAlbumFragment, bundle
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,21 +675,12 @@ class SelectAlbumFragment : Fragment() {
|
||||||
updateInterfaceWithEntries(musicDirectory)
|
updateInterfaceWithEntries(musicDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val musicFolderObserver = Observer<List<MusicFolder>> { changedFolders ->
|
|
||||||
if (changedFolders != null) {
|
|
||||||
selectFolderHeader!!.setData(
|
|
||||||
activeServerProvider.getActiveServer().musicFolderId,
|
|
||||||
changedFolders
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val songsForGenreObserver = Observer<MusicDirectory> { musicDirectory ->
|
private val songsForGenreObserver = Observer<MusicDirectory> { musicDirectory ->
|
||||||
|
|
||||||
// Hide more button when results are less than album list size
|
// Hide more button when results are less than album list size
|
||||||
if (musicDirectory.getChildren().size < requireArguments().getInt(
|
if (musicDirectory.getChildren().size < requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
moreButton!!.visibility = View.GONE
|
moreButton!!.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
@ -701,7 +691,7 @@ class SelectAlbumFragment : Fragment() {
|
||||||
val theGenre = requireArguments().getString(Constants.INTENT_EXTRA_NAME_GENRE_NAME)
|
val theGenre = requireArguments().getString(Constants.INTENT_EXTRA_NAME_GENRE_NAME)
|
||||||
val size = requireArguments().getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0)
|
val size = requireArguments().getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0)
|
||||||
val theOffset = requireArguments().getInt(
|
val theOffset = requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
||||||
) + size
|
) + size
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(Constants.INTENT_EXTRA_NAME_GENRE_NAME, theGenre)
|
bundle.putString(Constants.INTENT_EXTRA_NAME_GENRE_NAME, theGenre)
|
||||||
|
@ -713,7 +703,6 @@ class SelectAlbumFragment : Fragment() {
|
||||||
updateInterfaceWithEntries(musicDirectory)
|
updateInterfaceWithEntries(musicDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our old "done" function
|
|
||||||
private val defaultObserver = Observer(this::updateInterfaceWithEntries)
|
private val defaultObserver = Observer(this::updateInterfaceWithEntries)
|
||||||
|
|
||||||
private fun updateInterfaceWithEntries(musicDirectory: MusicDirectory) {
|
private fun updateInterfaceWithEntries(musicDirectory: MusicDirectory) {
|
||||||
|
@ -742,8 +731,8 @@ class SelectAlbumFragment : Fragment() {
|
||||||
val intentAlbumName = requireArguments().getString(Constants.INTENT_EXTRA_NAME_NAME)
|
val intentAlbumName = requireArguments().getString(Constants.INTENT_EXTRA_NAME_NAME)
|
||||||
val directoryName = musicDirectory.name
|
val directoryName = musicDirectory.name
|
||||||
val header = createHeader(
|
val header = createHeader(
|
||||||
entries, intentAlbumName ?: directoryName,
|
entries, intentAlbumName ?: directoryName,
|
||||||
songCount
|
songCount
|
||||||
)
|
)
|
||||||
if (header != null && albumListView!!.headerViewsCount == 0) {
|
if (header != null && albumListView!!.headerViewsCount == 0) {
|
||||||
albumListView!!.addHeaderView(header, null, false)
|
albumListView!!.addHeaderView(header, null, false)
|
||||||
|
@ -766,14 +755,14 @@ class SelectAlbumFragment : Fragment() {
|
||||||
if (requireArguments().getInt(Constants.INTENT_EXTRA_NAME_RANDOM, 0) > 0) {
|
if (requireArguments().getInt(Constants.INTENT_EXTRA_NAME_RANDOM, 0) > 0) {
|
||||||
moreButton!!.setOnClickListener {
|
moreButton!!.setOnClickListener {
|
||||||
val offset = requireArguments().getInt(
|
val offset = requireArguments().getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
||||||
) + listSize
|
) + listSize
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_RANDOM, 1)
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_RANDOM, 1)
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, listSize)
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, listSize)
|
||||||
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset)
|
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset)
|
||||||
Navigation.findNavController(requireView()).navigate(
|
Navigation.findNavController(requireView()).navigate(
|
||||||
R.id.selectAlbumFragment, bundle
|
R.id.selectAlbumFragment, bundle
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -803,7 +792,10 @@ class SelectAlbumFragment : Fragment() {
|
||||||
|
|
||||||
enableButtons()
|
enableButtons()
|
||||||
|
|
||||||
val isAlbumList = requireArguments().containsKey(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE)
|
val isAlbumList = requireArguments().containsKey(
|
||||||
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE
|
||||||
|
)
|
||||||
|
|
||||||
playAllButtonVisible = !(isAlbumList || entries.isEmpty()) && !allVideos
|
playAllButtonVisible = !(isAlbumList || entries.isEmpty()) && !allVideos
|
||||||
shareButtonVisible = !isOffline(context) && songCount > 0
|
shareButtonVisible = !isOffline(context) && songCount > 0
|
||||||
|
|
||||||
|
@ -823,15 +815,15 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
albumListView!!.adapter = EntryAdapter(
|
albumListView!!.adapter = EntryAdapter(
|
||||||
context,
|
context,
|
||||||
imageLoaderProvider.getImageLoader(), entries, true
|
imageLoaderProvider.getImageLoader(), entries, true
|
||||||
)
|
)
|
||||||
|
|
||||||
val playAll = requireArguments().getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false)
|
val playAll = requireArguments().getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false)
|
||||||
if (playAll && songCount > 0) {
|
if (playAll && songCount > 0) {
|
||||||
playAll(
|
playAll(
|
||||||
requireArguments().getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false),
|
requireArguments().getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false),
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,15 +831,15 @@ class SelectAlbumFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createHeader(
|
private fun createHeader(
|
||||||
entries: List<MusicDirectory.Entry>,
|
entries: List<MusicDirectory.Entry>,
|
||||||
name: CharSequence?,
|
name: CharSequence?,
|
||||||
songCount: Int
|
songCount: Int
|
||||||
): View? {
|
): View? {
|
||||||
val coverArtView = header!!.findViewById<View>(R.id.select_album_art) as ImageView
|
val coverArtView = header!!.findViewById<View>(R.id.select_album_art) as ImageView
|
||||||
val artworkSelection = random.nextInt(entries.size)
|
val artworkSelection = random.nextInt(entries.size)
|
||||||
imageLoaderProvider.getImageLoader().loadImage(
|
imageLoaderProvider.getImageLoader().loadImage(
|
||||||
coverArtView, entries[artworkSelection], false,
|
coverArtView, entries[artworkSelection], false,
|
||||||
Util.getAlbumImageSize(context), false, true
|
Util.getAlbumImageSize(context), false, true
|
||||||
)
|
)
|
||||||
|
|
||||||
val albumHeader = AlbumHeader.processEntries(context, entries)
|
val albumHeader = AlbumHeader.processEntries(context, entries)
|
||||||
|
@ -890,8 +882,8 @@ class SelectAlbumFragment : Fragment() {
|
||||||
|
|
||||||
val songCountView = header!!.findViewById<TextView>(R.id.select_album_song_count)
|
val songCountView = header!!.findViewById<TextView>(R.id.select_album_song_count)
|
||||||
val songs = resources.getQuantityString(
|
val songs = resources.getQuantityString(
|
||||||
R.plurals.select_album_n_songs, songCount,
|
R.plurals.select_album_n_songs, songCount,
|
||||||
songCount
|
songCount
|
||||||
)
|
)
|
||||||
songCountView.text = songs
|
songCountView.text = songs
|
||||||
|
|
||||||
|
@ -903,7 +895,6 @@ class SelectAlbumFragment : Fragment() {
|
||||||
return header
|
return header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getSelectedSongs(albumListView: ListView?): List<MusicDirectory.Entry?> {
|
private fun getSelectedSongs(albumListView: ListView?): List<MusicDirectory.Entry?> {
|
||||||
val songs: MutableList<MusicDirectory.Entry?> = ArrayList(10)
|
val songs: MutableList<MusicDirectory.Entry?> = ArrayList(10)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue