mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 20:05:53 -04:00
Merge pull request #111 from kiwix/mhutti1/analytics
Set useragent with app version #73
This commit is contained in:
commit
7605b60a9c
@ -4,15 +4,21 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import javax.inject.Singleton;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.network.KiwixService;
|
||||
import org.kiwix.kiwixmobile.network.UserAgentInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
@Module public class NetworkModule {
|
||||
|
||||
private final static String useragent = "kiwix-android-version:" + BuildConfig.VERSION_CODE;
|
||||
|
||||
@Provides @Singleton OkHttpClient provideOkHttpClient() {
|
||||
return new OkHttpClient().newBuilder().followRedirects(true).followSslRedirects(true).build();
|
||||
return new OkHttpClient().newBuilder().followRedirects(true).followSslRedirects(true)
|
||||
.addNetworkInterceptor(new UserAgentInterceptor(useragent)).build();
|
||||
}
|
||||
|
||||
@Provides @Singleton KiwixService provideKiwixService(OkHttpClient okHttpClient) {
|
||||
|
@ -0,0 +1,25 @@
|
||||
package org.kiwix.kiwixmobile.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Created by mhutti1 on 20/04/17.
|
||||
*/
|
||||
|
||||
public class UserAgentInterceptor implements Interceptor{
|
||||
public final String useragent;
|
||||
|
||||
public UserAgentInterceptor(String useragent) {
|
||||
this.useragent = useragent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request originalRequest = chain.request();
|
||||
Request newUserAgent = originalRequest.newBuilder().header("User-Agent", useragent).build();
|
||||
return chain.proceed(newUserAgent);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user