Skip to content

Commit

Permalink
Restructure code. Setup Manual DI
Browse files Browse the repository at this point in the history
  • Loading branch information
RotBolt committed Jul 28, 2023
1 parent fda6749 commit f0a3216
Show file tree
Hide file tree
Showing 50 changed files with 433 additions and 839 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/deploymentTargetDropDown.xml
/.idea/*
.DS_Store
/build
/captures
Expand Down
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

117 changes: 0 additions & 117 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

34 changes: 0 additions & 34 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

27 changes: 0 additions & 27 deletions .idea/gradle.xml

This file was deleted.

41 changes: 0 additions & 41 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ potential-bugs:
UnreachableCode:
active: true
UnsafeCallOnNullableType:
active: true
active: false
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**']
UnsafeCast:
active: true
Expand Down
1 change: 1 addition & 0 deletions flaker-android-retrofit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation(project(":flaker-android-ui"))
api(project(":flaker-retrofit-core"))
implementation(project(":flaker-domain"))
implementation(project(":flaker-data"))

implementation(libs.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
Expand Down
2 changes: 1 addition & 1 deletion flaker-android-retrofit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:supportsRtl="true"
tools:targetApi="33">
<activity
android:name="io.rotlabs.flakerandroidretrofit.FlakerActivity"
android:name="io.rotlabs.flakerandroidretrofit.ui.FlakerActivity"
android:exported="true"
android:icon="@mipmap/ic_flaker"
android:label="@string/companion_app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.rotlabs.flakerandroidretrofit.di

import android.content.Context
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.flakerandroidretrofit.ui.FlakerViewModel
import io.rotlabs.flakerdb.networkrequest.data.NetworkRequestRepo
import io.rotlabs.flakerprefs.PrefDataStore
import io.rotlabs.flakerretrofit.FlakerRetrofitDependencyContainer

object FlakerAndroidContainer {

private var networkRequestRepo: NetworkRequestRepo? = null

private var prefDataStore: PrefDataStore? = null

private fun networkRequestRepo() = networkRequestRepo!!

private fun prefDataStore() = prefDataStore!!

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

val flakerViewModelFactory: ViewModelProvider.Factory = viewModelFactory {
initializer {
val savedStateHandle = createSavedStateHandle()
FlakerViewModel(networkRequestRepo(), prefDataStore(), savedStateHandle)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.rotlabs.flakerandroidretrofit
package io.rotlabs.flakerandroidretrofit.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
Expand Down Expand Up @@ -36,12 +36,14 @@ import androidx.compose.ui.unit.dp
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.flakerandroidui.R as AndroidUiR

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

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

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -67,11 +69,13 @@ class FlakerActivity : ComponentActivity() {
}

if (state.toShowPrefs) {
FlakerPrefsDialog(
onDismissRequest = viewModel::closePrefs,
onConfirmAction = viewModel::updatePrefs,
currentValues = viewModel.getCurrentPrefs(),
)
state.currentPrefs?.let { prefs ->
FlakerPrefsDialog(
onDismissRequest = viewModel::closePrefs,
onConfirmAction = viewModel::updatePrefs,
currentValues = prefs,
)
}
}
}
}
Expand Down
Loading

0 comments on commit f0a3216

Please sign in to comment.