Search in sources :

Example 61 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project BookReader by JustWayward.

the class DownloadBookService method addToDownloadQueue.

@Subscribe(threadMode = ThreadMode.MAIN)
public synchronized void addToDownloadQueue(DownloadQueue queue) {
    if (!TextUtils.isEmpty(queue.bookId)) {
        boolean exists = false;
        // 判断当前书籍缓存任务是否存在
        for (int i = 0; i < downloadQueues.size(); i++) {
            if (downloadQueues.get(i).bookId.equals(queue.bookId)) {
                LogUtils.e("addToDownloadQueue:exists");
                exists = true;
                break;
            }
        }
        if (exists) {
            post(new DownloadMessage(queue.bookId, "当前缓存任务已存在", false));
            return;
        }
        // 添加到下载队列
        downloadQueues.add(queue);
        LogUtils.e("addToDownloadQueue:" + queue.bookId);
        post(new DownloadMessage(queue.bookId, "成功加入缓存队列", false));
    }
    // 从队列顺序取出第一条下载
    if (downloadQueues.size() > 0 && !isBusy) {
        isBusy = true;
        DownloadQueue downloadQueue = downloadQueues.get(0);
        downloadBook(downloadQueue);
    }
}
Also used : DownloadMessage(com.justwayward.reader.bean.support.DownloadMessage) DownloadQueue(com.justwayward.reader.bean.support.DownloadQueue) SyncOnSubscribe(rx.observables.SyncOnSubscribe) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 62 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project chefly_android by chef-ly.

the class GetCookingActivity method onEvent.

// This method will be called when the VoiceRec class sends a nextInstruction event
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(VoiceInstructionEvent event) {
    String instruction = event.getInstruction();
    switch(instruction) {
        case "next":
            updateStepText();
            pager.setCurrentItem(step + 1, true);
            break;
        case "back":
            if (ingredientsShowing) {
                ingredientsPopup.dismiss();
                // directionsPopup.dismiss();
                ingredientsShowing = false;
            } else if (directionsShowing) {
                directionsPopup.dismiss();
                directionsShowing = false;
            } else {
                updateStepText();
                pager.setCurrentItem(step - 1, true);
            }
            break;
        case "repeat":
            read(directions.get(step));
            break;
        case "ingredients":
            FragmentManager fm = getSupportFragmentManager();
            ingredientsPopup.show(fm, "Ingredients");
            ingredientsShowing = true;
            break;
        case "directions":
            fm = getSupportFragmentManager();
            directionsPopup.show(fm, "Directions");
            directionsShowing = true;
            break;
        case "question":
            // TODO - make chefly icon at bottom of screen blow to show hes listening
            break;
        case "listen":
            // btnSpeak.setImageDrawable(getResources().getDrawable(R.drawable.heartselected, getApplicationContext().getTheme()));
            // ImageView imgFp = (ImageView) findViewById(R.id.btnSpeak);
            // imgFp.setImageResource(0);
            // imgFp.setImageResource(R.drawable.heartselected);
            ImageView image = (ImageView) findViewById(R.id.btnSpeak);
            Glide.with(getApplicationContext()).load(R.drawable.heartselected).asGif().crossFade().into(image);
            // ((ImageView) v.findViewById(R.id.ImageView1)).setImageResource(0);
            break;
        default:
            Toast.makeText(this, "Can you please say that again?", Toast.LENGTH_LONG).show();
    }
    Log.e("DEBUG", "Received VoiceInstructionEvent " + event.getInstruction());
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) ImageView(android.widget.ImageView) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 63 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.

the class PlaybackHistoryFragment method onEventMainThread.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedItemEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    if (playbackHistory == null) {
        return;
    } else if (adapter == null) {
        loadItems();
        return;
    }
    for (int i = 0, size = event.items.size(); i < size; i++) {
        FeedItem item = event.items.get(i);
        int pos = FeedItemUtil.indexOfItemWithId(playbackHistory, item.getId());
        if (pos >= 0) {
            playbackHistory.remove(pos);
            playbackHistory.add(pos, item);
            adapter.notifyItemChangedCompat(pos);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 64 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.

the class PlaybackHistoryFragment method onEventMainThread.

@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(DownloadEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    DownloaderUpdate update = event.update;
    if (adapter != null && update.mediaIds.length > 0) {
        for (long mediaId : update.mediaIds) {
            int pos = FeedItemUtil.indexOfItemWithMediaId(playbackHistory, mediaId);
            if (pos >= 0) {
                adapter.notifyItemChangedCompat(pos);
            }
        }
    }
}
Also used : DownloaderUpdate(de.danoeh.antennapod.core.event.DownloaderUpdate) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 65 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project AntennaPod by AntennaPod.

the class QuickFeedDiscoveryFragment method loadToplist.

private void loadToplist() {
    progressBar.setVisibility(View.VISIBLE);
    discoverGridLayout.setVisibility(View.INVISIBLE);
    errorView.setVisibility(View.GONE);
    errorRetry.setVisibility(View.INVISIBLE);
    poweredByTextView.setVisibility(View.VISIBLE);
    ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
    SharedPreferences prefs = getActivity().getSharedPreferences(ItunesTopListLoader.PREFS, MODE_PRIVATE);
    String countryCode = prefs.getString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, Locale.getDefault().getCountry());
    if (countryCode.equals(ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE)) {
        errorTextView.setText(String.format(getResources().getString(R.string.discover_is_hidden), getResources().getString(R.string.discover_hide)));
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.INVISIBLE);
        poweredByTextView.setVisibility(View.INVISIBLE);
        return;
    }
    disposable = loader.loadToplist(countryCode, NUM_SUGGESTIONS).subscribe(podcasts -> {
        errorView.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.VISIBLE);
        if (podcasts.size() == 0) {
            errorTextView.setText(getResources().getText(R.string.search_status_no_results));
            errorView.setVisibility(View.VISIBLE);
            discoverGridLayout.setVisibility(View.INVISIBLE);
        } else {
            adapter.updateData(podcasts);
        }
    }, error -> {
        Log.e(TAG, Log.getStackTraceString(error));
        errorTextView.setText(error.getLocalizedMessage());
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.VISIBLE);
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) FeedDiscoverAdapter(de.danoeh.antennapod.adapter.FeedDiscoverAdapter) ArrayList(java.util.ArrayList) Locale(java.util.Locale) EventBus(org.greenrobot.eventbus.EventBus) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Log(android.util.Log) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) DiscoveryDefaultUpdateEvent(de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) SharedPreferences(android.content.SharedPreferences) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader)

Aggregations

Subscribe (org.greenrobot.eventbus.Subscribe)164 Intent (android.content.Intent)20 Bundle (android.os.Bundle)11 EventBus (org.greenrobot.eventbus.EventBus)10 ThreadMode (org.greenrobot.eventbus.ThreadMode)10 View (android.view.View)9 Poi (io.jawg.osmcontributor.model.entities.Poi)9 PoiType (io.jawg.osmcontributor.model.entities.PoiType)9 ArrayList (java.util.ArrayList)9 Context (android.content.Context)8 Handler (android.os.Handler)8 ViewGroup (android.view.ViewGroup)8 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)8 SuppressLint (android.annotation.SuppressLint)6 LayoutInflater (android.view.LayoutInflater)6 MenuItem (android.view.MenuItem)6 DownloaderUpdate (de.danoeh.antennapod.core.event.DownloaderUpdate)6 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)6 Disposable (io.reactivex.disposables.Disposable)6 Schedulers (io.reactivex.schedulers.Schedulers)6