AppModule.kt 2.92 KB
Newer Older
1
package ru.terrakok.gitlabclient.di.module
2 3

import android.content.Context
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
4
import android.content.res.AssetManager
5
import com.google.gson.Gson
6 7 8
import ru.terrakok.cicerone.Cicerone
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.Router
9
import ru.terrakok.gitlabclient.BuildConfig
10 11
import ru.terrakok.gitlabclient.di.*
import ru.terrakok.gitlabclient.di.provider.GsonProvider
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
12 13 14 15
import ru.terrakok.gitlabclient.entity.app.develop.AppInfo
import ru.terrakok.gitlabclient.model.data.storage.RawAppData
import ru.terrakok.gitlabclient.model.interactor.app.AppInfoInteractor
import ru.terrakok.gitlabclient.model.repository.app.AppInfoRepository
16
import ru.terrakok.gitlabclient.model.repository.session.SessionRepository
17
import ru.terrakok.gitlabclient.model.repository.tools.Base64Tools
18 19 20
import ru.terrakok.gitlabclient.model.system.AppSchedulers
import ru.terrakok.gitlabclient.model.system.ResourceManager
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
21
import ru.terrakok.gitlabclient.model.system.message.SystemMessageNotifier
22 23 24 25 26 27 28
import toothpick.config.Module

/**
 * @author Konstantin Tskhovrebov (aka terrakok) on 20.06.17.
 */
class AppModule(context: Context) : Module() {
    init {
29
        //Global
30
        bind(Context::class.java).toInstance(context)
31
        bind(String::class.java).withName(DefaultServerPath::class.java).toInstance(BuildConfig.ORIGIN_GITLAB_ENDPOINT)
glvvl's avatar
glvvl committed
32
        bind(String::class.java).withName(AppDevelopersPath::class.java).toInstance(BuildConfig.APP_DEVELOPERS_PATH)
33
        bind(PrimitiveWrapper::class.java).withName(DefaultPageSize::class.java).toInstance(PrimitiveWrapper(20))
34
        bind(PrimitiveWrapper::class.java).withName(CacheLifetime::class.java).toInstance(PrimitiveWrapper(300_000L))
35 36
        bind(SchedulersProvider::class.java).toInstance(AppSchedulers())
        bind(ResourceManager::class.java).singletonInScope()
Eugene Tereshkov's avatar
Eugene Tereshkov committed
37
        bind(Base64Tools::class.java).toInstance(Base64Tools())
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
38 39
        bind(AssetManager::class.java).toInstance(context.assets)
        bind(RawAppData::class.java)
40
        bind(SystemMessageNotifier::class.java).toInstance(SystemMessageNotifier())
41
        bind(Gson::class.java).toProvider(GsonProvider::class.java).providesSingletonInScope()
42

43
        //Navigation
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
44
        val cicerone = Cicerone.create()
45 46 47
        bind(Router::class.java).toInstance(cicerone.router)
        bind(NavigatorHolder::class.java).toInstance(cicerone.navigatorHolder)

48 49 50
        //Session
        bind(SessionRepository::class.java).singletonInScope()

Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
51
        //AppInfo
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
52 53
        bind(AppInfo::class.java).toInstance(
            AppInfo(
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
54 55 56 57 58
                BuildConfig.VERSION_NAME,
                BuildConfig.VERSION_CODE,
                BuildConfig.APP_DESCRIPTION,
                BuildConfig.VERSION_UID.take(8),
                BuildConfig.APP_HOME_PAGE,
59
                BuildConfig.FEEDBACK_URL
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
60 61
            )
        )
Konstantin Tskhovrebov's avatar
Konstantin Tskhovrebov committed
62 63
        bind(AppInfoRepository::class.java)
        bind(AppInfoInteractor::class.java)
64 65
    }
}