use of org.moire.ultrasonic.util.LoadingTask in project ultrasonic by ultrasonic.
the class SelectPlaylistActivity method deletePlaylist.
private void deletePlaylist(final Playlist playlist) {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.common_confirm).setMessage(getResources().getString(R.string.delete_playlist, playlist.getName())).setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LoadingTask<Void>(SelectPlaylistActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
musicService.deletePlaylist(playlist.getId(), SelectPlaylistActivity.this, null);
return null;
}
@Override
protected void done(Void result) {
playlistAdapter.remove(playlist);
playlistAdapter.notifyDataSetChanged();
Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.menu_deleted_playlist, playlist.getName()));
}
@Override
protected void error(Throwable error) {
String msg;
msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_playlist_error, playlist.getName()), getErrorMessage(error));
Util.toast(SelectPlaylistActivity.this, msg, false);
}
}.execute();
}
}).setNegativeButton(R.string.common_cancel, null).show();
}
use of org.moire.ultrasonic.util.LoadingTask in project ultrasonic by ultrasonic.
the class SelectPlaylistActivity method updatePlaylistInfo.
private void updatePlaylistInfo(final Playlist playlist) {
View dialogView = getLayoutInflater().inflate(R.layout.update_playlist, null);
if (dialogView == null) {
return;
}
final EditText nameBox = (EditText) dialogView.findViewById(R.id.get_playlist_name);
final EditText commentBox = (EditText) dialogView.findViewById(R.id.get_playlist_comment);
final CheckBox publicBox = (CheckBox) dialogView.findViewById(R.id.get_playlist_public);
nameBox.setText(playlist.getName());
commentBox.setText(playlist.getComment());
Boolean pub = playlist.getPublic();
if (pub == null) {
publicBox.setEnabled(false);
} else {
publicBox.setChecked(pub);
}
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setTitle(R.string.playlist_update_info);
alertDialog.setView(dialogView);
alertDialog.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LoadingTask<Void>(SelectPlaylistActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
Editable nameBoxText = nameBox.getText();
Editable commentBoxText = commentBox.getText();
String name = nameBoxText != null ? nameBoxText.toString() : null;
String comment = commentBoxText != null ? commentBoxText.toString() : null;
MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
musicService.updatePlaylist(playlist.getId(), name, comment, publicBox.isChecked(), SelectPlaylistActivity.this, null);
return null;
}
@Override
protected void done(Void result) {
refresh();
Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.playlist_updated_info, playlist.getName()));
}
@Override
protected void error(Throwable error) {
String msg;
msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, playlist.getName()), getErrorMessage(error));
Util.toast(SelectPlaylistActivity.this, msg, false);
}
}.execute();
}
});
alertDialog.setNegativeButton(R.string.common_cancel, null);
alertDialog.show();
}
use of org.moire.ultrasonic.util.LoadingTask in project ultrasonic by ultrasonic.
the class ShareActivity method updateShareInfo.
private void updateShareInfo(final Share share) {
View dialogView = getLayoutInflater().inflate(R.layout.share_details, null);
if (dialogView == null) {
return;
}
final EditText shareDescription = (EditText) dialogView.findViewById(R.id.share_description);
final TimeSpanPicker timeSpanPicker = (TimeSpanPicker) dialogView.findViewById(R.id.date_picker);
shareDescription.setText(share.getDescription());
CheckBox hideDialogCheckBox = (CheckBox) dialogView.findViewById(R.id.hide_dialog);
CheckBox saveAsDefaultsCheckBox = (CheckBox) dialogView.findViewById(R.id.save_as_defaults);
CheckBox noExpirationCheckBox = (CheckBox) dialogView.findViewById(R.id.timeSpanDisableCheckBox);
noExpirationCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
timeSpanPicker.setEnabled(!b);
}
});
noExpirationCheckBox.setChecked(true);
timeSpanPicker.setTimeSpanDisableText(getResources().getText(R.string.no_expiration));
hideDialogCheckBox.setVisibility(View.GONE);
saveAsDefaultsCheckBox.setVisibility(View.GONE);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setTitle(R.string.playlist_update_info);
alertDialog.setView(dialogView);
alertDialog.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LoadingTask<Void>(ShareActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
long millis = timeSpanPicker.getTimeSpan().getTotalMilliseconds();
if (millis > 0) {
millis = TimeSpan.getCurrentTime().add(millis).getTotalMilliseconds();
}
Editable shareDescriptionText = shareDescription.getText();
String description = shareDescriptionText != null ? shareDescriptionText.toString() : null;
MusicService musicService = MusicServiceFactory.getMusicService(ShareActivity.this);
musicService.updateShare(share.getId(), description, millis, ShareActivity.this, null);
return null;
}
@Override
protected void done(Void result) {
refresh();
Util.toast(ShareActivity.this, getResources().getString(R.string.playlist_updated_info, share.getName()));
}
@Override
protected void error(Throwable error) {
String msg;
msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, share.getName()), getErrorMessage(error));
Util.toast(ShareActivity.this, msg, false);
}
}.execute();
}
});
alertDialog.setNegativeButton(R.string.common_cancel, null);
alertDialog.show();
}
use of org.moire.ultrasonic.util.LoadingTask in project ultrasonic by ultrasonic.
the class ShareActivity method deleteShare.
private void deleteShare(final Share share) {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.common_confirm).setMessage(getResources().getString(R.string.delete_playlist, share.getName())).setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LoadingTask<Void>(ShareActivity.this, false) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(ShareActivity.this);
musicService.deleteShare(share.getId(), ShareActivity.this, null);
return null;
}
@Override
protected void done(Void result) {
shareAdapter.remove(share);
shareAdapter.notifyDataSetChanged();
Util.toast(ShareActivity.this, getResources().getString(R.string.menu_deleted_share, share.getName()));
}
@Override
protected void error(Throwable error) {
String msg;
msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_share_error, share.getName()), getErrorMessage(error));
Util.toast(ShareActivity.this, msg, false);
}
}.execute();
}
}).setNegativeButton(R.string.common_cancel, null).show();
}
Aggregations