use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.
the class DownloadActivity method menuItemSelected.
private boolean menuItemSelected(final int menuItemId, final DownloadFile song) {
Entry entry = null;
if (song != null) {
entry = song.getSong();
}
switch(menuItemId) {
case R.id.menu_show_artist:
if (entry == null) {
return false;
}
if (Util.getShouldUseId3Tags(DownloadActivity.this)) {
Intent intent = new Intent(DownloadActivity.this, SelectAlbumActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getArtistId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getArtist());
intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.getArtistId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true);
startActivityForResultWithoutTransition(DownloadActivity.this, intent);
}
return true;
case R.id.menu_show_album:
if (entry == null) {
return false;
}
Intent intent = new Intent(this, SelectAlbumActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getParent());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getAlbum());
startActivityForResultWithoutTransition(this, intent);
return true;
case R.id.menu_lyrics:
if (entry == null) {
return false;
}
intent = new Intent(this, LyricsActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, entry.getArtist());
intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, entry.getTitle());
startActivityForResultWithoutTransition(this, intent);
return true;
case R.id.menu_remove:
getDownloadService().remove(song);
onDownloadListChanged();
return true;
case R.id.menu_item_screen_on_off:
if (getDownloadService().getKeepScreenOn()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getDownloadService().setKeepScreenOn(false);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getDownloadService().setKeepScreenOn(true);
}
return true;
case R.id.menu_shuffle:
getDownloadService().shuffle();
Util.toast(this, R.string.download_menu_shuffle_notification);
return true;
case R.id.menu_item_equalizer:
startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
return true;
case R.id.menu_item_visualizer:
final boolean active = !visualizerView.isActive();
visualizerView.setActive(active);
if (!visualizerView.isActive()) {
visualizerViewLayout.setVisibility(View.GONE);
} else {
visualizerViewLayout.setVisibility(View.VISIBLE);
}
getDownloadService().setShowVisualization(visualizerView.isActive());
Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
return true;
case R.id.menu_item_jukebox:
final boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
getDownloadService().setJukeboxEnabled(jukeboxEnabled);
Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
return true;
case R.id.menu_item_toggle_list:
toggleFullScreenAlbumArt();
return true;
case R.id.menu_item_clear_playlist:
getDownloadService().setShufflePlayEnabled(false);
getDownloadService().clear();
onDownloadListChanged();
return true;
case R.id.menu_item_save_playlist:
if (!getDownloadService().getSongs().isEmpty()) {
showDialog(DIALOG_SAVE_PLAYLIST);
}
return true;
case R.id.menu_item_star:
if (currentSong == null) {
return true;
}
final boolean isStarred = currentSong.getStarred();
final String id = currentSong.getId();
if (isStarred) {
starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow));
currentSong.setStarred(false);
} else {
starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full));
currentSong.setStarred(true);
}
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
if (isStarred) {
musicService.unstar(id, null, null, DownloadActivity.this, null);
} else {
musicService.star(id, null, null, DownloadActivity.this, null);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
return true;
case R.id.menu_item_bookmark_set:
if (currentSong == null) {
return true;
}
final String songId = currentSong.getId();
final int playerPosition = getDownloadService().getPlayerPosition();
currentSong.setBookmarkPosition(playerPosition);
String bookmarkTime = Util.formatTotalDuration(playerPosition, true);
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
musicService.createBookmark(songId, playerPosition, DownloadActivity.this, null);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
String msg = getResources().getString(R.string.download_bookmark_set_at_position, bookmarkTime);
Util.toast(DownloadActivity.this, msg);
return true;
case R.id.menu_item_bookmark_delete:
if (currentSong == null) {
return true;
}
final String bookmarkSongId = currentSong.getId();
currentSong.setBookmarkPosition(0);
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
musicService.deleteBookmark(bookmarkSongId, DownloadActivity.this, null);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
Util.toast(DownloadActivity.this, R.string.download_bookmark_removed);
return true;
case R.id.menu_item_share:
DownloadService downloadService = getDownloadService();
List<Entry> entries = new ArrayList<Entry>();
if (downloadService != null) {
List<DownloadFile> downloadServiceSongs = downloadService.getSongs();
if (downloadServiceSongs != null) {
for (DownloadFile downloadFile : downloadServiceSongs) {
if (downloadFile != null) {
Entry playlistEntry = downloadFile.getSong();
if (playlistEntry != null) {
entries.add(playlistEntry);
}
}
}
}
}
createShare(entries);
return true;
default:
return false;
}
}
use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.
the class DownloadActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, view, menuInfo);
if (view == playlistView) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position);
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.nowplaying_context, menu);
Entry song = null;
if (downloadFile != null) {
song = downloadFile.getSong();
}
if (song != null && song.getParent() == null) {
MenuItem menuItem = menu.findItem(R.id.menu_show_album);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
if (Util.isOffline(this) || !Util.getShouldUseId3Tags(this)) {
MenuItem menuItem = menu.findItem(R.id.menu_show_artist);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
if (Util.isOffline(this)) {
MenuItem menuItem = menu.findItem(R.id.menu_lyrics);
if (menuItem != null) {
menuItem.setVisible(false);
}
}
}
}
use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.
the class EntryAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Entry entry = getItem(position);
if (entry.isDirectory()) {
AlbumView view;
if (convertView != null && convertView instanceof AlbumView) {
AlbumView currentView = (AlbumView) convertView;
if (currentView.getEntry().equals(entry)) {
return currentView;
} else {
AlbumViewHolder viewHolder = (AlbumViewHolder) currentView.getTag();
view = currentView;
view.setViewHolder(viewHolder);
}
} else {
view = new AlbumView(activity, imageLoader);
view.setLayout();
}
view.setAlbum(entry);
return view;
} else {
SongView view;
if (convertView != null && convertView instanceof SongView) {
SongView currentView = (SongView) convertView;
if (currentView.getEntry().equals(entry)) {
currentView.update();
return currentView;
} else {
SongViewHolder viewHolder = (SongViewHolder) convertView.getTag();
view = currentView;
view.setViewHolder(viewHolder);
}
} else {
view = new SongView(activity);
view.setLayout(entry);
}
view.setSong(entry, checkable, false);
return view;
}
}
use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.
the class SearchActivity method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
if (info == null) {
return true;
}
Object selectedItem = list.getItemAtPosition(info.position);
Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
Entry entry = selectedItem instanceof Entry ? (Entry) selectedItem : null;
String entryId = null;
if (entry != null) {
entryId = entry.getId();
}
String id = artist != null ? artist.getId() : entryId;
if (id == null) {
return true;
}
List<Entry> songs = new ArrayList<Entry>(1);
switch(menuItem.getItemId()) {
case R.id.album_menu_play_now:
downloadRecursively(id, false, false, true, false, false, false, false, false);
break;
case R.id.album_menu_play_next:
downloadRecursively(id, false, true, false, true, false, true, false, false);
break;
case R.id.album_menu_play_last:
downloadRecursively(id, false, true, false, false, false, false, false, false);
break;
case R.id.album_menu_pin:
downloadRecursively(id, true, true, false, false, false, false, false, false);
break;
case R.id.album_menu_unpin:
downloadRecursively(id, false, false, false, false, false, false, true, false);
break;
case R.id.album_menu_download:
downloadRecursively(id, false, false, false, false, true, false, false, false);
break;
case R.id.song_menu_play_now:
if (entry != null) {
songs = new ArrayList<MusicDirectory.Entry>(1);
songs.add(entry);
download(false, false, true, false, false, songs);
}
break;
case R.id.song_menu_play_next:
if (entry != null) {
songs = new ArrayList<MusicDirectory.Entry>(1);
songs.add(entry);
download(true, false, false, true, false, songs);
}
break;
case R.id.song_menu_play_last:
if (entry != null) {
songs = new ArrayList<MusicDirectory.Entry>(1);
songs.add(entry);
download(true, false, false, false, false, songs);
}
break;
case R.id.song_menu_pin:
if (entry != null) {
songs.add(entry);
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_pinned, songs.size(), songs.size()));
downloadBackground(true, songs);
}
break;
case R.id.song_menu_download:
if (entry != null) {
songs.add(entry);
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_downloaded, songs.size(), songs.size()));
downloadBackground(false, songs);
}
break;
case R.id.song_menu_unpin:
if (entry != null) {
songs.add(entry);
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_unpinned, songs.size(), songs.size()));
getDownloadService().unpin(songs);
}
break;
case R.id.menu_item_share:
if (entry != null) {
songs = new ArrayList<MusicDirectory.Entry>(1);
songs.add(entry);
createShare(songs);
}
default:
return super.onContextItemSelected(menuItem);
}
return true;
}
use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.
the class SearchActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
setActionBarTitle(R.string.common_appname);
setActionBarSubtitle(R.string.search_title);
View searchMenuItem = findViewById(R.id.menu_search);
menuDrawer.setActiveView(searchMenuItem);
DEFAULT_ARTISTS = Util.getDefaultArtists(this);
DEFAULT_ALBUMS = Util.getDefaultAlbums(this);
DEFAULT_SONGS = Util.getDefaultSongs(this);
View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
if (buttons != null) {
artistsHeading = buttons.findViewById(R.id.search_artists);
albumsHeading = buttons.findViewById(R.id.search_albums);
songsHeading = buttons.findViewById(R.id.search_songs);
searchButton = (TextView) buttons.findViewById(R.id.search_search);
moreArtistsButton = buttons.findViewById(R.id.search_more_artists);
moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
moreSongsButton = buttons.findViewById(R.id.search_more_songs);
}
list = (ListView) findViewById(R.id.search_list);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view == searchButton) {
onSearchRequested();
} else if (view == moreArtistsButton) {
expandArtists();
} else if (view == moreAlbumsButton) {
expandAlbums();
} else if (view == moreSongsButton) {
expandSongs();
} else {
Object item = parent.getItemAtPosition(position);
if (item instanceof Artist) {
onArtistSelected((Artist) item);
} else if (item instanceof MusicDirectory.Entry) {
MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
if (entry.isDirectory()) {
onAlbumSelected(entry, false);
} else if (entry.isVideo()) {
onVideoSelected(entry);
} else {
onSongSelected(entry, false, true, true, false);
}
}
}
}
});
registerForContextMenu(list);
onNewIntent(getIntent());
}
Aggregations