package com.felixsu.skyseeker.provider;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.felixsu.skyseeker.constant.Constants;
import com.felixsu.skyseeker.service.ForecastService;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.GoogleApiClient;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.Cache;
import okhttp3.OkHttpClient;

/**
 * Created by felixsu on 03/06/2016.
 */

@Module
public class UtilModule {

    @Provides
    @Singleton
    public SharedPreferences provideSharedPreference(Application application){
        return PreferenceManager.getDefaultSharedPreferences(application);
    }

    @Provides
    @Singleton
    public ObjectMapper provideObjectMapper(){
        return new ObjectMapper();
    }

    @Provides
    @Singleton
    Cache provideOkHttpCache(Application application) {
        int cacheSize = 1 * 1024 * 1024; // 1 MiB
        Cache cache = new Cache(application.getCacheDir(), cacheSize);
        return cache;
    }

    @Provides
    @Singleton
    OkHttpClient provideOkHttpClient(Cache cache) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .cache(cache);

        return builder.build();
    }

    @Provides
    @Singleton
    ForecastService provideForecastService(OkHttpClient client){
        ForecastService service = new ForecastService(client);
        return service;
    }
}

@@ -239,250 +239,31 @@
 ker.
-constant.Constants;%0Aimport com.felixsu.skyseeker.service.ForecastService;%0Aimport com.google.android.gms.auth.api.Auth;%0Aimport com.google.android.gms.auth.api.signin.GoogleSignInOptions;%0Aimport com.google.android.gms.common.api.GoogleApiClient
+service.ForecastService
 ;%0A%0Ai
@@ -343,30 +343,8 @@
 es;%0A
-import okhttp3.Cache;%0A
 impo
@@ -762,243 +762,8 @@
  %7D%0A%0A
-    @Provides%0A    @Singleton%0A    Cache provideOkHttpCache(Application application) %7B%0A        int cacheSize = 1 * 1024 * 1024; // 1 MiB%0A        Cache cache = new Cache(application.getCacheDir(), cacheSize);%0A        return cache;%0A    %7D%0A%0A
     
@@ -828,19 +828,8 @@
 ent(
-Cache cache
 ) %7B%0A
@@ -897,40 +897,9 @@
 er()
-%0A                .cache(cache);%0A
+;
 %0A   

remove cache EONT warning