Search in sources :

Example 66 with Subscribe

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

the class SubscriptionFragment method loadSubscriptions.

private void loadSubscriptions() {
    if (disposable != null) {
        disposable.dispose();
    }
    emptyView.hide();
    disposable = Observable.fromCallable(() -> {
        NavDrawerData data = DBReader.getNavDrawerData();
        List<NavDrawerData.DrawerItem> items = data.items;
        for (NavDrawerData.DrawerItem item : items) {
            if (item.type == NavDrawerData.DrawerItem.Type.TAG && item.getTitle().equals(displayedFolder)) {
                return ((NavDrawerData.TagDrawerItem) item).children;
            }
        }
        return items;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        if (listItems != null && listItems.size() > result.size()) {
            // We have fewer items. This can result in items being selected that are no longer visible.
            subscriptionAdapter.endSelectMode();
        }
        listItems = result;
        subscriptionAdapter.setItems(result);
        subscriptionAdapter.notifyDataSetChanged();
        emptyView.updateVisibility();
        // Keep hidden to avoid flickering while refreshing
        progressBar.setVisibility(View.GONE);
    }, error -> {
        Log.e(TAG, Log.getStackTraceString(error));
        progressBar.setVisibility(View.GONE);
    });
    if (UserPreferences.getSubscriptionsFilter().isEnabled()) {
        feedsFilteredMsg.setText("{md-info-outline} " + getString(R.string.subscriptions_are_filtered));
        Iconify.addIcons(feedsFilteredMsg);
        feedsFilteredMsg.setVisibility(View.VISIBLE);
    } else {
        feedsFilteredMsg.setVisibility(View.GONE);
    }
}
Also used : RemoveFeedDialog(de.danoeh.antennapod.dialog.RemoveFeedDialog) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) FeedListUpdateEvent(de.danoeh.antennapod.event.FeedListUpdateEvent) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) SubscriptionsRecyclerAdapter(de.danoeh.antennapod.adapter.SubscriptionsRecyclerAdapter) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) RenameItemDialog(de.danoeh.antennapod.dialog.RenameItemDialog) Log(android.util.Log) EmptyViewHandler(de.danoeh.antennapod.view.EmptyViewHandler) ThreadMode(org.greenrobot.eventbus.ThreadMode) FeedMultiSelectActionHandler(de.danoeh.antennapod.fragment.actions.FeedMultiSelectActionHandler) ViewGroup(android.view.ViewGroup) StringRes(androidx.annotation.StringRes) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) DownloadEvent(de.danoeh.antennapod.core.event.DownloadEvent) Toolbar(androidx.appcompat.widget.Toolbar) UnreadItemsUpdateEvent(de.danoeh.antennapod.event.UnreadItemsUpdateEvent) Context(android.content.Context) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) AutoUpdateManager(de.danoeh.antennapod.core.util.download.AutoUpdateManager) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog) Callable(java.util.concurrent.Callable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SubscriptionsFilterDialog(de.danoeh.antennapod.dialog.SubscriptionsFilterDialog) SuppressLint(android.annotation.SuppressLint) EventBus(org.greenrobot.eventbus.EventBus) Observable(io.reactivex.Observable) TagSettingsDialog(de.danoeh.antennapod.dialog.TagSettingsDialog) Feed(de.danoeh.antennapod.model.feed.Feed) DialogInterface(android.content.DialogInterface) NavDrawerData(de.danoeh.antennapod.core.storage.NavDrawerData) FeedSortDialog(de.danoeh.antennapod.dialog.FeedSortDialog) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) R(de.danoeh.antennapod.R) MenuItemUtils(de.danoeh.antennapod.core.menuhandler.MenuItemUtils) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Iconify(com.joanzapata.iconify.Iconify) DBReader(de.danoeh.antennapod.core.storage.DBReader) Collections(java.util.Collections) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) NavDrawerData(de.danoeh.antennapod.core.storage.NavDrawerData)

Example 67 with Subscribe

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

the class FeedItemlistFragment method onEventMainThread.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FeedItemEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    if (feed == null || feed.getItems() == 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(feed.getItems(), item.getId());
        if (pos >= 0) {
            feed.getItems().remove(pos);
            feed.getItems().add(pos, item);
            adapter.notifyItemChangedCompat(pos);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 68 with Subscribe

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

the class ItemFragment 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;
    downloaderList = update.downloaders;
    if (item == null || item.getMedia() == null) {
        return;
    }
    long mediaId = item.getMedia().getId();
    if (ArrayUtils.contains(update.mediaIds, mediaId)) {
        if (itemsLoaded && getActivity() != null) {
            updateButtons();
        }
    }
}
Also used : DownloaderUpdate(de.danoeh.antennapod.core.event.DownloaderUpdate) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 69 with Subscribe

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

the class SearchFragment 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(results, mediaId);
            if (pos >= 0) {
                adapter.notifyItemChangedCompat(pos);
            }
        }
    }
}
Also used : DownloaderUpdate(de.danoeh.antennapod.core.event.DownloaderUpdate) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 70 with Subscribe

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

the class QueueFragment method onEventMainThread.

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

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