created TempScreen for on-demand recompositions of the whole app.
enhanced UI
This commit is contained in:
-6
@@ -13,12 +13,6 @@
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="TimetablePreview">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="RBPreview">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
</project>
|
||||
@@ -63,7 +63,10 @@ object BackButtonFactory: BackButtonFactoryInterface {
|
||||
@Composable
|
||||
override fun get(type: BackButtonType): @Composable () -> Unit {
|
||||
return when (type) {
|
||||
BackButtonType.Menu -> { { BackButton { global.currentScreenElement = ScreenElement.Menu } } }
|
||||
BackButtonType.Menu -> { { BackButton {
|
||||
global.currentScreenElement = ScreenElement.Menu
|
||||
global.currentScreen = Screen.Main
|
||||
} } }
|
||||
BackButtonType.MarksAll -> { { BackButton {
|
||||
global.currentScreenElement = ScreenElement.Marks
|
||||
global.marksDepthLevel = MarksDepthLevel.All
|
||||
|
||||
@@ -15,12 +15,16 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.RecomposeScope
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalViewConfiguration
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.odweta.solon.ui.theme.PastelYellow
|
||||
@@ -32,7 +36,9 @@ import java.util.concurrent.Callable
|
||||
enum class Screen {
|
||||
Main,
|
||||
Splash,
|
||||
SignIn
|
||||
SignIn,
|
||||
Settings,
|
||||
Temp
|
||||
}
|
||||
|
||||
// default settings (will get overwritten by the saved settings)
|
||||
@@ -187,7 +193,6 @@ enum class ScreenElement {
|
||||
FinalMarks,
|
||||
Menu,
|
||||
About,
|
||||
Settings,
|
||||
SignOut
|
||||
}
|
||||
|
||||
@@ -217,11 +222,13 @@ class Global {
|
||||
var selectedLecture: Int = 0
|
||||
var currentLectureNumber: Int = 0
|
||||
|
||||
var tempScreen by mutableStateOf(Screen.Settings)
|
||||
var currentScreen by mutableStateOf(Screen.Main)
|
||||
var currentScreenElement by mutableStateOf(ScreenElement.Timetable)
|
||||
|
||||
var status by mutableStateOf("")
|
||||
|
||||
var returnToTempScreen by mutableStateOf(false)
|
||||
var isAPISetUp by mutableStateOf(false)
|
||||
var launched by mutableStateOf(false)
|
||||
var refreshed by mutableStateOf(false)
|
||||
@@ -273,9 +280,16 @@ val global = Global()
|
||||
|
||||
var settings = SettingsData()
|
||||
|
||||
private fun <T> changeAndRevert(variable: T, newValue: T, revert: (T) -> Unit) {
|
||||
val orig = variable
|
||||
revert(newValue)
|
||||
revert(orig)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> Animate(targetState: T, content: @Composable (target: T) -> Unit) {
|
||||
if (settings.useAnimations.checked.value == true) {
|
||||
// When animations are enabled, apply AnimatedContent
|
||||
AnimatedContent(
|
||||
targetState = targetState,
|
||||
transitionSpec = {
|
||||
@@ -283,11 +297,16 @@ fun <T> Animate(targetState: T, content: @Composable (target: T) -> Unit) {
|
||||
slideOutVertically(targetOffsetY = { it }) + fadeOut()
|
||||
)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(), label = "animated content"
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
label = "animated content"
|
||||
) { target ->
|
||||
content(target)
|
||||
}
|
||||
} else {
|
||||
// When animations are disabled, just show content without animation
|
||||
content(targetState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,51 +43,52 @@ class MainActivity : ComponentActivity() {
|
||||
Screen.Main -> if (global.launched) MainScreen()
|
||||
Screen.Splash -> SplashScreen()
|
||||
Screen.SignIn -> SignInScreen()
|
||||
Screen.Settings -> SettingsScreen()
|
||||
Screen.Temp -> TempScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainScreen() {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
@Composable
|
||||
fun MainScreen() {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
) {
|
||||
Box(
|
||||
modifier = global.modifiers.bar,
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = global.modifiers.bar,
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
ToolbarScreen()
|
||||
}
|
||||
ToolbarScreen()
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
Animate(global.currentScreenElement) { targetScreen ->
|
||||
when (targetScreen) {
|
||||
ScreenElement.Timetable -> TimetableScreen()
|
||||
ScreenElement.Marks -> MarksScreen()
|
||||
ScreenElement.NewMarks -> NewMarksScreen()
|
||||
ScreenElement.FinalMarks -> FinalMarksScreen()
|
||||
ScreenElement.Menu -> MenuScreen()
|
||||
ScreenElement.About -> AboutScreen()
|
||||
ScreenElement.Settings -> SettingsScreen()
|
||||
ScreenElement.SignOut -> SignOutScreen()
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
Animate(global.currentScreenElement) { targetScreen ->
|
||||
when (targetScreen) {
|
||||
ScreenElement.Timetable -> TimetableScreen()
|
||||
ScreenElement.Marks -> MarksScreen()
|
||||
ScreenElement.NewMarks -> NewMarksScreen()
|
||||
ScreenElement.FinalMarks -> FinalMarksScreen()
|
||||
ScreenElement.Menu -> MenuScreen()
|
||||
ScreenElement.About -> AboutScreen()
|
||||
ScreenElement.SignOut -> SignOutScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = global.modifiers.bar,
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
NavbarScreen()
|
||||
}
|
||||
Box(
|
||||
modifier = global.modifiers.bar,
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
NavbarScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ fun MenuScreen() {
|
||||
Spacer(modifier = Modifier.width(menuSeparatorDimen))
|
||||
|
||||
MenuButton(
|
||||
{ global.currentScreenElement = ScreenElement.Settings },
|
||||
{ global.currentScreen = Screen.Settings },
|
||||
Icons.Default.Settings,
|
||||
"Nastavení"
|
||||
)
|
||||
|
||||
@@ -158,7 +158,7 @@ class Parsing {
|
||||
subj.getJSONArray("teachers")
|
||||
.getJSONObject(0).getString("name") + " " +
|
||||
subj.getJSONArray("teachers")
|
||||
.getJSONObject(0).getString("name")
|
||||
.getJSONObject(0).getString("surname")
|
||||
} else {
|
||||
""
|
||||
}
|
||||
@@ -199,15 +199,13 @@ class Parsing {
|
||||
|
||||
val detailHours = subj.getJSONArray("detailHours")
|
||||
newSubject.number =
|
||||
detailHours.getJSONObject(i).get("id").toString()
|
||||
detailHours.getJSONObject(i).getString("id")
|
||||
newSubject.start =
|
||||
detailHours.getJSONObject(i).get("timeFrom")
|
||||
.toString()
|
||||
detailHours.getJSONObject(i).getString("timeFrom")
|
||||
newSubject.start =
|
||||
newSubject.start.slice(0..newSubject.start.length - 4)
|
||||
newSubject.end =
|
||||
detailHours.getJSONObject(i).get("timeto")
|
||||
.toString()
|
||||
detailHours.getJSONObject(i).getString("timeto")
|
||||
newSubject.end =
|
||||
newSubject.end.slice(0..newSubject.end.length - 4)
|
||||
subjects.add(newSubject)
|
||||
@@ -217,7 +215,7 @@ class Parsing {
|
||||
}
|
||||
|
||||
val sCopy = subjects.toList()
|
||||
for (s in 0 until sCopy.size) {
|
||||
for (s in sCopy.indices) {
|
||||
if ("-" in subjects[s].number) {
|
||||
subjects[s].number = "1"
|
||||
subjects[s].start = "08:00"
|
||||
@@ -226,26 +224,6 @@ class Parsing {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// rust pseudocode
|
||||
|
||||
let mut res: Vec<i32> = vec![];
|
||||
for i in 0..v.len()-1 {
|
||||
if v[i] == v[i+1]-1 {
|
||||
res.push(v[i]);
|
||||
} else {
|
||||
res.push(v[i]);
|
||||
|
||||
while res[res.len()-1]+1 != v[i+1] {
|
||||
res.push(res[res.len()-1]+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
res.push(v[v.len()-1]);
|
||||
|
||||
res
|
||||
*/
|
||||
|
||||
if (subjects.size > 1) {
|
||||
for (i in 0..<subjects.size - 1) {
|
||||
if (subjects[i].number == ((subjects[i + 1].number.toInt() - 1).toString())) {
|
||||
|
||||
@@ -38,7 +38,10 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun SettingsScreen() {
|
||||
// handle the back gesture (back swipe form side or back button on bottom android navbar)
|
||||
BackHandler { global.currentScreenElement = ScreenElement.Menu }
|
||||
BackHandler {
|
||||
global.currentScreenElement = ScreenElement.Menu
|
||||
global.currentScreen = Screen.Main
|
||||
}
|
||||
|
||||
// load the settings dat every time the settings screen is opened,
|
||||
// maybe i can add a flag that determines if the settings are up to date?
|
||||
@@ -87,6 +90,7 @@ fun SettingsTableRow(setting: Setting) {
|
||||
checked = setting.checked.value == true,
|
||||
onCheckedChange = {
|
||||
setting.checked.value = it
|
||||
showTempScreen(Screen.Settings)
|
||||
Util.saveStringToFile(global.filePaths.settings, settings.toString())
|
||||
},
|
||||
colors = SwitchColors(
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.odweta.solon
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
// temporary screens to artificially trigger recompositions basically at the root level
|
||||
|
||||
@Composable
|
||||
fun TempScreen() {
|
||||
when (global.tempScreen) {
|
||||
Screen.Main -> MainScreen()
|
||||
Screen.Splash -> SplashScreen()
|
||||
Screen.SignIn -> SignInScreen()
|
||||
Screen.Settings -> SettingsScreen()
|
||||
Screen.Temp -> {}
|
||||
}
|
||||
}
|
||||
|
||||
fun showTempScreen(screen: Screen) {
|
||||
global.returnToTempScreen = true
|
||||
global.tempScreen = screen
|
||||
global.currentScreen = Screen.Temp
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import androidx.compose.ui.focus.focusModifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -440,8 +441,9 @@ private fun DayScreen(day: Day) {
|
||||
|
||||
Text(
|
||||
text = " supl ",
|
||||
color = Color.Black,
|
||||
modifier = Modifier.background(color = Color.White)
|
||||
color = Color.White,
|
||||
fontStyle = FontStyle.Italic,
|
||||
modifier = Modifier.background(color = PastelRedTransparent)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -486,8 +488,7 @@ private fun DayScreen(day: Day) {
|
||||
) {
|
||||
if (settings.useSvobodaMode.checked.value == true) {
|
||||
if (
|
||||
subject.teacher == "Jindřich Svoboda" &&
|
||||
global.studentClass == "5. G"
|
||||
subject.teacher == "Jindřich Svoboda"
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.spock),
|
||||
|
||||
Reference in New Issue
Block a user