use of org.moire.ultrasonic.service.MusicService 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.service.MusicService in project ultrasonic by ultrasonic.
the class ServerSettingsFragment method testConnection.
private void testConnection() {
ModalBackgroundTask<Boolean> task = new ModalBackgroundTask<Boolean>(getActivity(), false) {
private int previousInstance;
@Override
protected Boolean doInBackground() throws Throwable {
updateProgress(R.string.settings_testing_connection);
final Context context = getActivity();
previousInstance = Util.getActiveServer(context);
Util.setActiveServer(context, serverId);
try {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.ping(context, this);
return musicService.isLicenseValid(context, null);
} finally {
Util.setActiveServer(context, previousInstance);
}
}
@Override
protected void done(Boolean licenseValid) {
if (licenseValid) {
Util.toast(getActivity(), R.string.settings_testing_ok);
} else {
Util.toast(getActivity(), R.string.settings_testing_unlicensed);
}
}
@Override
protected void cancel() {
super.cancel();
Util.setActiveServer(getActivity(), previousInstance);
}
@Override
protected void error(Throwable error) {
Log.w(LOG_TAG, error.toString(), error);
new ErrorDialog(getActivity(), String.format("%s %s", getResources().getString(R.string.settings_connection_failure), getErrorMessage(error)), false);
}
};
task.execute();
}
use of org.moire.ultrasonic.service.MusicService 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.service.MusicService 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