content: package com.ladwa.aditya.offlinefirstapp.dagger.module;
  
  import android.app.Application;
  import android.content.SharedPreferences;
  import android.preference.PreferenceManager;
  
  import com.google.gson.FieldNamingPolicy;
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.ladwa.aditya.offlinefirstapp.data.local.AppLocalDataStore;
  import com.ladwa.aditya.offlinefirstapp.data.remote.AppRemoteDataStore;
  
  import javax.inject.Singleton;
  
  import dagger.Module;
  import dagger.Provides;
  import okhttp3.Cache;
  import okhttp3.OkHttpClient;
  import retrofit2.Retrofit;
  import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  /**
   * Created by Aditya on 23-Oct-16.
   */
  
  @Module
  public class DataModule {
      String mBaseUrl;
  
      public DataModule(String mBaseUrl) {
          this.mBaseUrl = mBaseUrl;
      }
  
      @Provides
      @Singleton
      SharedPreferences providesSharedPreferences(Application application) {
          return PreferenceManager.getDefaultSharedPreferences(application);
      }
  
      @Provides
      @Singleton
      Cache provideHttpCache(Application application) {
          int cacheSize = 10 * 1024 * 1024;
          Cache cache = new Cache(application.getCacheDir(), cacheSize);
          return cache;
      }
  
      @Provides
      @Singleton
      Gson provideGson() {
          GsonBuilder gsonBuilder = new GsonBuilder();
          gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
          return gsonBuilder.create();
      }
  
      @Provides
      @Singleton
      OkHttpClient provideOkhttpClient(Cache cache) {
          OkHttpClient.Builder client = new OkHttpClient.Builder();
          client.cache(cache);
          return client.build();
      }
  
      @Provides
      @Singleton
      Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
          Retrofit retrofit = new Retrofit.Builder()
                  .addConverterFactory(GsonConverterFactory.create(gson))
                  .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                  .baseUrl(mBaseUrl)
                  .client(okHttpClient)
                  .build();
          return retrofit;
      }
  
  
      @Provides
      @Singleton
      AppLocalDataStore porvidesAppLocalDataStore(Application context) {
          return new AppLocalDataStore(context);
      }
  
      @Provides
      @Singleton
      AppRemoteDataStore providesRepository() {
          return new AppRemoteDataStore();
      }
  
  }
  