#2966 RxJava2 null - explicit mark underlying Rx sources as NonNull

to be on the safe side, for cases that the consuming observers checks null
unnecessarily.

Rx observer : underlying sources marked as NonNull
OnlineFeedViewActivity.startFeedDownload : Downloader.getResult
AllEpisodesFragment.loadItems : AllEpisodesFragment.loadData
PlaybackHistoryFragment.loadItems : DBReader.getPlaybackHistory
QueueFragment.loadItems : DBReader.getQueue
SearchFragment.search : .performSearch
This commit is contained in:
orionlee 2019-01-10 11:44:08 -08:00
parent 670fc124eb
commit 0472bb9237
9 changed files with 37 additions and 29 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;
@ -288,12 +288,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;
}

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

@ -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

@ -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

@ -202,6 +202,7 @@ public final class DBReader {
}
}
@NonNull
private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
List<FeedItem> result = new ArrayList<>(cursor.getCount());
@ -254,6 +255,7 @@ public final class DBReader {
return feed;
}
@NonNull
static List<FeedItem> getQueue(PodDBAdapter adapter) {
Log.d(TAG, "getQueue()");
Cursor cursor = null;
@ -310,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");
@ -418,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 + "]");
@ -444,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");

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));