bugfix - rxjava2 null return - wrap nullable return with Optional
This commit is contained in:
parent
20f1445c06
commit
e16f44ad5d
|
@ -58,9 +58,11 @@ import de.danoeh.antennapod.core.storage.DBReader;
|
|||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.syndication.handler.FeedHandler;
|
||||
import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult;
|
||||
import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException;
|
||||
import de.danoeh.antennapod.core.util.DownloadError;
|
||||
import de.danoeh.antennapod.core.util.FileNameGenerator;
|
||||
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.syndication.FeedDiscoverer;
|
||||
|
@ -315,16 +317,33 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
}
|
||||
Log.d(TAG, "Parsing feed");
|
||||
|
||||
parser = Observable.fromCallable(() -> {
|
||||
// TODO: [PENDING 2954] return Optional<FeedHandlerResult>
|
||||
parser = Observable.fromCallable(this::doParseFeed)
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(optionalResult -> {
|
||||
if(optionalResult.isPresent()) {
|
||||
FeedHandlerResult result = optionalResult.get();
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Optional<FeedHandlerResult> doParseFeed() throws Exception {
|
||||
FeedHandler handler = new FeedHandler();
|
||||
try {
|
||||
return handler.parseFeed(feed);
|
||||
return Optional.of(handler.parseFeed(feed));
|
||||
} catch (UnsupportedFeedtypeException e) {
|
||||
Log.d(TAG, "Unsupported feed type detected");
|
||||
if ("html".equalsIgnoreCase(e.getRootElement())) {
|
||||
showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url());
|
||||
return null;
|
||||
return Optional.empty();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
@ -335,20 +354,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
|||
boolean rc = new File(feed.getFile_url()).delete();
|
||||
Log.d(TAG, "Deleted feed source file. Result: " + rc);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> { // TODO: [PENDING 2954] wrap underlying Nullable return with Optional<>
|
||||
if(result != null) {
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue