diff --git a/app/build.gradle b/app/build.gradle index 8cf982f..36cb6e4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -69,4 +69,7 @@ dependencies { implementation "androidx.room:room-ktx:2.2.6" implementation "androidx.navigation:navigation-compose:2.5.3" + + implementation 'com.google.dagger:dagger:2.38.1' + kapt 'com.google.dagger:dagger-compiler:2.34' } \ No newline at end of file diff --git a/app/src/main/java/ru/megboyzz/studentq/AppViewModel.kt b/app/src/main/java/ru/megboyzz/studentq/AppViewModel.kt new file mode 100644 index 0000000..f371dcf --- /dev/null +++ b/app/src/main/java/ru/megboyzz/studentq/AppViewModel.kt @@ -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> { + + override fun fail(error: Exception) { + error.message?.let { Log.e("VK::getUser", it) } + } + + override fun success(result: List) { + + 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() + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/ru/megboyzz/studentq/screens/Splash.kt b/app/src/main/java/ru/megboyzz/studentq/screens/Splash.kt index 6813325..420d8f0 100644 --- a/app/src/main/java/ru/megboyzz/studentq/screens/Splash.kt +++ b/app/src/main/java/ru/megboyzz/studentq/screens/Splash.kt @@ -30,13 +30,13 @@ fun SplashScreen(navHostController: NavHostController){ val alphaAnim = animateFloatAsState( targetValue = if (startAnimation) 1f else 0f, animationSpec = tween( - durationMillis = 1000 + durationMillis = 500 ) ) LaunchedEffect(key1 = true) { startAnimation = true - delay(1000) + delay(500) navHostController.popBackStack() navHostController.navigate(AppNavRoute.Auth.route) } diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 05babe3..bce149a 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -2,6 +2,8 @@ + \ No newline at end of file