package com.thuytrinh.transactionviewer.app;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;

import com.google.gson.Gson;
import com.thuytrinh.transactionviewer.api.MockRatesFetcher;
import com.thuytrinh.transactionviewer.api.MockTransactionsFetcher;
import com.thuytrinh.transactionviewer.api.RatesFetcher;
import com.thuytrinh.transactionviewer.api.TransactionsFetcher;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import rx.functions.Action1;

@Module
class AppModule {
  private final Context context;

  AppModule(Context context) {
    this.context = context;
  }

  @Provides Resources resources() {
    return context.getResources();
  }

  @Provides TransactionsFetcher transactionsFetcher() {
    return new MockTransactionsFetcher(context.getAssets(), new Gson());
  }

  @Provides RatesFetcher ratesFetcher() {
    return new MockRatesFetcher(context.getAssets(), new Gson());
  }

  @Provides @Singleton Action1<Throwable> errorHandler() {
    return error -> Log.e(App.class.getSimpleName(), error.getMessage(), error);
  }
}

@@ -715,32 +715,97 @@
 sources();%0A  %7D%0A%0A
+  @Provides @Singleton Gson gson() %7B%0A    return new Gson();%0A  %7D%0A%0A
   @Provides Tran
@@ -832,32 +832,41 @@
 sactionsFetcher(
+Gson gson
 ) %7B%0A    return n
@@ -909,34 +909,28 @@
 etAssets(), 
-new G
+g
 son
-()
 );%0A  %7D%0A%0A  @P
@@ -963,16 +963,25 @@
 Fetcher(
+Gson gson
 ) %7B%0A    
@@ -1029,26 +1029,20 @@
 sets(), 
-new G
+g
 son
-()
 );%0A  %7D%0A%0A

Use the same Gson instance