ref: open Login from MainActivity, not vice versa
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Created by sweetbread on 22.02.2025, 15:45
|
~ Created by sweetbread
|
||||||
~ Copyright (c) 2025. All rights reserved.
|
~ Copyright (c) 2025. All rights reserved.
|
||||||
~ Last modified 22.02.2025, 14:00
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
@@ -21,7 +20,7 @@
|
|||||||
android:theme="@style/Theme.PixelDragon"
|
android:theme="@style/Theme.PixelDragon"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activity.Login"
|
android:name=".ui.activity.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:theme="@style/Theme.PixelDragon">
|
android:theme="@style/Theme.PixelDragon">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activity.MainActivity"
|
android:name=".ui.activity.Login"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@style/Theme.PixelDragon" />
|
android:theme="@style/Theme.PixelDragon" />
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2025. All rights reserved.
|
||||||
* Last modified 03.03.2025, 16:08
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon.ui.activity
|
package ru.risdeveau.pixeldragon.ui.activity
|
||||||
@@ -36,11 +35,9 @@ import androidx.compose.ui.text.input.KeyboardType
|
|||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.risdeveau.pixeldragon.api.getHomeserver
|
import ru.risdeveau.pixeldragon.api.getHomeserver
|
||||||
import ru.risdeveau.pixeldragon.api.login
|
import ru.risdeveau.pixeldragon.api.login
|
||||||
import ru.risdeveau.pixeldragon.initCheck
|
|
||||||
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
||||||
import splitties.activities.start
|
import splitties.activities.start
|
||||||
|
|
||||||
@@ -49,14 +46,6 @@ class Login : ComponentActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
|
||||||
GlobalScope.launch {
|
|
||||||
if (initCheck()) {
|
|
||||||
start<MainActivity>()
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
PixelDragonTheme {
|
PixelDragonTheme {
|
||||||
@@ -75,7 +64,10 @@ class Login : ComponentActivity() {
|
|||||||
.padding(innerPadding)) {
|
.padding(innerPadding)) {
|
||||||
LoginField(
|
LoginField(
|
||||||
Modifier.align(Alignment.Center),
|
Modifier.align(Alignment.Center),
|
||||||
{ start<MainActivity>() },
|
{
|
||||||
|
start<MainActivity>()
|
||||||
|
finish()
|
||||||
|
},
|
||||||
{
|
{
|
||||||
scope.launch {
|
scope.launch {
|
||||||
snackbarHostState
|
snackbarHostState
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import ru.risdeveau.pixeldragon.api.Me
|
import ru.risdeveau.pixeldragon.api.Me
|
||||||
import ru.risdeveau.pixeldragon.api.getMe
|
import ru.risdeveau.pixeldragon.api.getMe
|
||||||
|
import ru.risdeveau.pixeldragon.initCheck
|
||||||
import ru.risdeveau.pixeldragon.ui.layout.Room
|
import ru.risdeveau.pixeldragon.ui.layout.Room
|
||||||
import ru.risdeveau.pixeldragon.ui.layout.RoomList
|
import ru.risdeveau.pixeldragon.ui.layout.RoomList
|
||||||
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
||||||
|
import splitties.activities.start
|
||||||
|
|
||||||
var ME: Me? = null
|
var ME: Me? = null
|
||||||
|
|
||||||
@@ -59,18 +61,30 @@ class MainActivity : ComponentActivity() {
|
|||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
withContext(Dispatchers.IO) {
|
if (initCheck()) {
|
||||||
ME = getMe()
|
ME = withContext(Dispatchers.IO) { getMe() }
|
||||||
|
if (ME != null) {
|
||||||
|
navController.navigate("rooms")
|
||||||
|
} else {
|
||||||
|
start<Login>()
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start<Login>()
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NavHost(navController = navController, startDestination = "rooms") {
|
NavHost(navController = navController, startDestination = "none") {
|
||||||
|
composable("none") { }
|
||||||
composable("rooms") { RoomList(Modifier.padding(innerPadding), navController) }
|
composable("rooms") { RoomList(Modifier.padding(innerPadding), navController) }
|
||||||
composable(
|
composable(
|
||||||
"room/{rid}",
|
"room/{rid}",
|
||||||
arguments = listOf(navArgument("rid") { type = NavType.StringType })
|
arguments = listOf(navArgument("rid") { type = NavType.StringType })
|
||||||
) { navBackStackEntry ->
|
) { navBackStackEntry ->
|
||||||
Room(Modifier.padding(innerPadding).fillMaxSize(), navBackStackEntry.arguments!!.getString("rid")!!)
|
Room(Modifier
|
||||||
|
.padding(innerPadding)
|
||||||
|
.fillMaxSize(), navBackStackEntry.arguments!!.getString("rid")!!)
|
||||||
}
|
}
|
||||||
composable(
|
composable(
|
||||||
"space/{rid}",
|
"space/{rid}",
|
||||||
|
|||||||
Reference in New Issue
Block a user