Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/20 vk authorization research #41

Merged
merged 13 commits into from
Feb 9, 2024
Merged
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ dependencies {
implementation(libs.firebase.analytics)
implementation(platform(libs.firebase.bom))

// Auth vk
implementation(libs.vkid)

// Ui Kit Library
implementation(project(":uikit"))
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
package app.cashadvisor.authorization.presentation.ui

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import app.cashadvisor.R
import app.cashadvisor.databinding.FragmentEntryBinding
import com.vk.api.sdk.VK
import com.vk.api.sdk.VKApiCallback
import com.vk.api.sdk.auth.VKAuthenticationResult
import com.vk.dto.common.id.UserId
import com.vk.sdk.api.users.UsersService
import com.vk.sdk.api.users.dto.UsersUserFullDto

class EntryFragment : Fragment() {

private var _binding: FragmentEntryBinding? = null
private val binding get() = _binding!!

private val activityVKAuthLauncher = registerForActivityResult(VK.getVKAuthActivityResultContract()) { result ->
when (result) {
is VKAuthenticationResult.Success -> {
Log.d("TEST", "Success: ${result.token.userId}")
avanisimov marked this conversation as resolved.
Show resolved Hide resolved
Toast.makeText(
requireContext(),
"Success: userId ${result.token.userId.value}",
Toast.LENGTH_SHORT
).show()

getUserInfoFromVK(result.token.userId)
}

is VKAuthenticationResult.Failed -> {
Log.d("TEST", "Failed: ${result.exception.authError}")
Toast.makeText(
requireContext(),
"Failed: ${result.exception.authError}",
Toast.LENGTH_LONG
).show()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
Expand All @@ -32,7 +62,6 @@ class EntryFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.btnLogin.setOnClickListener {
findNavController().navigate(R.id.action_entryFragment_to_loginFragment)
}
Expand All @@ -41,10 +70,31 @@ class EntryFragment : Fragment() {
findNavController().navigate(R.id.action_entryFragment_to_signupFragment)
}

binding.btnAuthVk.setOnClickListener {
activityVKAuthLauncher.launch(arrayListOf())
}

}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun getUserInfoFromVK(userId: UserId) {
VK.execute(UsersService().usersGet(userIds = listOf(userId)), object:
VKApiCallback<List<UsersUserFullDto>> {
override fun success(result: List<UsersUserFullDto>) {
Log.d("TEST", "result: ${result.first().firstName}")
Toast.makeText(
requireContext(),
"Success: ${result.first().firstName} ${result.first().lastName}",
Toast.LENGTH_SHORT
).show()
}
override fun fail(error: Exception) {
Log.e("TEST", error.toString())
}
})
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@
app:layout_constraintTop_toTopOf="parent" />


<Button
android:id="@+id/btn_auth_vk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Войти через vk"
avanisimov marked this conversation as resolved.
Show resolved Hide resolved
android:layout_marginVertical="20dp"
app:layout_constraintStart_toStartOf="@id/btn_signup"
app:layout_constraintTop_toBottomOf="@id/btn_signup" />


</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>

<!-- vk auth -->
<integer name="com_vk_sdk_AppId">51807488</integer>
avanisimov marked this conversation as resolved.
Show resolved Hide resolved

</resources>
11 changes: 11 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencyResolutionManagement {
version("gms-googleServices", "4.4.0")
version("firebase.appdistribution", "4.0.1")
version("android-library", "8.1.1")
version("vkid", "4.1.0")


plugin(
Expand Down Expand Up @@ -290,6 +291,16 @@ dependencyResolutionManagement {
"com.google.firebase",
"firebase-crashlytics-gradle"
).versionRef("firebase-crashlytics-gradle")

// Auth vk
library("vkid",
"com.vk",
"android-sdk-core"
).versionRef("vkid")
library("vkid",
"com.vk",
"android-sdk-api"
).versionRef("vkid")
}
}
}
Expand Down
Loading