use of org.moire.ultrasonic.util.MergeAdapter in project ultrasonic by ultrasonic.
the class SearchActivity method populateList.
private void populateList() {
mergeAdapter = new MergeAdapter();
mergeAdapter.addView(searchButton, true);
if (searchResult != null) {
List<Artist> artists = searchResult.getArtists();
if (!artists.isEmpty()) {
mergeAdapter.addView(artistsHeading);
List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
artistAdapter = new ArtistAdapter(this, displayedArtists);
mergeAdapter.addAdapter(artistAdapter);
if (artists.size() > DEFAULT_ARTISTS) {
moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
}
}
List<MusicDirectory.Entry> albums = searchResult.getAlbums();
if (!albums.isEmpty()) {
mergeAdapter.addView(albumsHeading);
List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
mergeAdapter.addAdapter(albumAdapter);
if (albums.size() > DEFAULT_ALBUMS) {
moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
}
}
List<MusicDirectory.Entry> songs = searchResult.getSongs();
if (!songs.isEmpty()) {
mergeAdapter.addView(songsHeading);
List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
mergeAdapter.addAdapter(songAdapter);
if (songs.size() > DEFAULT_SONGS) {
moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
}
}
boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
}
list.setAdapter(mergeAdapter);
}
use of org.moire.ultrasonic.util.MergeAdapter in project ultrasonic by ultrasonic.
the class MainActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
setResult(Constants.RESULT_CLOSE_ALL);
if (getDownloadService() != null) {
getDownloadService().stopJukeboxService();
}
if (getImageLoader() != null) {
getImageLoader().stopImageLoader();
}
finish();
exit();
return;
}
setContentView(R.layout.main);
loadSettings();
final View buttons = LayoutInflater.from(this).inflate(R.layout.main_buttons, null);
final View serverButton = buttons.findViewById(R.id.main_select_server);
final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2);
final View musicTitle = buttons.findViewById(R.id.main_music);
final View artistsButton = buttons.findViewById(R.id.main_artists_button);
final View albumsButton = buttons.findViewById(R.id.main_albums_button);
final View genresButton = buttons.findViewById(R.id.main_genres_button);
final View videosTitle = buttons.findViewById(R.id.main_videos_title);
final View songsTitle = buttons.findViewById(R.id.main_songs);
final View randomSongsButton = buttons.findViewById(R.id.main_songs_button);
final View songsStarredButton = buttons.findViewById(R.id.main_songs_starred);
final View albumsTitle = buttons.findViewById(R.id.main_albums);
final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest);
final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random);
final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest);
final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred);
final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent);
final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent);
final View albumsAlphaByNameButton = buttons.findViewById(R.id.main_albums_alphaByName);
final View albumsAlphaByArtistButton = buttons.findViewById(R.id.main_albums_alphaByArtist);
final View videosButton = buttons.findViewById(R.id.main_videos);
final View dummyView = findViewById(R.id.main_dummy);
boolean shouldShowDialog = false;
if (!getActiveServerEnabled()) {
shouldShowDialog = true;
Util.setActiveServer(this, 0);
}
int instance = Util.getActiveServer(this);
String name = Util.getServerName(this, instance);
if (name == null) {
shouldShowDialog = true;
Util.setActiveServer(this, 0);
instance = Util.getActiveServer(this);
name = Util.getServerName(this, instance);
}
serverTextView.setText(name);
final ListView list = (ListView) findViewById(R.id.main_list);
final MergeAdapter adapter = new MergeAdapter();
adapter.addViews(Collections.singletonList(serverButton), true);
if (!Util.isOffline(this)) {
adapter.addView(musicTitle, false);
adapter.addViews(asList(artistsButton, albumsButton, genresButton), true);
adapter.addView(songsTitle, false);
adapter.addViews(asList(randomSongsButton, songsStarredButton), true);
adapter.addView(albumsTitle, false);
if (Util.getShouldUseId3Tags(MainActivity.this)) {
shouldUseId3 = true;
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton, albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
} else {
shouldUseId3 = false;
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton, albumsHighestButton, albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
}
adapter.addView(videosTitle, false);
adapter.addViews(Collections.singletonList(videosButton), true);
if (Util.isNetworkConnected(this)) {
new PingTask(this, false).execute();
}
}
list.setAdapter(adapter);
registerForContextMenu(dummyView);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view == serverButton) {
dummyView.showContextMenu();
} else if (view == albumsNewestButton) {
showAlbumList("newest", R.string.main_albums_newest);
} else if (view == albumsRandomButton) {
showAlbumList("random", R.string.main_albums_random);
} else if (view == albumsHighestButton) {
showAlbumList("highest", R.string.main_albums_highest);
} else if (view == albumsRecentButton) {
showAlbumList("recent", R.string.main_albums_recent);
} else if (view == albumsFrequentButton) {
showAlbumList("frequent", R.string.main_albums_frequent);
} else if (view == albumsStarredButton) {
showAlbumList(Constants.STARRED, R.string.main_albums_starred);
} else if (view == albumsAlphaByNameButton) {
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_alphaByName);
} else if (view == albumsAlphaByArtistButton) {
showAlbumList("alphabeticalByArtist", R.string.main_albums_alphaByArtist);
} else if (view == songsStarredButton) {
showStarredSongs();
} else if (view == artistsButton) {
showArtists();
} else if (view == albumsButton) {
showAlbumList(Constants.ALPHABETICAL_BY_NAME, R.string.main_albums_title);
} else if (view == randomSongsButton) {
showRandomSongs();
} else if (view == genresButton) {
showGenres();
} else if (view == videosButton) {
showVideos();
}
}
});
final View homeMenuItem = findViewById(R.id.menu_home);
menuDrawer.setActiveView(homeMenuItem);
setActionBarTitle(R.string.common_appname);
setTitle(R.string.common_appname);
// Remember the current theme.
theme = Util.getTheme(this);
showInfoDialog(shouldShowDialog);
}
use of org.moire.ultrasonic.util.MergeAdapter in project ultrasonic by ultrasonic.
the class SearchActivity method onNewIntent.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
boolean autoPlay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
boolean requestSearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false);
if (query != null) {
mergeAdapter = new MergeAdapter();
list.setAdapter(mergeAdapter);
search(query, autoPlay);
} else {
populateList();
if (requestSearch)
onSearchRequested();
}
}
Aggregations