Skip to content

Commit 2a28cd2

Browse files
stslexstslex
andauthored
Develop (#32)
* Refactor/mapper (#26) * refactor mappers injection * add tests * add tests * add tests * refactoring (#28) * Refactor/modules structure (#29) * refactoring * refactor catalogs and modules structure * refactor * merge changes * refactor navigation on one screen (#31) Co-authored-by: stslex <[email protected]>
1 parent b9a528c commit 2a28cd2

File tree

24 files changed

+366
-154
lines changed

24 files changed

+366
-154
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/stslex/cnotes/MainActivity.kt

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,62 @@ package com.stslex.cnotes
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6+
import androidx.compose.animation.ExperimentalAnimationApi
67
import androidx.compose.foundation.isSystemInDarkTheme
78
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
89
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
10+
import androidx.compose.runtime.Composable
911
import androidx.compose.runtime.SideEffect
1012
import androidx.compose.ui.graphics.Color
1113
import androidx.core.view.WindowCompat
14+
import androidx.navigation.NavHostController
15+
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
1216
import com.google.accompanist.systemuicontroller.SystemUiController
1317
import com.google.accompanist.systemuicontroller.rememberSystemUiController
18+
import com.stslex.cnotes.di.ActivityComponent
1419
import com.stslex.cnotes.ui.AppCreator
1520
import com.stslex.cnotes.utils.ShortcutBuilder
1621
import com.stslex.core_firebase.utils.abstraction.FirebaseAppInitialisationUtil
1722
import org.koin.android.ext.android.inject
23+
import org.koin.core.context.loadKoinModules
1824

1925
class MainActivity : ComponentActivity() {
2026

2127
private val firebaseAppInitialisationUtil: FirebaseAppInitialisationUtil by inject()
2228
private val shortcutBuilder: ShortcutBuilder by inject()
2329

24-
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
30+
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class, ExperimentalAnimationApi::class)
2531
override fun onCreate(savedInstanceState: Bundle?) {
26-
firebaseAppInitialisationUtil.invoke()
32+
firebaseAppInitialisationUtil()
2733
super.onCreate(savedInstanceState)
2834
WindowCompat.setDecorFitsSystemWindows(window, false)
2935
setContent {
30-
val systemUiController: SystemUiController = rememberSystemUiController()
31-
val iconsDark = !isSystemInDarkTheme()
32-
SideEffect {
33-
systemUiController.setSystemBarsColor(
34-
color = Color.Transparent,
35-
darkIcons = iconsDark
36-
)
37-
}
38-
AppCreator(calculateWindowSizeClass(this))
36+
SetUpUIEffects()
37+
val navController = rememberAnimatedNavController()
38+
setUpDependencies(navController)
39+
AppCreator(
40+
windowSizeClass = calculateWindowSizeClass(this),
41+
navController = navController
42+
)
3943
}
4044
shortcutBuilder.invoke()
4145
}
46+
47+
private fun setUpDependencies(navController: NavHostController) {
48+
val component = ActivityComponent()
49+
val moduleNavigation = component.module(navController)
50+
loadKoinModules(moduleNavigation)
51+
}
52+
53+
@Composable
54+
private fun SetUpUIEffects() {
55+
val systemUiController: SystemUiController = rememberSystemUiController()
56+
val iconsDark = !isSystemInDarkTheme()
57+
SideEffect {
58+
systemUiController.setSystemBarsColor(
59+
color = Color.Transparent,
60+
darkIcons = iconsDark
61+
)
62+
}
63+
}
4264
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.stslex.cnotes.di
2+
3+
import androidx.navigation.NavController
4+
import androidx.navigation.NavHostController
5+
import org.koin.core.annotation.Single
6+
import org.koin.core.module.Module
7+
import org.koin.dsl.module
8+
9+
@Single
10+
class ActivityComponent {
11+
12+
val module: (navController: NavHostController) -> Module
13+
get() = { navController ->
14+
module {
15+
single<NavController> { navController }
16+
}
17+
}
18+
}

app/src/main/java/com/stslex/cnotes/navigation/NavigationHost.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import androidx.compose.runtime.Composable
55
import androidx.compose.ui.Modifier
66
import androidx.navigation.NavGraph.Companion.findStartDestination
77
import androidx.navigation.NavHostController
8+
import com.google.accompanist.navigation.animation.AnimatedNavHost
9+
import com.stslex.core_navigation.destinations.AuthCodeDestination
10+
import com.stslex.core_navigation.destinations.NoteListDestination
11+
import com.stslex.core_navigation.destinations.PhoneNumberDestination
12+
import com.stslex.core_navigation.destinations.ProfileDestination
813
import com.stslex.feature_auth_code.navigation.authCodeGraph
914
import com.stslex.feature_auth_phonenumber.navigation.authPhoneNumberGraph
1015
import com.stslex.feature_note_list.navigation.noteListGraph
11-
import com.google.accompanist.navigation.animation.AnimatedNavHost
12-
import com.stslex.core_navigation.destinations.*
1316
import com.stslex.feature_profile.navigation.profileGraph
1417
import com.stslex.feature_single_note.navigation.singleNoteGraph
1518
import com.stslex.feature_todo.navigation.todoGraph
@@ -26,11 +29,7 @@ fun NavigationHost(
2629
navController = navController,
2730
startDestination = startDestination
2831
) {
29-
noteListGraph(
30-
openSingleNote = { navController.navigate("${SingleNoteDestination.route}/$it") },
31-
openProfile = { navController.navigate(ProfileDestination.route) },
32-
openAuthPhoneNumber = { navController.navigate(PhoneNumberDestination.route) }
33-
) {
32+
noteListGraph {
3433
singleNoteGraph(popBackStack = { navController.popBackStack() })
3534
}
3635
todoGraph()

app/src/main/java/com/stslex/cnotes/ui/AppCreator.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import androidx.compose.runtime.Composable
1212
import androidx.compose.runtime.getValue
1313
import androidx.compose.runtime.remember
1414
import androidx.compose.ui.Modifier
15+
import androidx.navigation.NavController
16+
import androidx.navigation.NavHostController
1517
import androidx.navigation.compose.currentBackStackEntryAsState
1618
import com.stslex.feature_note_list.navigation.noteListTopLevelDestination
1719
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
@@ -34,9 +36,11 @@ private val listOfDestinations = listOf(
3436
ExperimentalAnimationApi::class
3537
)
3638
@Composable
37-
fun AppCreator(windowSizeClass: WindowSizeClass) {
39+
fun AppCreator(
40+
windowSizeClass: WindowSizeClass,
41+
navController: NavHostController
42+
) {
3843
AppTheme(dynamicColor = Build.VERSION.SDK_INT > 30) {
39-
val navController = rememberAnimatedNavController()
4044
val niaTopLevelNavigation = remember(navController) {
4145
AppTopLevelNavigation(navController)
4246
}

feature-note-list/src/main/java/com/stslex/feature_note_list/di/NoteListModule.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
package com.stslex.feature_note_list.di
22

33
import androidx.paging.PagingConfig
4-
import com.stslex.feature_note_list.ui.NotesViewModel
54
import com.stslex.core_model.common.MapperName
65
import com.stslex.feature_note_list.data.abstraction.NoteListRepository
76
import com.stslex.feature_note_list.data.realisation.NoteListRepositoryImpl
7+
import com.stslex.feature_note_list.navigation.NoteListRouter
8+
import com.stslex.feature_note_list.navigation.NoteListRouterImpl
9+
import com.stslex.feature_note_list.ui.NotesViewModel
810
import org.koin.androidx.viewmodel.dsl.viewModel
911
import org.koin.core.module.dsl.bind
1012
import org.koin.core.module.dsl.factoryOf
1113
import org.koin.core.qualifier.named
1214
import org.koin.dsl.module
1315

1416
class NoteListModule {
17+
1518
val module = module {
19+
1620
single { PagingConfig(10) }
21+
1722
factoryOf(::NoteListRepositoryImpl) { bind<NoteListRepository>() }
1823

24+
factoryOf(::NoteListRouterImpl) { bind<NoteListRouter>() }
25+
1926
viewModel {
2027
NotesViewModel(
2128
noteRepository = get(),
2229
noteMapper = get(named(MapperName.PAGING_ENTITY_DYNAMIC)),
23-
dispatchers = get()
30+
dispatchers = get(),
31+
router = get()
2432
)
2533
}
2634
}

0 commit comments

Comments
 (0)