Начало архитектуры

This commit is contained in:
Пытков Роман
2026-02-15 22:13:41 +03:00
parent 27ebdf4646
commit b48f28dc89
8 changed files with 153 additions and 60 deletions

View File

@@ -0,0 +1,82 @@
package ru.freedominc.wallenc.ui
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 ru.freedominc.wallenc.ui.theme.WallencTheme
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) {
}
}
}