mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Better null result handling
// FREEBIE
This commit is contained in:
parent
469f41b955
commit
4bf3632b40
@ -42,7 +42,7 @@ public abstract class GiphyLoader extends AsyncLoader<List<GiphyImage>> {
|
||||
return loadPage(0);
|
||||
}
|
||||
|
||||
public List<GiphyImage> loadPage(int offset) {
|
||||
public @NonNull List<GiphyImage> loadPage(int offset) {
|
||||
try {
|
||||
String url;
|
||||
|
||||
@ -56,9 +56,12 @@ public abstract class GiphyLoader extends AsyncLoader<List<GiphyImage>> {
|
||||
throw new IOException("Unexpected code " + response);
|
||||
}
|
||||
|
||||
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
|
||||
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
|
||||
List<GiphyImage> results = giphyResponse.getData();
|
||||
|
||||
if (results == null) return new LinkedList<>();
|
||||
else return results;
|
||||
|
||||
return giphyResponse.getData();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
return new LinkedList<>();
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.giph.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -106,7 +107,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
public void setImages(List<GiphyImage> images) {
|
||||
public void setImages(@NonNull List<GiphyImage> images) {
|
||||
this.images = images;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.giph.ui;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
@ -63,11 +64,11 @@ public abstract class GiphyFragment extends Fragment implements LoaderManager.Lo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<GiphyImage>> loader, List<GiphyImage> data) {
|
||||
public void onLoadFinished(Loader<List<GiphyImage>> loader, @NonNull List<GiphyImage> data) {
|
||||
this.loadingProgress.setVisibility(View.GONE);
|
||||
|
||||
if (data == null || data.isEmpty()) noResultsView.setVisibility(View.VISIBLE);
|
||||
else noResultsView.setVisibility(View.GONE);
|
||||
if (data.isEmpty()) noResultsView.setVisibility(View.VISIBLE);
|
||||
else noResultsView.setVisibility(View.GONE);
|
||||
|
||||
this.giphyAdapter.setImages(data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user