use of org.moire.ultrasonic.util.TimeSpanPicker 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();
}
Aggregations