/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.jessyan.art.di.module;

import android.app.Application;
import android.content.Context;
import android.support.annotation.Nullable;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import me.jessyan.art.integration.cache.Cache;
import me.jessyan.art.integration.cache.CacheType;
import me.jessyan.art.mvp.IRepositoryManager;
import me.jessyan.art.mvp.RepositoryManager;

/**
 * ================================================
 * 提供一些框架必须的实例的 {@link Module}
 * <p>
 * Created by JessYan on 8/4/2016.
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
@Module
public class AppModule {
    private Application mApplication;

    public AppModule(Application application) {
        this.mApplication = application;
    }

    @Singleton
    @Provides
    public Application provideApplication() {
        return mApplication;
    }

    @Singleton
    @Provides
    public Gson provideGson(Application application, @Nullable GsonConfiguration configuration) {
        GsonBuilder builder = new GsonBuilder();
        if (configuration != null)
            configuration.configGson(application, builder);
        return builder.create();
    }

    @Singleton
    @Provides
    public IRepositoryManager provideRepositoryManager(RepositoryManager repositoryManager) {
        return repositoryManager;
    }

    @Singleton
    @Provides
    public Cache<String, Object> provideExtras(Cache.Factory cacheFactory) {
        return cacheFactory.build(CacheType.EXTRAS);
    }


    public interface GsonConfiguration {
        void configGson(Context context, GsonBuilder builder);
    }

}

@@ -727,16 +727,63 @@
 ullable;
+%0Aimport android.support.v4.app.FragmentManager;
 %0A%0Aimport
@@ -838,24 +838,76 @@
 onBuilder;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import javax
@@ -926,16 +926,37 @@
 leton;%0A%0A
+import dagger.Binds;%0A
 import d
@@ -993,16 +993,122 @@
 ovides;%0A
+import me.jessyan.art.integration.ActivityLifecycle;%0Aimport me.jessyan.art.integration.FragmentLifecycle;%0A
 import m
@@ -1614,309 +1614,72 @@
 lic 
-class AppModule %7B%0A    private Application mApplication;%0A%0A    public AppModule(Application application) %7B%0A        this.mApplication = application;%0A    %7D%0A%0A    @Singleton%0A    @Provides%0A    public Application provideApplication() %7B%0A        return mApplication;%0A    %7D%0A%0A    @Singleton%0A    @Provides%0A    publ
+abstract class AppModule %7B%0A    @Singleton%0A    @Provides%0A    stat
 ic G
@@ -1957,42 +1957,26 @@
    @
-Singleton%0A    @Provides%0A    public
+Binds%0A    abstract
  IRe
@@ -1991,23 +1991,20 @@
 Manager 
-provide
+bind
 Reposito
@@ -2053,50 +2053,9 @@
 ger)
- %7B%0A        return repositoryManager;%0A    %7D
+;
 %0A%0A  
@@ -2085,20 +2085,20 @@
 des%0A    
-publ
+stat
 ic Cache
@@ -2218,16 +2218,426 @@
 %0A    %7D%0A%0A
+    @Binds%0A    abstract Application.ActivityLifecycleCallbacks bindActivityLifecycle(ActivityLifecycle activityLifecycle);%0A%0A    @Binds%0A    abstract FragmentManager.FragmentLifecycleCallbacks bindFragmentLifecycle(FragmentLifecycle fragmentLifecycle);%0A%0A    @Singleton%0A    @Provides%0A    static List%3CFragmentManager.FragmentLifecycleCallbacks%3E provideFragmentLifecycles()%7B%0A        return new ArrayList%3C%3E();%0A    %7D%0A
 %0A    pub

Improve AppModule