Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullability annotations to okhttp3 module and its dependencies #2685

Merged
merged 2 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.okhttp3;

import android.content.Context;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
Expand All @@ -19,7 +20,8 @@
@GlideModule
public final class OkHttpLibraryGlideModule extends LibraryGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
@NonNull Registry registry) {
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) {
}

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
public void onResponse(@NonNull Call call, @NonNull Response response) {
responseBody = response.body();
if (response.isSuccessful()) {
long contentLength = Preconditions.checkNotNull(responseBody).contentLength();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.integration.okhttp3;

import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelLoader;
Expand All @@ -18,18 +19,18 @@ public class OkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {

// Public API.
@SuppressWarnings("WeakerAccess")
public OkHttpUrlLoader(Call.Factory client) {
public OkHttpUrlLoader(@NonNull Call.Factory client) {
this.client = client;
}

@Override
public boolean handles(GlideUrl url) {
public boolean handles(@NonNull GlideUrl url) {
return true;
}

@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
Options options) {
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl model, int width, int height,
@NonNull Options options) {
return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}

Expand Down Expand Up @@ -65,10 +66,11 @@ public Factory() {
*
* @param client this is typically an instance of {@code OkHttpClient}.
*/
public Factory(Call.Factory client) {
public Factory(@NonNull Call.Factory client) {
this.client = client;
}

@NonNull
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
return new OkHttpUrlLoader(client);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.volley;

import android.content.Context;
import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
Expand All @@ -21,7 +22,8 @@
@GlideModule
public class VolleyLibraryGlideModule extends LibraryGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
@NonNull Registry registry) {
registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.volley;

import android.content.Context;
import android.support.annotation.NonNull;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.load.Options;
Expand Down Expand Up @@ -32,13 +33,13 @@ public VolleyUrlLoader(RequestQueue requestQueue, VolleyRequestFactory requestFa
}

@Override
public boolean handles(GlideUrl url) {
public boolean handles(@NonNull GlideUrl url) {
return true;
}

@Override
public LoadData<InputStream> buildLoadData(GlideUrl url, int width, int height,
Options options) {
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl url, int width, int height,
@NonNull Options options) {
return new LoadData<>(url, new VolleyStreamFetcher(requestQueue, url, requestFactory));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.data.FileDescriptorAssetPathFetcher;
Expand Down Expand Up @@ -33,14 +34,14 @@ public AssetUriLoader(AssetManager assetManager, AssetFetcherFactory<Data> facto
}

@Override
public LoadData<Data> buildLoadData(Uri model, int width, int height,
Options options) {
public LoadData<Data> buildLoadData(@NonNull Uri model, int width, int height,
@NonNull Options options) {
String assetPath = model.toString().substring(ASSET_PREFIX_LENGTH);
return new LoadData<>(new ObjectKey(model), factory.buildFetcher(assetManager, assetPath));
}

@Override
public boolean handles(Uri model) {
public boolean handles(@NonNull Uri model) {
return ContentResolver.SCHEME_FILE.equals(model.getScheme()) && !model.getPathSegments()
.isEmpty() && ASSET_PATH_SEGMENT.equals(model.getPathSegments().get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public ByteArrayLoader(Converter<Data> converter) {

@Override
public LoadData<Data> buildLoadData(
byte[] model, int width, int height, Options options) {
@NonNull byte[] model, int width, int height, @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new Fetcher<>(model, converter));
}

@Override
public boolean handles(byte[] model) {
public boolean handles(@NonNull byte[] model) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class ByteBufferFileLoader implements ModelLoader<File, ByteBuffer> {
private static final String TAG = "ByteBufferFileLoader";

@Override
public LoadData<ByteBuffer> buildLoadData(File file, int width, int height,
Options options) {
public LoadData<ByteBuffer> buildLoadData(@NonNull File file, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(file), new ByteBufferFetcher(file));
}

@Override
public boolean handles(File file) {
public boolean handles(@NonNull File file) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ public DataUrlLoader(DataDecoder<Data> dataDecoder) {
}

@Override
public LoadData<Data> buildLoadData(String model, int width, int height, Options options) {
public LoadData<Data> buildLoadData(@NonNull String model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new DataUriFetcher<>(model, dataDecoder));
}

@Override
public boolean handles(String url) {
public boolean handles(@NonNull String url) {
return url.startsWith(DATA_SCHEME_IMAGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public FileLoader(FileOpener<Data> fileOpener) {
}

@Override
public LoadData<Data> buildLoadData(File model, int width, int height,
Options options) {
public LoadData<Data> buildLoadData(@NonNull File model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new FileFetcher<>(model, fileOpener));
}

@Override
public boolean handles(File model) {
public boolean handles(@NonNull File model) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Loads the file path for {@link MediaStore} owned {@link Uri uris}.
*/
public final class MediaStoreFileLoader implements ModelLoader<Uri, File> {
public final class MediaStoreFileLoader implements ModelLoader<Uri, File> {

private final Context context;

Expand All @@ -29,12 +29,13 @@ public MediaStoreFileLoader(Context context) {
}

@Override
public LoadData<File> buildLoadData(Uri uri, int width, int height, Options options) {
public LoadData<File> buildLoadData(@NonNull Uri uri, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(uri), new FilePathFetcher(context, uri));
}

@Override
public boolean handles(Uri uri) {
public boolean handles(@NonNull Uri uri) {
return MediaStoreUtil.isMediaStoreUri(uri);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.model;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Options;
Expand Down Expand Up @@ -77,7 +78,8 @@ public LoadData(Key sourceKey, List<Key> alternateKeys, DataFetcher<Data> fetche
* the resource should be loaded at its original height.
*/
@Nullable
LoadData<Data> buildLoadData(Model model, int width, int height, Options options);
LoadData<Data> buildLoadData(@NonNull Model model, int width, int height,
@NonNull Options options);

/**
* Returns true if the given model is a of a recognized type that this loader can probably load.
Expand All @@ -89,5 +91,5 @@ public LoadData(Key sourceKey, List<Key> alternateKeys, DataFetcher<Data> fetche
* results are acceptable. {@link ModelLoader ModelLoaders} that return true from this method may
* return {@code null} from {@link #buildLoadData(Object, int, int, Options)} </p>
*/
boolean handles(Model model);
boolean handles(@NonNull Model model);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, Data> {
}

@Override
public LoadData<Data> buildLoadData(Model model, int width, int height,
Options options) {
public LoadData<Data> buildLoadData(@NonNull Model model, int width, int height,
@NonNull Options options) {
Key sourceKey = null;
int size = modelLoaders.size();
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
Expand All @@ -56,7 +56,7 @@ public LoadData<Data> buildLoadData(Model model, int width, int height,
}

@Override
public boolean handles(Model model) {
public boolean handles(@NonNull Model model) {
for (ModelLoader<Model, Data> modelLoader : modelLoaders) {
if (modelLoader.handles(model)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.model;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.util.Pools.Pool;
Expand Down Expand Up @@ -213,12 +214,13 @@ private static class EmptyModelLoader implements ModelLoader<Object, Object> {

@Nullable
@Override
public LoadData<Object> buildLoadData(Object o, int width, int height, Options options) {
public LoadData<Object> buildLoadData(@NonNull Object o, int width, int height,
@NonNull Options options) {
return null;
}

@Override
public boolean handles(Object o) {
public boolean handles(@NonNull Object o) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.Resources;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.bumptech.glide.load.Options;
Expand All @@ -28,7 +29,8 @@ public ResourceLoader(Resources resources, ModelLoader<Uri, Data> uriLoader) {
}

@Override
public LoadData<Data> buildLoadData(Integer model, int width, int height, Options options) {
public LoadData<Data> buildLoadData(@NonNull Integer model, int width, int height,
@NonNull Options options) {
Uri uri = getResourceUri(model);
return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options);
}
Expand All @@ -49,7 +51,7 @@ private Uri getResourceUri(Integer model) {
}

@Override
public boolean handles(Integer model) {
public boolean handles(@NonNull Integer model) {
// TODO: check that this is in fact a resource id.
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.bumptech.glide.load.Options;
Expand All @@ -24,14 +25,14 @@ public StringLoader(ModelLoader<Uri, Data> uriLoader) {
}

@Override
public LoadData<Data> buildLoadData(String model, int width, int height,
Options options) {
public LoadData<Data> buildLoadData(@NonNull String model, int width, int height,
@NonNull Options options) {
Uri uri = parseUri(model);
return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options);
}

@Override
public boolean handles(String model) {
public boolean handles(@NonNull String model) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public UnitModelLoader() {
}

@Override
public LoadData<Model> buildLoadData(Model model, int width, int height,
Options options) {
public LoadData<Model> buildLoadData(@NonNull Model model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new UnitFetcher<>(model));
}

@Override
public boolean handles(Model model) {
public boolean handles(@NonNull Model model) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.ContentResolver;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher;
Expand Down Expand Up @@ -42,13 +43,13 @@ public UriLoader(LocalUriFetcherFactory<Data> factory) {
}

@Override
public LoadData<Data> buildLoadData(Uri model, int width, int height,
Options options) {
public LoadData<Data> buildLoadData(@NonNull Uri model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model), factory.build(model));
}

@Override
public boolean handles(Uri model) {
public boolean handles(@NonNull Uri model) {
return SCHEMES.contains(model.getScheme());
}

Expand Down
Loading