Search in sources :

Example 1 with ApiNotSupportedException

use of org.moire.ultrasonic.api.subsonic.ApiNotSupportedException 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();
}
Also used : ApiNotSupportedException(org.moire.ultrasonic.api.subsonic.ApiNotSupportedException) MusicService(org.moire.ultrasonic.service.MusicService) DialogInterface(android.content.DialogInterface) LoadingTask(org.moire.ultrasonic.util.LoadingTask) SpannableString(android.text.SpannableString) OfflineException(org.moire.ultrasonic.service.OfflineException)

Example 2 with ApiNotSupportedException

use of org.moire.ultrasonic.api.subsonic.ApiNotSupportedException 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();
}
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) OfflineException(org.moire.ultrasonic.service.OfflineException)

Example 3 with ApiNotSupportedException

use of org.moire.ultrasonic.api.subsonic.ApiNotSupportedException 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)

Example 4 with ApiNotSupportedException

use of org.moire.ultrasonic.api.subsonic.ApiNotSupportedException 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();
}
Also used : ApiNotSupportedException(org.moire.ultrasonic.api.subsonic.ApiNotSupportedException) MusicService(org.moire.ultrasonic.service.MusicService) DialogInterface(android.content.DialogInterface) LoadingTask(org.moire.ultrasonic.util.LoadingTask) SpannableString(android.text.SpannableString) OfflineException(org.moire.ultrasonic.service.OfflineException)

Aggregations

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