Consolidate the networking libraries - drop volley in favor of OkHttp

This commit is contained in:
Paul Hawke 2017-12-09 23:01:47 -06:00
parent 2255bd9a56
commit 32cb8df9ae
8 changed files with 194 additions and 262 deletions

View file

@ -4,9 +4,11 @@ import android.content.ContentProviderClient;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.util.LruCache;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.inject.Named;
import javax.inject.Singleton;
@ -14,7 +16,6 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.auth.AccountUtil;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.caching.CacheController;
@ -24,6 +25,8 @@ import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.nearby.NearbyPlaces;
import fr.free.nrw.commons.upload.UploadController;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import static android.content.Context.MODE_PRIVATE;
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.CONTRIBUTION_AUTHORITY;
@ -69,6 +72,12 @@ public class CommonsApplicationModule {
return context.getContentResolver().acquireContentProviderClient(MODIFICATIONS_AUTHORITY);
}
@Provides
@Singleton
public OkHttpClient provideOkHttpClient() {
return new OkHttpClient.Builder().build();
}
@Provides
@Named("application_preferences")
public SharedPreferences providesApplicationSharedPreferences(Context context) {
@ -126,6 +135,14 @@ public class CommonsApplicationModule {
return new ApacheHttpClientMediaWikiApi(context, BuildConfig.WIKIMEDIA_API_HOST, defaultPreferences, categoryPrefs, gson);
}
@Provides
@Named("commons_mediawiki_url")
@NonNull
@SuppressWarnings("ConstantConditions")
public HttpUrl provideMwUrl() {
return HttpUrl.parse("https://commons.wikimedia.org/");
}
@Provides
@Singleton
public LocationServiceManager provideLocationServiceManager(Context context) {
@ -139,7 +156,7 @@ public class CommonsApplicationModule {
@Provides
@Singleton
public Gson provideGson() {
return new Gson();
return new GsonBuilder().create();
}
@Provides