Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,34 @@ android {
}

dependencies {
compile(Config.Libs.kotlin_std)
compile(Config.Libs.appcompat)
compile(Config.Libs.recyclerview)
compile(Config.Libs.cardview)
compile(Config.Libs.palette)
compile(Config.Libs.design)
compile(Config.Libs.eventbus)
compile(Config.Libs.picasso)
compile(Config.Libs.okhttp)
compile(Config.Libs.okhttp_interceptor)
compile(Config.Libs.retrofit)
compile(Config.Libs.retrofit_gson)
compile(Config.Libs.jobqueue)
compile(Config.Libs.anko_sdk15)
compile(Config.Libs.anko_support)
compile(Config.Libs.anko_appcompat)
compile(Config.Libs.anko_design)
compile(Config.Libs.anko_cardview)
compile(Config.Libs.anko_recyclerview)
kapt(Config.Libs.dagger_compiler)
compile(Config.Libs.dagger)
implementation(Config.Libs.kotlin_std)
implementation(Config.Libs.appcompat)
implementation(Config.Libs.recyclerview)
implementation(Config.Libs.cardview)
implementation(Config.Libs.palette)
implementation(Config.Libs.design)
implementation(Config.Libs.eventbus)
implementation(Config.Libs.picasso)
implementation(Config.Libs.okhttp)
implementation(Config.Libs.okhttp_interceptor)
implementation(Config.Libs.retrofit)
implementation(Config.Libs.retrofit_gson)
implementation(Config.Libs.jobqueue)
implementation(Config.Libs.anko_sdk15)
implementation(Config.Libs.anko_support)
implementation(Config.Libs.anko_appcompat)
implementation(Config.Libs.anko_design)
implementation(Config.Libs.anko_cardview)
implementation(Config.Libs.anko_recyclerview)
implementation(Config.Libs.kodein_generic_jvm)
implementation(Config.Libs.kodein_android)

testCompile(Config.TestLibs.junit)
testCompile(Config.TestLibs.mockito)
testImplementation(Config.TestLibs.junit)
testImplementation(Config.TestLibs.mockito)

androidTestCompile(Config.TestLibs.mockito)
androidTestCompile(Config.TestLibs.dexmaker)
androidTestCompile(Config.TestLibs.dexmaker_mockito)
androidTestCompile(Config.TestLibs.annotations)
androidTestCompile(Config.TestLibs.espresso)
androidTestImplementation(Config.TestLibs.mockito)
androidTestImplementation(Config.TestLibs.dexmaker)
androidTestImplementation(Config.TestLibs.dexmaker_mockito)
androidTestImplementation(Config.TestLibs.annotations)
androidTestImplementation(Config.TestLibs.espresso)
}
28 changes: 11 additions & 17 deletions app/src/main/java/com/antonioleiva/bandhookkotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@
package com.antonioleiva.bandhookkotlin

import android.app.Application
import com.antonioleiva.bandhookkotlin.di.ApplicationComponent
import com.antonioleiva.bandhookkotlin.di.ApplicationModule
import com.antonioleiva.bandhookkotlin.di.DaggerApplicationComponent
import com.antonioleiva.bandhookkotlin.di.*
import org.kodein.di.Kodein
import org.kodein.di.KodeinAware
import org.kodein.di.android.androidModule

class App : Application() {
class App : Application(), KodeinAware {

companion object {
lateinit var graph: ApplicationComponent
}

override fun onCreate() {
super.onCreate()
initializeDagger()
}

private fun initializeDagger() {
graph = DaggerApplicationComponent.builder()
.applicationModule(ApplicationModule(this))
.build()
override val kodein = Kodein {
import(androidModule(this@App))
import(appModule(this@App))
import(dataModule(this@App))
import(domainModule)
import(repositoryModule)
}
}

This file was deleted.

84 changes: 84 additions & 0 deletions app/src/main/java/com/antonioleiva/bandhookkotlin/di/AppModules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.antonioleiva.bandhookkotlin.di

import android.content.*
import com.antonioleiva.bandhookkotlin.*
import com.antonioleiva.bandhookkotlin.BuildConfig
import com.antonioleiva.bandhookkotlin.R
import com.antonioleiva.bandhookkotlin.data.*
import com.antonioleiva.bandhookkotlin.data.lastfm.*
import com.antonioleiva.bandhookkotlin.domain.*
import com.antonioleiva.bandhookkotlin.domain.interactor.*
import com.antonioleiva.bandhookkotlin.domain.interactor.base.*
import com.antonioleiva.bandhookkotlin.domain.repository.*
import com.antonioleiva.bandhookkotlin.repository.*
import com.birbit.android.jobqueue.*
import com.squareup.picasso.*
import okhttp3.*
import okhttp3.Cache
import okhttp3.logging.*
import org.kodein.di.Kodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.provider
import org.kodein.di.generic.singleton
import retrofit2.*
import retrofit2.converter.gson.*
import java.util.*


enum class Qualifiers {
ApplicationContext,
LanguageSelection,
ApiKey,
CacheDuration
}

fun appModule(app: App) = Kodein.Module {
bind() from singleton { app }
bind<Context>(Qualifiers.ApplicationContext) with singleton { app }
bind<Bus>() with singleton { BusImpl() }
bind() from singleton { Picasso.Builder(app).build() }
bind<JobManager>() with singleton { CustomJobManager(app) }
bind<InteractorExecutor>() with singleton { InteractorExecutorImpl(instance(), instance()) }
bind<String>(Qualifiers.LanguageSelection) with singleton { Locale.getDefault().language }
}

fun dataModule(appContext: Context) = Kodein.Module {

bind() from singleton { Cache(appContext.cacheDir, 10 * 1024 * 1024.toLong()) }
bind(Qualifiers.ApiKey) from singleton { appContext.getString(R.string.last_fm_api_key) }
bind(Qualifiers.CacheDuration) from singleton { appContext.resources.getInteger(R.integer.cache_duration) }
bind<Interceptor>() with singleton { LastFmRequestInterceptor(instance(Qualifiers.ApiKey), instance(Qualifiers.CacheDuration)) }

bind() from singleton {
OkHttpClient().newBuilder()
.cache(instance())
.addInterceptor(instance())
.addInterceptor(HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
})
.build()
}

bind() from singleton {
Retrofit.Builder()
.baseUrl("http://ws.audioscrobbler.com")
.client(instance())
.addConverterFactory(GsonConverterFactory.create())
.build()
}

bind() from singleton { instance<Retrofit>().create(LastFmService::class.java) }
}

val domainModule = Kodein.Module {
bind() from provider { GetRecommendedArtistsInteractor(instance()) }
bind() from provider { GetArtistDetailInteractor(instance()) }
bind() from provider { GetTopAlbumsInteractor(instance()) }
bind() from provider { GetAlbumDetailInteractor(instance()) }
}

val repositoryModule = Kodein.Module {
bind<ArtistRepository>() with singleton { ArtistRepositoryImpl(listOf(CloudArtistDataSet(instance(Qualifiers.LanguageSelection), instance()))) }
bind<AlbumRepository>() with singleton { AlbumRepositoryImpl(listOf(CloudAlbumDataSet(instance()))) }
}

This file was deleted.

This file was deleted.

58 changes: 0 additions & 58 deletions app/src/main/java/com/antonioleiva/bandhookkotlin/di/DataModule.kt

This file was deleted.

This file was deleted.

This file was deleted.

Loading