Merge pull request #2974 from orionlee/bugfix_rxjava2_null_returns_2966

Fix rxjava2 null returns
This commit is contained in:
H. Lehmann 2019-04-07 11:35:13 +02:00 committed by GitHub
commit 3fdf6af1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 94 additions and 65 deletions

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
@ -27,7 +28,6 @@ import android.widget.Spinner;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import org.apache.commons.lang3.StringUtils;
@ -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;
@ -288,12 +290,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
error -> Log.e(TAG, Log.getStackTraceString(error)));
}
private void checkDownloadResult(DownloadStatus status) {
if (status == null) {
Log.wtf(TAG, "DownloadStatus returned by Downloader was null");
finish();
return;
}
private void checkDownloadResult(@NonNull DownloadStatus status) {
if (status.isCancelled()) {
return;
}
@ -320,30 +317,12 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
}
Log.d(TAG, "Parsing feed");
parser = Observable.fromCallable(() -> {
FeedHandler handler = new FeedHandler();
try {
return 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;
} else {
throw e;
}
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
throw e;
} finally {
boolean rc = new File(feed.getFile_url()).delete();
Log.d(TAG, "Deleted feed source file. Result: " + rc);
}
})
parser = Observable.fromCallable(this::doParseFeed)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
if(result != null) {
.subscribe(optionalResult -> {
if(optionalResult.isPresent()) {
FeedHandlerResult result = optionalResult.get();
beforeShowFeedInformation(result.feed);
showFeedInformation(result.feed, result.alternateFeedUrls);
}
@ -355,6 +334,28 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
});
}
@NonNull
private Optional<FeedHandlerResult> doParseFeed() throws Exception {
FeedHandler handler = new FeedHandler();
try {
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 Optional.empty();
} else {
throw e;
}
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
throw e;
} finally {
boolean rc = new File(feed.getFile_url()).delete();
Log.d(TAG, "Deleted feed source file. Result: " + rc);
}
}
/**
* Called after the feed has been downloaded and parsed and before showFeedInformation is called.
* This method is executed on a background thread

View File

@ -23,15 +23,15 @@ public class ExportWorker {
private static final String TAG = "ExportWorker";
private static final String DEFAULT_OUTPUT_NAME = "antennapod-feeds";
private final ExportWriter exportWriter;
private final File output;
private final @NonNull ExportWriter exportWriter;
private final @NonNull File output;
public ExportWorker(ExportWriter exportWriter) {
public ExportWorker(@NonNull ExportWriter exportWriter) {
this(exportWriter, new File(UserPreferences.getDataFolder(EXPORT_DIR),
DEFAULT_OUTPUT_NAME + "." + exportWriter.fileExtension()));
}
private ExportWorker(ExportWriter exportWriter, @NonNull File output) {
private ExportWorker(@NonNull ExportWriter exportWriter, @NonNull File output) {
this.exportWriter = exportWriter;
this.output = output;
}

View File

@ -5,6 +5,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
@ -498,16 +499,15 @@ public class AllEpisodesFragment extends Fragment {
.subscribe(data -> {
recyclerView.setVisibility(View.VISIBLE);
progLoading.setVisibility(View.GONE);
if (data != null) {
episodes = data;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
episodes = data;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@NonNull
List<FeedItem> loadData() {
return DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT);
}

View File

@ -11,6 +11,7 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.ContextMenu;
@ -313,6 +314,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@NonNull
private String loadData() {
Timeline timeline = new Timeline(getActivity(), shownotesProvider);
return timeline.processShownotes(highlightTimecodes);

View File

@ -588,6 +588,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@Nullable
private FeedItem loadInBackground() {
FeedItem feedItem = DBReader.getFeedItem(feedItems[feedItemPos]);
if (feedItem != null) {

View File

@ -6,6 +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.v4.app.ListFragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
@ -25,7 +26,6 @@ import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.widget.IconTextView;
@ -618,16 +618,15 @@ public class ItemlistFragment extends ListFragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
if (result != null) {
feed = result;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
feed = result;
itemsLoaded = true;
if (viewsCreated) {
onFragmentLoaded();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@Nullable
private Feed loadData() {
Feed feed = DBReader.getFeed(feedID);
DBReader.loadAdditionalFeedItemListData(feed.getItems());

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.fragment;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.support.v4.view.MenuItemCompat;
import android.util.Log;
@ -293,6 +294,7 @@ public class PlaybackHistoryFragment extends ListFragment {
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@NonNull
private List<FeedItem> loadData() {
List<FeedItem> history = DBReader.getPlaybackHistory();
DBReader.loadAdditionalFeedItemListData(history);

View File

@ -639,13 +639,11 @@ public class QueueFragment extends Fragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(items -> {
if(items != null) {
progLoading.setVisibility(View.GONE);
queue = items;
onFragmentLoaded(restoreScrollPosition);
if(recyclerAdapter != null) {
recyclerAdapter.notifyDataSetChanged();
}
progLoading.setVisibility(View.GONE);
queue = items;
onFragmentLoaded(restoreScrollPosition);
if(recyclerAdapter != null) {
recyclerAdapter.notifyDataSetChanged();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
@ -215,16 +216,15 @@ public class SearchFragment extends ListFragment {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
if (result != null) {
itemsLoaded = true;
searchResults = result;
if (viewCreated) {
onFragmentLoaded();
}
itemsLoaded = true;
searchResults = result;
if (viewCreated) {
onFragmentLoaded();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@NonNull
private List<SearchResult> performSearch() {
Bundle args = getArguments();
String query = args.getString(ARG_QUERY);

View File

@ -455,6 +455,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog {
return context.getTheme().resolveAttribute(attr, value, true) ? value.resourceId : 0;
}
@NonNull
private Pair<Bitmap, Integer> fetchArt(@NonNull MediaDescriptionCompat description) {
Bitmap iconBitmap = description.getIconBitmap();
Uri iconUri = description.getIconUri();

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.download;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.support.annotation.NonNull;
import java.util.concurrent.Callable;
@ -18,10 +19,12 @@ public abstract class Downloader implements Callable<Downloader> {
volatile boolean cancelled;
@NonNull
final DownloadRequest request;
@NonNull
final DownloadStatus result;
Downloader(DownloadRequest request) {
Downloader(@NonNull DownloadRequest request) {
super();
this.request = request;
this.request.setStatusMsg(R.string.download_pending);
@ -54,10 +57,12 @@ public abstract class Downloader implements Callable<Downloader> {
return this;
}
@NonNull
public DownloadRequest getDownloadRequest() {
return request;
}
@NonNull
public DownloadStatus getResult() {
return result;
}

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.service.download;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
@ -38,7 +39,7 @@ public class HttpDownloader extends Downloader {
private static final int BUFFER_SIZE = 8 * 1024;
public HttpDownloader(DownloadRequest request) {
public HttpDownloader(@NonNull DownloadRequest request) {
super(request);
}

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.core.storage;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
@ -58,6 +59,7 @@ public final class DBReader {
* of the returned list does NOT have its list of FeedItems yet. The FeedItem-list
* can be loaded separately with {@link #getFeedItemList(Feed)}.
*/
@NonNull
public static List<Feed> getFeedList() {
Log.d(TAG, "Extracting Feedlist");
@ -70,6 +72,7 @@ public final class DBReader {
}
}
@NonNull
private static List<Feed> getFeedList(PodDBAdapter adapter) {
Cursor cursor = null;
try {
@ -199,6 +202,7 @@ public final class DBReader {
}
}
@NonNull
private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
List<FeedItem> result = new ArrayList<>(cursor.getCount());
@ -251,6 +255,7 @@ public final class DBReader {
return feed;
}
@NonNull
static List<FeedItem> getQueue(PodDBAdapter adapter) {
Log.d(TAG, "getQueue()");
Cursor cursor = null;
@ -307,6 +312,7 @@ public final class DBReader {
* @return A list of FeedItems sorted by the same order as the queue. The caller can wrap the returned
* list in a {@link de.danoeh.antennapod.core.util.QueueAccess} object for easier access to the queue's properties.
*/
@NonNull
public static List<FeedItem> getQueue() {
Log.d(TAG, "getQueue() called");
@ -324,6 +330,7 @@ public final class DBReader {
*
* @return A list of FeedItems whose episdoe has been downloaded.
*/
@NonNull
public static List<FeedItem> getDownloadedItems() {
Log.d(TAG, "getDownloadedItems() called");
@ -414,6 +421,7 @@ public final class DBReader {
*
* @param limit The maximum number of episodes that should be loaded.
*/
@NonNull
public static List<FeedItem> getRecentlyPublishedEpisodes(int limit) {
Log.d(TAG, "getRecentlyPublishedEpisodes() called with: " + "limit = [" + limit + "]");
@ -440,6 +448,7 @@ public final class DBReader {
* @return The playback history. The FeedItems are sorted by their media's playbackCompletionDate in descending order.
* The size of the returned list is limited by {@link #PLAYBACK_HISTORY_SIZE}.
*/
@NonNull
public static List<FeedItem> getPlaybackHistory() {
Log.d(TAG, "getPlaybackHistory() called");
@ -595,6 +604,7 @@ public final class DBReader {
}
}
@Nullable
private static FeedItem getFeedItem(final long itemId, PodDBAdapter adapter) {
Log.d(TAG, "Loading feeditem with id " + itemId);
@ -628,6 +638,7 @@ public final class DBReader {
* @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
* as well as chapter marks of the FeedItem will also be loaded from the database.
*/
@Nullable
public static FeedItem getFeedItem(final long itemId) {
Log.d(TAG, "getFeedItem() called with: " + "itemId = [" + itemId + "]");
@ -640,6 +651,7 @@ public final class DBReader {
}
}
@Nullable
private static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
Log.d(TAG, "Loading feeditem with podcast url " + podcastUrl + " and episode url " + episodeUrl);
Cursor cursor = null;
@ -859,6 +871,7 @@ public final class DBReader {
* countAll calculation time
* @return The StatisticsInfo object
*/
@NonNull
public static StatisticsData getStatistics(boolean sortByCountAll) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
@ -1025,6 +1038,7 @@ public final class DBReader {
* the list of subscriptions, the number of items in the queue and the number of unread
* items.
*/
@NonNull
public static NavDrawerData getNavDrawerData() {
Log.d(TAG, "getNavDrawerData() called with: " + "");
PodDBAdapter adapter = PodDBAdapter.getInstance();

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.Log;
import org.shredzone.flattr4j.model.Flattr;
@ -48,7 +49,6 @@ import de.danoeh.antennapod.core.util.flattr.FlattrStatus;
import de.danoeh.antennapod.core.util.flattr.FlattrThing;
import de.danoeh.antennapod.core.util.flattr.SimpleFlattrThing;
import de.greenrobot.event.EventBus;
import io.reactivex.annotations.NonNull;
/**
* Provides methods for writing data to AntennaPod's database.
@ -633,11 +633,13 @@ public class DBWriter {
* FeedItem.NEW, FeedItem.UNPLAYED
* @param resetMediaPosition true if this method should also reset the position of the FeedItem's FeedMedia object.
*/
@NonNull
public static Future<?> markItemPlayed(FeedItem item, int played, boolean resetMediaPosition) {
long mediaId = (item.hasMedia()) ? item.getMedia().getId() : 0;
return markItemPlayed(item.getId(), played, mediaId, resetMediaPosition);
}
@NonNull
private static Future<?> markItemPlayed(final long itemId,
final int played,
final long mediaId,

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.core.storage;
import android.content.Context;
import android.support.annotation.NonNull;
import java.util.ArrayList;
import java.util.Collections;
@ -35,6 +36,7 @@ public class FeedSearcher {
* @param selectedFeed feed to search, 0 to search through all feeds
* @return list of episodes containing the query
*/
@NonNull
public static List<SearchResult> performSearch(final Context context,
final String query, final long selectedFeed) {
final int values[] = {2, 1, 0, 0, 0, 0};
@ -45,7 +47,7 @@ public class FeedSearcher {
context.getString(R.string.found_in_authors_label),
context.getString(R.string.found_in_feeds_label)};
List<SearchResult> result = new ArrayList<>();
final List<SearchResult> result = new ArrayList<>();
List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));

View File

@ -83,6 +83,7 @@ public class Timeline {
* @param addTimecodes True if this method should add timecode links
* @return The processed HTML string.
*/
@NonNull
public String processShownotes(final boolean addTimecodes) {
final Playable playable = (shownotesProvider instanceof Playable) ? (Playable) shownotesProvider : null;
@ -92,8 +93,8 @@ public class Timeline {
try {
shownotes = shownotesProvider.loadShownotes().call();
} catch (Exception e) {
e.printStackTrace();
return null;
Log.e(TAG, "processShownotes() - encounters exceptions unexpectedly in load, treat as if no shownotes.", e);
shownotes = "";
}
if (TextUtils.isEmpty(shownotes)) {