Инициализация модулей для даггера

This commit is contained in:
Michael Kits
2022-11-05 16:55:57 +03:00
parent b614ae82d2
commit 227c872317
4 changed files with 71 additions and 3 deletions
+3
View File
@@ -69,4 +69,7 @@ dependencies {
implementation "androidx.room:room-ktx:2.2.6" implementation "androidx.room:room-ktx:2.2.6"
implementation "androidx.navigation:navigation-compose:2.5.3" implementation "androidx.navigation:navigation-compose:2.5.3"
implementation 'com.google.dagger:dagger:2.38.1'
kapt 'com.google.dagger:dagger-compiler:2.34'
} }
@@ -0,0 +1,63 @@
package ru.megboyzz.studentq
import android.app.Activity
import android.app.Application
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.lifecycle.AndroidViewModel
import com.vk.api.sdk.VK
import com.vk.api.sdk.VKApiCallback
import com.vk.api.sdk.VKApiConfig
import com.vk.api.sdk.auth.VKAuthenticationResult
import com.vk.sdk.api.users.UsersService
import com.vk.sdk.api.users.dto.UsersUserFull
import ru.megboyzz.studentq.data.Profile
class AppViewModel(activity: ComponentActivity) : AndroidViewModel(activity.application) {
val authLauncher = VK.login(activity) { result: VKAuthenticationResult ->
when (result) {
is VKAuthenticationResult.Success -> {
Toast.makeText(activity.applicationContext, "Успешный успех", Toast.LENGTH_LONG).show()
val userId = VK.getUserId()
val value = object : VKApiCallback<List<UsersUserFull>> {
override fun fail(error: Exception) {
error.message?.let { Log.e("VK::getUser", it) }
}
override fun success(result: List<UsersUserFull>) {
val name = result[0].firstName
val surname = result[0].lastName
val id = userId.value
if(name != null && surname != null) {
val profile = Profile(name = name, surname = surname, vkID = id, isHeadman = false)
dao?.setProfile(profile)
}
}
}
//Создает кофиг
val config = VKApiConfig(
context = activity.applicationContext,
langProvider = {"ru"}
)
VK.setConfig(config)
VK.execute(
UsersService().usersGet(listOf(userId), listOf()),
value
)
}
is VKAuthenticationResult.Failed -> {
Toast.makeText(this, "Не успех", Toast.LENGTH_LONG).show()
}
}
}
}
@@ -30,13 +30,13 @@ fun SplashScreen(navHostController: NavHostController){
val alphaAnim = animateFloatAsState( val alphaAnim = animateFloatAsState(
targetValue = if (startAnimation) 1f else 0f, targetValue = if (startAnimation) 1f else 0f,
animationSpec = tween( animationSpec = tween(
durationMillis = 1000 durationMillis = 500
) )
) )
LaunchedEffect(key1 = true) { LaunchedEffect(key1 = true) {
startAnimation = true startAnimation = true
delay(1000) delay(500)
navHostController.popBackStack() navHostController.popBackStack()
navHostController.navigate(AppNavRoute.Auth.route) navHostController.navigate(AppNavRoute.Auth.route)
} }
+3 -1
View File
@@ -2,6 +2,8 @@
<resources> <resources>
<style name="Theme.Studentq" parent="android:Theme.Material.Light.NoActionBar"> <style name="Theme.Studentq" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">#CCE6195E</item> <item name="android:statusBarColor">#CCD81858</item>
<item name="android:colorBackground">#FF1E1E1E</item>
</style> </style>
</resources> </resources>