Search in sources :

Example 16 with MusicService

use of org.moire.ultrasonic.service.MusicService in project ultrasonic by ultrasonic.

the class SelectArtistActivity method load.

private void load() {
    BackgroundTask<Indexes> task = new TabActivityBackgroundTask<Indexes>(this, true) {

        @Override
        protected Indexes doInBackground() throws Throwable {
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this);
            boolean isOffline = Util.isOffline(SelectArtistActivity.this);
            boolean useId3Tags = Util.getShouldUseId3Tags(SelectArtistActivity.this);
            if (!isOffline && !useId3Tags) {
                musicFolders = musicService.getMusicFolders(refresh, SelectArtistActivity.this, this);
            }
            String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
            return !isOffline && useId3Tags ? musicService.getArtists(refresh, SelectArtistActivity.this, this) : musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this);
        }

        @Override
        protected void done(Indexes result) {
            if (result != null) {
                List<Artist> artists = new ArrayList<Artist>(result.getShortcuts().size() + result.getArtists().size());
                artists.addAll(result.getShortcuts());
                artists.addAll(result.getArtists());
                artistListView.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists));
            }
            // Display selected music folder
            if (musicFolders != null) {
                String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this);
                if (musicFolderId == null) {
                    if (folderName != null) {
                        folderName.setText(R.string.select_artist_all_folders);
                    }
                } else {
                    for (MusicFolder musicFolder : musicFolders) {
                        if (musicFolder.getId().equals(musicFolderId)) {
                            if (folderName != null) {
                                folderName.setText(musicFolder.getName());
                            }
                            break;
                        }
                    }
                }
            }
        }
    };
    task.execute();
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) ArtistAdapter(org.moire.ultrasonic.view.ArtistAdapter) ArrayList(java.util.ArrayList) Indexes(org.moire.ultrasonic.domain.Indexes) MusicFolder(org.moire.ultrasonic.domain.MusicFolder)

Example 17 with MusicService

use of org.moire.ultrasonic.service.MusicService 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 18 with MusicService

use of org.moire.ultrasonic.service.MusicService 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 19 with MusicService

use of org.moire.ultrasonic.service.MusicService 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 20 with MusicService

use of org.moire.ultrasonic.service.MusicService 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

MusicService (org.moire.ultrasonic.service.MusicService)24 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)8 TextView (android.widget.TextView)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 SpannableString (android.text.SpannableString)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)4 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)4 LinkedList (java.util.LinkedList)4 ApiNotSupportedException (org.moire.ultrasonic.api.subsonic.ApiNotSupportedException)4 Share (org.moire.ultrasonic.domain.Share)4 OfflineException (org.moire.ultrasonic.service.OfflineException)4 LoadingTask (org.moire.ultrasonic.util.LoadingTask)4 Editable (android.text.Editable)3 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)3