diff options
author | ByteHamster <info@bytehamster.com> | 2021-03-01 20:47:05 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-03-01 20:47:05 +0100 |
commit | e59767890eb81af48b7860400f0bd0b0bee95638 (patch) | |
tree | a238c33ef5541147e43e5cb63699833663356c00 /app/src | |
parent | d444e8d23e1062e073925c537f1da9ce63e15c90 (diff) | |
download | AntennaPod-e59767890eb81af48b7860400f0bd0b0bee95638.zip |
Removed our re-implementation of 'Optimal' and used the RxJava equivalent instead
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java | 44 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java | 23 |
2 files changed, 44 insertions, 23 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index bd2c7f9a6..045cc5f21 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -16,6 +16,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.UiThread; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -51,7 +52,6 @@ import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeExceptio import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.FileNameGenerator; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.Optional; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.URLChecker; import de.danoeh.antennapod.core.util.playback.RemoteMedia; @@ -60,9 +60,11 @@ import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.databinding.OnlinefeedviewActivityBinding; import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.danoeh.antennapod.discovery.PodcastSearcherRegistry; +import io.reactivex.Maybe; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; +import io.reactivex.observers.DisposableMaybeObserver; import io.reactivex.schedulers.Schedulers; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; @@ -321,34 +323,48 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } Log.d(TAG, "Parsing feed"); - parser = Observable.fromCallable(this::doParseFeed) + parser = Maybe.fromCallable(this::doParseFeed) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(optionalResult -> { - if(optionalResult.isPresent()) { - FeedHandlerResult result = optionalResult.get(); + .subscribeWith(new DisposableMaybeObserver<FeedHandlerResult>() { + @Override + public void onSuccess(@NonNull FeedHandlerResult result) { beforeShowFeedInformation(result.feed); showFeedInformation(result.feed, result.alternateFeedUrls); } - }, error -> { - String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( - OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; - showErrorDialog(errorMsg); - Log.d(TAG, "Feed parser exception: " + Log.getStackTraceString(error)); + + @Override + public void onComplete() { + // Ignore null result: We showed the discovery dialog. + } + + @Override + public void onError(@NonNull Throwable error) { + String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( + OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; + showErrorDialog(errorMsg); + Log.d(TAG, "Feed parser exception: " + Log.getStackTraceString(error)); + } }); } - @NonNull - private Optional<FeedHandlerResult> doParseFeed() throws Exception { + /** + * Try to parse the feed. + * @return The FeedHandlerResult if successful. + * Null if unsuccessful but we started another attempt. + * @throws Exception If unsuccessful but we do not know a resolution. + */ + @Nullable + private FeedHandlerResult doParseFeed() throws Exception { FeedHandler handler = new FeedHandler(); try { - return Optional.of(handler.parseFeed(feed)); + return handler.parseFeed(feed); } catch (UnsupportedFeedtypeException e) { Log.d(TAG, "Unsupported feed type detected"); if ("html".equalsIgnoreCase(e.getRootElement())) { boolean dialogShown = showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); if (dialogShown) { - return Optional.empty(); + return null; // Should not display an error message } else { Log.d(TAG, "Supplied feed is an HTML web page that has no references to any feed"); throw e; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index c86fdc070..6be532887 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -56,7 +56,6 @@ import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemPermutors; import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.Optional; import de.danoeh.antennapod.ui.common.ThemeUtils; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; @@ -549,15 +548,21 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem disposable = Observable.fromCallable(this::loadData) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(result -> { - feed = result.orElse(null); - refreshHeaderView(); - displayList(); - }, error -> Log.e(TAG, Log.getStackTraceString(error))); + .subscribe( + result -> { + feed = result; + refreshHeaderView(); + displayList(); + }, error -> { + feed = null; + refreshHeaderView(); + displayList(); + Log.e(TAG, Log.getStackTraceString(error)); + }); } - @NonNull - private Optional<Feed> loadData() { + @Nullable + private Feed loadData() { Feed feed = DBReader.getFeed(feedID); if (feed != null && feed.getItemFilter() != null) { DBReader.loadAdditionalFeedItemListData(feed.getItems()); @@ -569,7 +574,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem FeedItemPermutors.getPermutor(feed.getSortOrder()).reorder(feedItems); feed.setItems(feedItems); } - return Optional.ofNullable(feed); + return feed; } private static class FeedItemListAdapter extends EpisodeItemListAdapter { |