toolbar working (removed the loading 'animation' when fetching new remote data)
This commit is contained in:
@@ -74,8 +74,6 @@ var signedInAndReadyToLaunch: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
var isShowing by mutableStateOf(IsShowing.Timetable)
|
||||
|
||||
var toolbarText: MutableState<String> = 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<Int, LectureNote> = hashMapOf()
|
||||
var status by mutableStateOf("")
|
||||
var currentScreen by mutableStateOf(Screen.Main)
|
||||
var currentScreenElement by mutableStateOf(ScreenElement.Timetable)
|
||||
inner class FilePaths {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user