Return Optional feed when loading feed items

RxJava 2.x no longer accepts `null` values and will yield a
`NullPointerException` immediately or as a signal to downstream [1].

This returns an Optional<Feed> instead to avoid errors.

[1]: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#nulls
This commit is contained in:
Anderson Mesquita 2019-04-27 18:13:45 -04:00
parent 34d33f796e
commit a2cd8cca73
1 changed files with 8 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.LightingColorFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
@ -61,6 +61,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.Optional;
import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil;
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
@ -618,7 +619,7 @@ public class ItemlistFragment extends ListFragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
feed = result;
feed = result.orElse(null);
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
@ -626,18 +627,15 @@ public class ItemlistFragment extends ListFragment {
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@Nullable
private Feed loadData() {
@NonNull
private Optional<Feed> loadData() {
Feed feed = DBReader.getFeed(feedID);
if (feed == null) {
return null;
}
if (feed != null && feed.getItemFilter() != null) {
DBReader.loadAdditionalFeedItemListData(feed.getItems());
if (feed.getItemFilter() != null) {
FeedItemFilter filter = feed.getItemFilter();
feed.setItems(filter.filter(feed.getItems()));
}
return feed;
return Optional.ofNullable(feed);
}
}