use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.
the class SearchActivity method search.
private void search(final String query, final boolean autoplay) {
final int maxArtists = Util.getMaxArtists(this);
final int maxAlbums = Util.getMaxAlbums(this);
final int maxSongs = Util.getMaxSongs(this);
BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this, true) {
@Override
protected SearchResult doInBackground() throws Throwable {
SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs);
MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
licenseValid = service.isLicenseValid(SearchActivity.this, this);
return service.search(criteria, SearchActivity.this, this);
}
@Override
protected void done(SearchResult result) {
searchResult = result;
populateList();
if (autoplay) {
autoplay();
}
}
};
task.execute();
}
use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.
the class SelectArtistActivity method load.
private void load() {
BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this, true) {
@Override
protected Indexes doInBackground() throws Throwable {
boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
boolean isOffline = Util.isOffline(SelectArtistActivity.this);
boolean useId3Tags = Util.getShouldUseId3Tags(SelectArtistActivity.this);
if (!isOffline && !useId3Tags) {
musicFolders = musicService.getMusicFolders(refresh, SelectArtistActivity.this, this);
}
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
return !isOffline && useId3Tags ? musicService.getArtists(refresh, SelectArtistActivity.this, this) : musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
}
@Override
protected void done(Indexes result) {
if (result != null) {
List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
artists.addAll(result.getShortcuts());
artists.addAll(result.getArtists());
artistListView.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
}
// Display selected music folder
if (musicFolders != null) {
String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
if (musicFolderId == null) {
if (folderName != null) {
folderName.setText(R.string.select_artist_all_folders);
}
} else {
for (MusicFolder musicFolder : musicFolders) {
if (musicFolder.getId().equals(musicFolderId)) {
if (folderName != null) {
folderName.setText(musicFolder.getName());
}
break;
}
}
}
}
}
};
task.execute();
}
use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.
the class SubsonicTabActivity method share.
public void share() {
BackgroundTask<Share> task = new TabActivityBackgroundTask<Share>(this, true) {
@Override
protected Share doInBackground() throws Throwable {
List<String> ids = new ArrayList<String>();
if (shareDetails.Entries.isEmpty()) {
ids.add(getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID));
} else {
for (Entry entry : shareDetails.Entries) {
ids.add(entry.getId());
}
}
MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
long timeInMillis = 0;
if (shareDetails.Expiration != 0) {
timeInMillis = shareDetails.Expiration;
}
List<Share> shares = musicService.createShare(ids, shareDetails.Description, timeInMillis, SubsonicTabActivity.this, this);
return shares.get(0);
}
@Override
protected void done(Share result) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, String.format("%s\n\n%s", Util.getShareGreeting(SubsonicTabActivity.this), result.getUrl()));
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_via)));
}
};
task.execute();
}
use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.
the class ChatActivity method sendMessage.
private void sendMessage() {
if (messageEditText != null) {
final String message;
Editable text = messageEditText.getText();
if (text == null) {
return;
}
message = text.toString();
if (!Util.isNullOrWhiteSpace(message)) {
messageEditText.setText("");
BackgroundTask<Void> task = new TabActivityBackgroundTask<Void>(ChatActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(ChatActivity.this);
musicService.addChatMessage(message, ChatActivity.this, this);
return null;
}
@Override
protected void done(Void result) {
load();
}
};
task.execute();
}
}
}
use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.
the class ChatActivity method load.
private synchronized void load() {
BackgroundTask<List<ChatMessage>> task = new TabActivityBackgroundTask<List<ChatMessage>>(this, false) {
@Override
protected List<ChatMessage> doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(ChatActivity.this);
return musicService.getChatMessages(lastChatMessageTime, ChatActivity.this, this);
}
@Override
protected void done(List<ChatMessage> result) {
if (result != null && !result.isEmpty()) {
// Reset lastChatMessageTime if we have a newer message
for (ChatMessage message : result) {
if (message.getTime() > lastChatMessageTime) {
lastChatMessageTime = message.getTime();
}
}
// Reverse results to show them on the bottom
Collections.reverse(result);
messageList.addAll(result);
ListAdapter chatAdapter = new ChatAdapter(ChatActivity.this, messageList);
chatListView.setAdapter(chatAdapter);
}
}
};
task.execute();
}
Aggregations