android: splash screen (to avoid showing welcome screen before the user is loaded) (#345)

* initial attempt -- not recomposing

* change to mutable state, still not working

* two state works, why not three?

* fix so we actually change state

* remove unnecessary brackets

* refactor

* using Boolean? for userCreated

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
IanRDavies
2022-02-22 07:29:41 +00:00
committed by GitHub
parent 1edf60362e
commit 69c79c5e0a
4 changed files with 30 additions and 4 deletions

View File

@@ -53,10 +53,10 @@ class SimplexViewModel(application: Application): AndroidViewModel(application)
@ExperimentalMaterialApi
@Composable
fun MainPage(chatModel: ChatModel, nav: NavController) {
if (chatModel.currentUser.value == null) WelcomeView(chatModel) {
nav.navigate(Pages.ChatList.route)
} else {
ChatListView(chatModel, nav)
when (chatModel.userCreated.value) {
null -> SplashView()
false -> WelcomeView(chatModel) { nav.navigate(Pages.ChatList.route) }
true -> ChatListView(chatModel, nav)
}
}

View File

@@ -10,6 +10,7 @@ import kotlinx.serialization.Serializable
class ChatModel(val controller: ChatController, val alertManager: SimplexApp.AlertManager) {
var currentUser = mutableStateOf<User?>(null)
var userCreated = mutableStateOf<Boolean?>(null)
var chats = mutableStateListOf<Chat>()
var chatId = mutableStateOf<String?>(null)
var chatItems = mutableStateListOf<ChatItem>()

View File

@@ -18,6 +18,7 @@ open class ChatController(val ctrl: ChatCtrl, val alertManager: SimplexApp.Alert
suspend fun startChat(u: User) {
chatModel.currentUser = mutableStateOf(u)
chatModel.userCreated.value = true
Log.d("SIMPLEX (user)", u.toString())
try {
apiStartChat()
@@ -63,6 +64,7 @@ open class ChatController(val ctrl: ChatCtrl, val alertManager: SimplexApp.Alert
val r = sendCmd(CC.ShowActiveUser())
if (r is CR.ActiveUser) return r.user
Log.d("SIMPLEX", "apiGetActiveUser: ${r.responseType} ${r.details}")
chatModel.userCreated.value = false
return null
}

View File

@@ -0,0 +1,23 @@
package chat.simplex.app.views
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import chat.simplex.app.R
@Composable
fun SplashView() {
Box(modifier = Modifier.fillMaxSize()) {
Image(
painter = painterResource(R.drawable.logo),
contentDescription = "Simplex Icon",
modifier = Modifier
.height(230.dp)
.align(Alignment.Center)
)
}
}