This commit is contained in:
KP9lK 2025-03-21 17:46:42 +03:00
parent d87059a190
commit 31f6ead9fe
6 changed files with 42 additions and 3 deletions
app

View File

@ -53,6 +53,8 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:4.7.2")
implementation("io.insert-koin:koin-compose:4.1.0-Beta5")
implementation("io.insert-koin:koin-compose-viewmodel:4.1.0-Beta5")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)

View File

@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".MainApplication"
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"

View File

@ -21,8 +21,10 @@ import com.example.netwrok_datastore.domain.usecase.AuthUseCase
import com.example.netwrok_datastore.ui.screen.ProfileScreen
import com.example.netwrok_datastore.ui.screen.SplashScreen
import com.example.netwrok_datastore.ui.screen.registration.RegistrationScreen
import com.example.netwrok_datastore.ui.screen.registration.RegistrationViewModel
import com.example.netwrok_datastore.ui.theme.NetwrokDatastoreTheme
import kotlinx.serialization.Serializable
import org.koin.androidx.viewmodel.ext.android.viewModel
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -33,6 +35,7 @@ class MainActivity : ComponentActivity() {
val localStorage = LocalStorage(applicationContext)
val authUseCase = AuthUseCase(localStorage, authRepository)
val registrationViewModel: RegistrationViewModel by viewModel()
setContent {
val navController = rememberNavController()
NetwrokDatastoreTheme {
@ -48,7 +51,7 @@ class MainActivity : ComponentActivity() {
}
}
composable<Registration> {
RegistrationScreen(authUseCase){
RegistrationScreen(registrationViewModel){
navController.navigate(route = Profile)
}
}

View File

@ -0,0 +1,16 @@
package com.example.netwrok_datastore
import android.app.Application
import com.example.netwrok_datastore.di.appModules
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
class MainApplication: Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidContext(applicationContext)
modules(appModules)
}
}
}

View File

@ -0,0 +1,18 @@
package com.example.netwrok_datastore.di
import com.example.netwrok_datastore.data.AuthRepository
import com.example.netwrok_datastore.data.local.LocalStorage
import com.example.netwrok_datastore.data.remote.RetrofitSettings
import com.example.netwrok_datastore.data.remote.auth.AuthApi
import com.example.netwrok_datastore.domain.usecase.AuthUseCase
import com.example.netwrok_datastore.ui.screen.registration.RegistrationViewModel
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
val appModules = module {
single { LocalStorage(get()) }
single<AuthApi> { RetrofitSettings.authApi }
single<AuthRepository> { AuthRepository(get()) }
single { AuthUseCase(get(), get()) }
viewModel { RegistrationViewModel(get()) }
}

View File

@ -31,8 +31,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
@Composable
fun RegistrationScreen(authUseCase: AuthUseCase, onNavigationToProfile: ()-> Unit){
val viewModel = RegistrationViewModel(authUseCase)
fun RegistrationScreen(viewModel: RegistrationViewModel, onNavigationToProfile: ()-> Unit){
val snackBarHostState = remember { SnackbarHostState() }
Scaffold(