Skip to content

Commit

Permalink
Restructure Dependency classes packages
Browse files Browse the repository at this point in the history
  • Loading branch information
RotBolt committed Jul 29, 2023
1 parent 9aeae33 commit 42443bf
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.createSavedStateHandle
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import io.rotlabs.FlakerDataDependencyContainer
import io.rotlabs.di.FlakerDataContainer
import io.rotlabs.flakerandroidretrofit.ui.FlakerViewModel
import io.rotlabs.flakerdb.networkrequest.data.NetworkRequestRepo
import io.rotlabs.flakerprefs.PrefDataStore
import io.rotlabs.flakerretrofit.FlakerRetrofitDependencyContainer
import io.rotlabs.flakerretrofit.di.FlakerRetrofitCoreContainer

object FlakerAndroidContainer {
object FlakerAndroidRetrofitContainer {

private var networkRequestRepo: NetworkRequestRepo? = null

Expand All @@ -22,9 +22,9 @@ object FlakerAndroidContainer {
private fun prefDataStore() = prefDataStore!!

fun init(appContext: Context) {
FlakerRetrofitDependencyContainer.init(FlakerDataDependencyContainer(appContext))
networkRequestRepo = FlakerRetrofitDependencyContainer.networkRequestRepo()
prefDataStore = FlakerRetrofitDependencyContainer.prefDataStore()
FlakerRetrofitCoreContainer.init(FlakerDataContainer(appContext))
networkRequestRepo = FlakerRetrofitCoreContainer.networkRequestRepo()
prefDataStore = FlakerRetrofitCoreContainer.prefDataStore()
}

val flakerViewModelFactory: ViewModelProvider.Factory = viewModelFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import io.rotlabs.flakerandroidapp.ui.listitem.NetworkRequestItem
import io.rotlabs.flakerandroidapp.ui.listitem.SectionDateItem
import io.rotlabs.flakerandroidapp.ui.theme.FlakerAndroidTheme
import io.rotlabs.flakerandroidretrofit.R
import io.rotlabs.flakerandroidretrofit.di.FlakerAndroidContainer
import io.rotlabs.flakerandroidretrofit.di.FlakerAndroidRetrofitContainer
import io.rotlabs.flakerandroidui.R as AndroidUiR

@OptIn(ExperimentalMaterial3Api::class)
class FlakerActivity : ComponentActivity() {

private val viewModel: FlakerViewModel by viewModels { FlakerAndroidContainer.flakerViewModelFactory }
private val viewModel: FlakerViewModel by viewModels { FlakerAndroidRetrofitContainer.flakerViewModelFactory }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.rotlabs
package io.rotlabs.di

import android.content.Context
import io.rotlabs.flakerdb.DbDriverFactory
Expand All @@ -8,7 +8,7 @@ import io.rotlabs.flakerprefs.DataStoreFactory
import io.rotlabs.flakerprefs.PrefDataStore
import io.rotlabs.flakerprefs.PrefDataStoreImpl

open class FlakerDataDependencyContainer(context: Context) {
open class FlakerDataContainer(context: Context) {

open val networkRequestRepo : NetworkRequestRepo by lazy {
NetworkRequestRepoImpl(DbDriverFactory(context).createDriver())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.rotlabs.flakerretrofit
import io.rotlabs.flakedomain.networkrequest.NetworkRequest
import io.rotlabs.flakerdb.networkrequest.data.NetworkRequestRepo
import io.rotlabs.flakerprefs.PrefDataStore
import io.rotlabs.flakerretrofit.di.FlakerRetrofitCoreContainer
import io.rotlabs.flakerretrofit.dto.FlakerFailResponse
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
Expand Down Expand Up @@ -86,8 +87,8 @@ class FlakerInterceptor private constructor(
}

fun build(): FlakerInterceptor {
val networkRequestRepo = FlakerRetrofitDependencyContainer.networkRequestRepo()
val prefDataStore = FlakerRetrofitDependencyContainer.prefDataStore()
val networkRequestRepo = FlakerRetrofitCoreContainer.networkRequestRepo()
val prefDataStore = FlakerRetrofitCoreContainer.prefDataStore()
return FlakerInterceptor(failResponse, prefDataStore, networkRequestRepo)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.rotlabs.flakerretrofit
package io.rotlabs.flakerretrofit.di

import io.rotlabs.FlakerDataDependencyContainer
import io.rotlabs.di.FlakerDataContainer
import io.rotlabs.flakerdb.networkrequest.data.NetworkRequestRepo
import io.rotlabs.flakerprefs.PrefDataStore

object FlakerRetrofitDependencyContainer {
object FlakerRetrofitCoreContainer {

private var networkRequestRepo: NetworkRequestRepo? = null

Expand All @@ -14,7 +14,7 @@ object FlakerRetrofitDependencyContainer {

fun prefDataStore() = prefDataStore!!

fun init(dataDependencyContainer: FlakerDataDependencyContainer) {
fun init(dataDependencyContainer: FlakerDataContainer) {
networkRequestRepo = dataDependencyContainer.networkRequestRepo
prefDataStore = dataDependencyContainer.prefsDataStore
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.rotlabs.flakerretrofit

import io.rotlabs.flakerprefs.dto.FlakerPrefs
import io.rotlabs.flakerretrofit.di.FlakerRetrofitCoreContainer
import io.rotlabs.flakerretrofit.dto.FlakerFailResponse
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
Expand All @@ -24,11 +25,11 @@ class FlakerInterceptorTest {

private val flakerFailResponse = FlakerFailResponse()

private val testDataDependencyContainer = TestDataDependencyContainer()
private val testDataDependencyContainer = TestDataContainer()

@Before
fun setup() {
FlakerRetrofitDependencyContainer.init(testDataDependencyContainer)
FlakerRetrofitCoreContainer.init(testDataDependencyContainer)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.rotlabs.flakerretrofit

import io.rotlabs.FlakerDataDependencyContainer
import io.rotlabs.di.FlakerDataContainer
import io.rotlabs.flakedomain.networkrequest.NetworkRequest
import io.rotlabs.flakerdb.networkrequest.data.NetworkRequestRepo
import io.rotlabs.flakerprefs.PrefDataStore
Expand All @@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow

class TestDataDependencyContainer : FlakerDataDependencyContainer(FakeContext()) {
class TestDataContainer : FlakerDataContainer(FakeContext()) {

private val fakeNetworkRequestRepo = object : NetworkRequestRepo {
override fun selectAll(): List<NetworkRequest> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.rotlabs.flakersampleapp

import android.app.Application
import io.rotlabs.flakerandroidretrofit.di.FlakerAndroidContainer
import io.rotlabs.flakerandroidretrofit.di.FlakerAndroidRetrofitContainer
import io.rotlabs.flakersampleapp.di.AppContainer

class MainApplication : Application() {
Expand All @@ -10,7 +10,7 @@ class MainApplication : Application() {

override fun onCreate() {
super.onCreate()
FlakerAndroidContainer.init(this)
FlakerAndroidRetrofitContainer.init(this)
appContainer = AppContainer()
}
}

0 comments on commit 42443bf

Please sign in to comment.