Search in sources :

Example 21 with MusicService

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

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

the class ServerSettingsFragment method testConnection.

private void testConnection() {
    ModalBackgroundTask<Boolean> task = new ModalBackgroundTask<Boolean>(getActivity(), false) {

        private int previousInstance;

        @Override
        protected Boolean doInBackground() throws Throwable {
            updateProgress(R.string.settings_testing_connection);
            final Context context = getActivity();
            previousInstance = Util.getActiveServer(context);
            Util.setActiveServer(context, serverId);
            try {
                MusicService musicService = MusicServiceFactory.getMusicService(context);
                musicService.ping(context, this);
                return musicService.isLicenseValid(context, null);
            } finally {
                Util.setActiveServer(context, previousInstance);
            }
        }

        @Override
        protected void done(Boolean licenseValid) {
            if (licenseValid) {
                Util.toast(getActivity(), R.string.settings_testing_ok);
            } else {
                Util.toast(getActivity(), R.string.settings_testing_unlicensed);
            }
        }

        @Override
        protected void cancel() {
            super.cancel();
            Util.setActiveServer(getActivity(), previousInstance);
        }

        @Override
        protected void error(Throwable error) {
            Log.w(LOG_TAG, error.toString(), error);
            new ErrorDialog(getActivity(), String.format("%s %s", getResources().getString(R.string.settings_connection_failure), getErrorMessage(error)), false);
        }
    };
    task.execute();
}
Also used : Context(android.content.Context) MusicService(org.moire.ultrasonic.service.MusicService) ErrorDialog(org.moire.ultrasonic.util.ErrorDialog) ModalBackgroundTask(org.moire.ultrasonic.util.ModalBackgroundTask)

Example 23 with MusicService

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

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