package ru.freedominc.wallenc import android.os.Bundle import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.yandex.authsdk.YandexAuthLoginOptions import com.yandex.authsdk.YandexAuthOptions import com.yandex.authsdk.YandexAuthResult import com.yandex.authsdk.YandexAuthSdk import com.yandex.authsdk.internal.strategy.LoginType import dagger.hilt.android.AndroidEntryPoint import ru.freedominc.wallenc.ui.theme.WallencTheme @AndroidEntryPoint class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() val sdk = YandexAuthSdk.create(YandexAuthOptions(applicationContext, true)) val launcher = registerForActivityResult(sdk.contract) { result -> handleResult(result) } val loginOptions = YandexAuthLoginOptions(LoginType.CHROME_TAB) setContent { WallencTheme { Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> Greeting(modifier = Modifier.padding(innerPadding)) { launcher.launch(loginOptions) } } } } } private fun handleResult(result: YandexAuthResult) { when (result) { is YandexAuthResult.Success -> Toast.makeText(applicationContext, "Success: ${result.token}", Toast.LENGTH_SHORT).show() is YandexAuthResult.Failure -> Toast.makeText(applicationContext, "Success: ${result.exception}", Toast.LENGTH_SHORT).show() YandexAuthResult.Cancelled -> Toast.makeText(applicationContext, "Cancel", Toast.LENGTH_SHORT).show() } } } @Composable fun Greeting(modifier: Modifier = Modifier, onClick: () -> Unit) { Column( modifier = modifier .fillMaxWidth() .fillMaxHeight(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { Button(onClick = onClick) { Text(text = "Login") } } } @Preview(showBackground = true) @Composable fun GreetingPreview() { WallencTheme { Greeting(Modifier) { } } }