Search in sources :

Example 6 with TabActivityBackgroundTask

use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.

the class SearchActivity method search.

private void search(final String query, final boolean autoplay) {
    final int maxArtists = Util.getMaxArtists(this);
    final int maxAlbums = Util.getMaxAlbums(this);
    final int maxSongs = Util.getMaxSongs(this);
    BackgroundTask<SearchResult> task = new TabActivityBackgroundTask<SearchResult>(this, true) {

        @Override
        protected SearchResult doInBackground() throws Throwable {
            SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs);
            MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this);
            licenseValid = service.isLicenseValid(SearchActivity.this, this);
            return service.search(criteria, SearchActivity.this, this);
        }

        @Override
        protected void done(SearchResult result) {
            searchResult = result;
            populateList();
            if (autoplay) {
                autoplay();
            }
        }
    };
    task.execute();
}
Also used : TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) SearchResult(org.moire.ultrasonic.domain.SearchResult) SearchCriteria(org.moire.ultrasonic.domain.SearchCriteria)

Example 7 with TabActivityBackgroundTask

use of org.moire.ultrasonic.util.TabActivityBackgroundTask 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 8 with TabActivityBackgroundTask

use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.

the class SubsonicTabActivity method share.

public void share() {
    BackgroundTask<Share> task = new TabActivityBackgroundTask<Share>(this, true) {

        @Override
        protected Share doInBackground() throws Throwable {
            List<String> ids = new ArrayList<String>();
            if (shareDetails.Entries.isEmpty()) {
                ids.add(getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID));
            } else {
                for (Entry entry : shareDetails.Entries) {
                    ids.add(entry.getId());
                }
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            long timeInMillis = 0;
            if (shareDetails.Expiration != 0) {
                timeInMillis = shareDetails.Expiration;
            }
            List<Share> shares = musicService.createShare(ids, shareDetails.Description, timeInMillis, SubsonicTabActivity.this, this);
            return shares.get(0);
        }

        @Override
        protected void done(Share result) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, String.format("%s\n\n%s", Util.getShareGreeting(SubsonicTabActivity.this), result.getUrl()));
            startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_via)));
        }
    };
    task.execute();
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Share(org.moire.ultrasonic.domain.Share)

Example 9 with TabActivityBackgroundTask

use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.

the class ChatActivity method sendMessage.

private void sendMessage() {
    if (messageEditText != null) {
        final String message;
        Editable text = messageEditText.getText();
        if (text == null) {
            return;
        }
        message = text.toString();
        if (!Util.isNullOrWhiteSpace(message)) {
            messageEditText.setText("");
            BackgroundTask<Void> task = new TabActivityBackgroundTask<Void>(ChatActivity.this, false) {

                @Override
                protected Void doInBackground() throws Throwable {
                    MusicService musicService = MusicServiceFactory.getMusicService(ChatActivity.this);
                    musicService.addChatMessage(message, ChatActivity.this, this);
                    return null;
                }

                @Override
                protected void done(Void result) {
                    load();
                }
            };
            task.execute();
        }
    }
}
Also used : TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) Editable(android.text.Editable)

Example 10 with TabActivityBackgroundTask

use of org.moire.ultrasonic.util.TabActivityBackgroundTask in project ultrasonic by ultrasonic.

the class ChatActivity method load.

private synchronized void load() {
    BackgroundTask<List<ChatMessage>> task = new TabActivityBackgroundTask<List<ChatMessage>>(this, false) {

        @Override
        protected List<ChatMessage> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(ChatActivity.this);
            return musicService.getChatMessages(lastChatMessageTime, ChatActivity.this, this);
        }

        @Override
        protected void done(List<ChatMessage> result) {
            if (result != null && !result.isEmpty()) {
                // Reset lastChatMessageTime if we have a newer message
                for (ChatMessage message : result) {
                    if (message.getTime() > lastChatMessageTime) {
                        lastChatMessageTime = message.getTime();
                    }
                }
                // Reverse results to show them on the bottom
                Collections.reverse(result);
                messageList.addAll(result);
                ListAdapter chatAdapter = new ChatAdapter(ChatActivity.this, messageList);
                chatListView.setAdapter(chatAdapter);
            }
        }
    };
    task.execute();
}
Also used : TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) ChatMessage(org.moire.ultrasonic.domain.ChatMessage) ArrayList(java.util.ArrayList) List(java.util.List) ChatAdapter(org.moire.ultrasonic.view.ChatAdapter) ListAdapter(android.widget.ListAdapter)

Aggregations

MusicService (org.moire.ultrasonic.service.MusicService)10 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)10 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Share (org.moire.ultrasonic.domain.Share)2 Intent (android.content.Intent)1 Editable (android.text.Editable)1 ListAdapter (android.widget.ListAdapter)1 TextView (android.widget.TextView)1 Artist (org.moire.ultrasonic.domain.Artist)1 ChatMessage (org.moire.ultrasonic.domain.ChatMessage)1 Genre (org.moire.ultrasonic.domain.Genre)1 Indexes (org.moire.ultrasonic.domain.Indexes)1 Lyrics (org.moire.ultrasonic.domain.Lyrics)1 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)1 MusicFolder (org.moire.ultrasonic.domain.MusicFolder)1 Playlist (org.moire.ultrasonic.domain.Playlist)1 PodcastsChannel (org.moire.ultrasonic.domain.PodcastsChannel)1 SearchCriteria (org.moire.ultrasonic.domain.SearchCriteria)1 SearchResult (org.moire.ultrasonic.domain.SearchResult)1