-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #210 -- replace dagger component builder with dagger factory
- Loading branch information
Showing
56 changed files
with
657 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package fi.kroon.vadret.core | ||
|
||
import android.content.Context | ||
import com.afollestad.rxkprefs.RxkPrefs | ||
import com.squareup.moshi.Moshi | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import fi.kroon.vadret.core.module.ApiServiceModule | ||
import fi.kroon.vadret.core.module.CacheModule | ||
import fi.kroon.vadret.core.module.DatabaseModule | ||
import fi.kroon.vadret.core.module.NetworkModule | ||
import fi.kroon.vadret.core.module.RxkPrefsModule | ||
import fi.kroon.vadret.data.exception.ErrorHandler | ||
import fi.kroon.vadret.data.persistance.AppDatabase | ||
import okhttp3.OkHttpClient | ||
import okhttp3.internal.cache.DiskLruCache | ||
|
||
@CoreScope | ||
@Component( | ||
modules = [ | ||
ApiServiceModule::class, | ||
CacheModule::class, | ||
DatabaseModule::class, | ||
NetworkModule::class, | ||
RxkPrefsModule::class | ||
] | ||
) | ||
interface CoreComponent { | ||
|
||
fun provideOkHttpClient(): OkHttpClient | ||
fun provideAppDatabase(): AppDatabase | ||
fun provideMoshi(): Moshi | ||
fun provideDiskLruCache(): DiskLruCache | ||
fun provideRxkPrefs(): RxkPrefs | ||
fun provideErrorHandler(): ErrorHandler | ||
|
||
@Component.Factory | ||
interface Factory { | ||
fun create( | ||
@BindsInstance | ||
context: Context | ||
): CoreComponent | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/fi/kroon/vadret/core/CoreComponentFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fi.kroon.vadret.core | ||
|
||
import android.content.Context | ||
|
||
object CoreComponentFactory { | ||
|
||
@Volatile | ||
private var instance: CoreComponent? = null | ||
|
||
fun getInstance(context: Context): CoreComponent = | ||
instance ?: synchronized(this) { | ||
instance ?: DaggerCoreComponent | ||
.factory() | ||
.create( | ||
context = context | ||
).also { instance = it } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/fi/kroon/vadret/core/CoreComponentProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fi.kroon.vadret.core | ||
|
||
interface CoreComponentProvider { | ||
val coreComponent: CoreComponent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fi.kroon.vadret.core | ||
|
||
import javax.inject.Scope | ||
|
||
@Scope | ||
@kotlin.annotation.Retention | ||
annotation class CoreScope |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/fi/kroon/vadret/core/module/ApiServiceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fi.kroon.vadret.core.module | ||
|
||
import com.squareup.moshi.Moshi | ||
import dagger.Module | ||
import dagger.Provides | ||
import fi.kroon.vadret.core.CoreScope | ||
import fi.kroon.vadret.data.common.SingleToArrayAdapter | ||
|
||
@Module | ||
object ApiServiceModule { | ||
|
||
@Provides | ||
@CoreScope | ||
fun provideMoshi(): Moshi = Moshi | ||
.Builder() | ||
.add(SingleToArrayAdapter.INSTANCE) | ||
.build() | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/fi/kroon/vadret/core/module/CacheModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fi.kroon.vadret.core.module | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import fi.kroon.vadret.core.CoreScope | ||
import fi.kroon.vadret.util.DISK_CACHE_SIZE | ||
import okhttp3.internal.cache.DiskLruCache | ||
import okhttp3.internal.io.FileSystem | ||
|
||
@Module | ||
object CacheModule { | ||
|
||
@Provides | ||
@CoreScope | ||
fun provideDiskLruCache(context: Context): DiskLruCache = | ||
DiskLruCache.create( | ||
FileSystem.SYSTEM, | ||
context.cacheDir, | ||
1, | ||
1, | ||
DISK_CACHE_SIZE | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/fi/kroon/vadret/core/module/DatabaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package fi.kroon.vadret.core.module | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import dagger.Module | ||
import dagger.Provides | ||
import fi.kroon.vadret.core.CoreScope | ||
import fi.kroon.vadret.data.persistance.AppDatabase | ||
import fi.kroon.vadret.util.DATABASE_NAME | ||
|
||
@Module | ||
object DatabaseModule { | ||
|
||
@Provides | ||
@CoreScope | ||
fun provideAppDatabase( | ||
context: Context | ||
): AppDatabase = Room.databaseBuilder( | ||
context, | ||
AppDatabase::class.java, | ||
DATABASE_NAME | ||
).build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 3 additions & 8 deletions
11
...kroon/vadret/di/modules/RxkPrefsModule.kt → ...roon/vadret/core/module/RxkPrefsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
package fi.kroon.vadret.di.modules | ||
package fi.kroon.vadret.core.module | ||
|
||
import android.content.Context | ||
import com.afollestad.rxkprefs.RxkPrefs | ||
import com.afollestad.rxkprefs.rxkPrefs | ||
import dagger.Module | ||
import dagger.Provides | ||
import fi.kroon.vadret.data.exception.ErrorHandler | ||
import fi.kroon.vadret.di.scope.CoreApplicationScope | ||
import fi.kroon.vadret.core.CoreScope | ||
import fi.kroon.vadret.util.DEFAULT_SETTINGS | ||
|
||
@Module | ||
object RxkPrefsModule { | ||
|
||
@Provides | ||
@CoreApplicationScope | ||
@CoreScope | ||
fun provideRxkPrefs(context: Context): RxkPrefs = rxkPrefs(context, DEFAULT_SETTINGS) | ||
|
||
@Provides | ||
@CoreApplicationScope | ||
fun provideFailureHandler(): ErrorHandler = ErrorHandler() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/src/main/java/fi/kroon/vadret/data/exception/ErrorHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/src/main/java/fi/kroon/vadret/data/exception/ExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.