From ce6afefd3f852c7edeaae790e43b68017f1dd919 Mon Sep 17 00:00:00 2001 From: Odweta Date: Sat, 21 Dec 2024 22:59:47 +0100 Subject: [PATCH] toolbar working (removed the loading 'animation' when fetching new remote data) --- .../src/main/java/com/odweta/solon/Global.kt | 3 +- .../src/main/java/com/odweta/solon/Launch.kt | 3 ++ .../src/main/java/com/odweta/solon/Toolbar.kt | 43 ++++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/mobile/app/src/main/java/com/odweta/solon/Global.kt b/mobile/app/src/main/java/com/odweta/solon/Global.kt index 3306364..7b1f32b 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Global.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Global.kt @@ -74,8 +74,6 @@ var signedInAndReadyToLaunch: MutableState = mutableStateOf(false) var isShowing by mutableStateOf(IsShowing.Timetable) -var toolbarText: MutableState = mutableStateOf("") - // default settings (will get overwritten by the saved settings) class Setting(auxId: SettingsId, auxName: String, auxChecked: Boolean) { var id: SettingsId = auxId @@ -301,6 +299,7 @@ class Global { var isAPISetUp: Boolean = false var noSignInBackHandle: Boolean = false var lectureNotes: HashMap = hashMapOf() + var status by mutableStateOf("") var currentScreen by mutableStateOf(Screen.Main) var currentScreenElement by mutableStateOf(ScreenElement.Timetable) inner class FilePaths { diff --git a/mobile/app/src/main/java/com/odweta/solon/Launch.kt b/mobile/app/src/main/java/com/odweta/solon/Launch.kt index 1bbccc8..ce4aff3 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Launch.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Launch.kt @@ -87,6 +87,9 @@ fun launchContinue( // inside show the timetable global.currentScreenElement = ScreenElement.Timetable + + // show the full name of the user in the toolbar as a status + statusFactory.show(StatusType.NameRole) } private fun setOnInternetAvailListener(ctx: Context) { diff --git a/mobile/app/src/main/java/com/odweta/solon/Toolbar.kt b/mobile/app/src/main/java/com/odweta/solon/Toolbar.kt index 870432a..3fe747a 100644 --- a/mobile/app/src/main/java/com/odweta/solon/Toolbar.kt +++ b/mobile/app/src/main/java/com/odweta/solon/Toolbar.kt @@ -14,37 +14,68 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import org.json.JSONObject @Composable fun ToolbarScreen() { // make the font size adaptive relative to the length of the user's name var toolbarTextSizeAdaptive by remember { mutableStateOf(25.sp) } - if (toolbarText.value.length > 28) { + if (global.status.length > 28) { toolbarTextSizeAdaptive = 20.sp } - if (toolbarText.value.length > 32) { + if (global.status.length > 32) { toolbarTextSizeAdaptive = 16.sp } - if (toolbarText.value.length > 40) { + if (global.status.length > 40) { toolbarTextSizeAdaptive = 12.sp } - if (toolbarText.value.length > 45) { + if (global.status.length > 45) { toolbarTextSizeAdaptive = 10.sp } Box(modifier = Modifier.padding(10.dp)) { Text( - text = toolbarText.value, + text = global.status, fontSize = toolbarTextSizeAdaptive, color = Color.White ) } } +enum class StatusType { + NameRole, + NoInternet +} + +interface StatusFactoryInterface { + fun show(type: StatusType) +} + +object StatusFactory: StatusFactoryInterface { + override fun show(type: StatusType) { + when (type) { + StatusType.NameRole -> { + val role = if (Parsing.userIsParent()) { + " – Rodič" + } else { + " – Student" + } + + showStatus("${global.userData.getString("fullName")}$role") + } + StatusType.NoInternet -> { + showStatus("Bez připojení k internetu.") + } + } + } +} + +val statusFactory = StatusFactory + fun showStatus(text: String) { - toolbarText.value = text + global.status = text } \ No newline at end of file