Search in sources :

Example 1 with TimeSpanPicker

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();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) ApiNotSupportedException(org.moire.ultrasonic.api.subsonic.ApiNotSupportedException) MusicService(org.moire.ultrasonic.service.MusicService) DialogInterface(android.content.DialogInterface) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) TextView(android.widget.TextView) ListView(android.widget.ListView) CheckBox(android.widget.CheckBox) LoadingTask(org.moire.ultrasonic.util.LoadingTask) Editable(android.text.Editable) TimeSpanPicker(org.moire.ultrasonic.util.TimeSpanPicker) CompoundButton(android.widget.CompoundButton) OfflineException(org.moire.ultrasonic.service.OfflineException)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Editable (android.text.Editable)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)1 ApiNotSupportedException (org.moire.ultrasonic.api.subsonic.ApiNotSupportedException)1 MusicService (org.moire.ultrasonic.service.MusicService)1 OfflineException (org.moire.ultrasonic.service.OfflineException)1 LoadingTask (org.moire.ultrasonic.util.LoadingTask)1 TimeSpanPicker (org.moire.ultrasonic.util.TimeSpanPicker)1