show the Remove/delete current song menu buttons when appropriate

This commit is contained in:
tibbi 2018-05-20 16:10:42 +02:00
parent 9578c6f088
commit 1fcbf186a6

View file

@ -178,14 +178,11 @@ class MainActivity : SimpleActivity(), SongListListener {
val autoplay = menu.findItem(R.id.toggle_autoplay)
autoplay.title = getString(if (config.autoplay) R.string.disable_autoplay else R.string.enable_autoplay)
val isSongSelected = MusicService.mCurrSong != null
menu.apply {
findItem(R.id.sort).isVisible = !isThirdPartyIntent
findItem(R.id.toggle_autoplay).isVisible = !isThirdPartyIntent
findItem(R.id.sort).isVisible = !isThirdPartyIntent
findItem(R.id.open_playlist).isVisible = !isThirdPartyIntent
findItem(R.id.remove_current).isVisible = !isThirdPartyIntent && isSongSelected
findItem(R.id.delete_current).isVisible = !isThirdPartyIntent && isSongSelected
findItem(R.id.add_folder_to_playlist).isVisible = !isThirdPartyIntent
findItem(R.id.add_file_to_playlist).isVisible = !isThirdPartyIntent
findItem(R.id.remove_playlist).isVisible = !isThirdPartyIntent
@ -194,6 +191,15 @@ class MainActivity : SimpleActivity(), SongListListener {
return true
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
val isSongSelected = MusicService.mCurrSong != null
menu.apply {
findItem(R.id.remove_current).isVisible = !isThirdPartyIntent && isSongSelected
findItem(R.id.delete_current).isVisible = !isThirdPartyIntent && isSongSelected
}
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.sort -> showSortingDialog()