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);
}
}
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());
}
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);
}
}
}
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);
}
}
}
}
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);
});
}
Aggregations