menu working
This commit is contained in:
@@ -27,7 +27,7 @@ class Account(val username: String, val password: String, private val error: Int
|
||||
*/
|
||||
|
||||
// check if file exists
|
||||
val file = File(global.fileDir, accountDataFilePath)
|
||||
val file = File(global.fileDir, global.filePaths.accountData)
|
||||
|
||||
return if (!file.exists()) {
|
||||
// it does not exist
|
||||
@@ -44,7 +44,7 @@ class Account(val username: String, val password: String, private val error: Int
|
||||
|
||||
fun save(acc: Account): Boolean {
|
||||
return try {
|
||||
val file = File(global.fileDir, accountDataFilePath)
|
||||
val file = File(global.fileDir, global.filePaths.accountData)
|
||||
file.writeText("${acc.username}\n${acc.password}\n", Charset.forName("UTF-8"))
|
||||
|
||||
true
|
||||
|
||||
@@ -24,17 +24,6 @@ import java.io.File
|
||||
val roundedCornerDimen = 8.dp
|
||||
val borderWidthDimen = 5.dp
|
||||
|
||||
val barModifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(100.dp)
|
||||
.padding(20.dp)
|
||||
//.background(PastelYellowTransparent)
|
||||
.border(
|
||||
width = borderWidthDimen,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
)
|
||||
|
||||
fun makeStatusBarBlack(window: Window) {
|
||||
window.statusBarColor = Color.Black.toArgb()
|
||||
}
|
||||
@@ -50,10 +39,6 @@ var height: Int = 0
|
||||
|
||||
var loaded: Boolean = false
|
||||
|
||||
var studentClass = "1. A"
|
||||
|
||||
var currentLectureNumber = 0
|
||||
|
||||
enum class IsShowing {
|
||||
Timetable,
|
||||
Marks,
|
||||
@@ -70,8 +55,6 @@ enum class Screen {
|
||||
|
||||
var screenToShow: MutableState<Screen> = mutableStateOf(Screen.Main)
|
||||
|
||||
var signedInAndReadyToLaunch: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
var isShowing by mutableStateOf(IsShowing.Timetable)
|
||||
|
||||
// default settings (will get overwritten by the saved settings)
|
||||
@@ -86,8 +69,7 @@ enum class SettingsId {
|
||||
Svoboda,
|
||||
Amoled,
|
||||
RefreshButton,
|
||||
TagNewMarks,
|
||||
DeleteLocalData
|
||||
TagNewMarks
|
||||
}
|
||||
|
||||
class SettingsData {
|
||||
@@ -120,24 +102,10 @@ class SettingsData {
|
||||
|
||||
var settings : SettingsData = SettingsData()
|
||||
|
||||
var done: Boolean = false
|
||||
|
||||
var internetAwaitListenerRunning: Boolean = false
|
||||
|
||||
var timeTableAvailOffline: Boolean = false
|
||||
var marksAvailOffline: Boolean = false
|
||||
|
||||
val subjectNameMap = mutableMapOf<String, String>()
|
||||
|
||||
val dayMap = mutableMapOf<Int, Day>()
|
||||
val dayList = mutableListOf<Day>()
|
||||
var days = listOf<Day>()
|
||||
|
||||
var marks: MutableMap<String, MutableList<Mark>> = mutableMapOf()
|
||||
|
||||
var username: String = ""
|
||||
var password: String = ""
|
||||
|
||||
val client = OkHttpClient()
|
||||
|
||||
enum class LectureNoteType {
|
||||
@@ -279,6 +247,7 @@ class Global {
|
||||
var userData: JSONObject = JSONObject()
|
||||
var timetable: List<Day> = listOf()
|
||||
var lectureNotes: HashMap<Int, LectureNote> = hashMapOf()
|
||||
var subjectNameMap: HashMap<String, String> = hashMapOf()
|
||||
|
||||
var username: String = ""
|
||||
var password: String = ""
|
||||
|
||||
@@ -108,15 +108,15 @@ fun MarksAll() {
|
||||
.padding(horizontal = 5.dp)
|
||||
.verticalScroll(scrollState)
|
||||
) {
|
||||
for ((subject, markList) in marks) {
|
||||
for ((subject, markList) in global.marks) {
|
||||
val amoledModifier = if (settings.useAmoledMode.checked.value) {
|
||||
Modifier
|
||||
.width(150.dp)
|
||||
.fillMaxHeight()
|
||||
.border(
|
||||
width = borderWidthDimen,
|
||||
width = global.dimens.borderWidth,
|
||||
color = getAvgColor(Util.avg(markList), true), // decide on the color (transparent)
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
@@ -124,7 +124,7 @@ fun MarksAll() {
|
||||
.fillMaxHeight()
|
||||
.background(
|
||||
color = getAvgColor(Util.avg(markList)), // decide on the color (not transparent)
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ fun MarksAll() {
|
||||
.border(
|
||||
width = borderWidthDimen,
|
||||
color = getAvgColor(Util.avg(markList), true), // decide on the color (transparent)
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.clickable {
|
||||
global.marksDepthLevel = MarksDepthLevel.Subject
|
||||
@@ -147,7 +147,7 @@ fun MarksAll() {
|
||||
.height(70.dp)
|
||||
.background(
|
||||
color = getAvgColor(Util.avg(markList)), // decide on the color (transparent)
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.clickable {
|
||||
global.marksDepthLevel = MarksDepthLevel.Subject
|
||||
@@ -175,7 +175,7 @@ fun MarksAll() {
|
||||
}
|
||||
marksString += markList[markList.size-1].grade
|
||||
|
||||
if (marks.keys.indexOf(subject) > 0) {
|
||||
if (global.marks.keys.indexOf(subject) > 0) {
|
||||
Box(modifier = Modifier.height(10.dp))
|
||||
}
|
||||
|
||||
@@ -260,9 +260,7 @@ fun MarksAll() {
|
||||
@Composable
|
||||
fun MarksSubject() {
|
||||
// handle the back gesture (back swipe form side or back button on bottom android navbar)
|
||||
BackHandler {
|
||||
global.marksDepthLevel = MarksDepthLevel.All
|
||||
}
|
||||
BackHandler { global.marksDepthLevel = MarksDepthLevel.All }
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
@@ -285,26 +283,26 @@ fun MarksSubject() {
|
||||
.width(70.dp)
|
||||
.height(70.dp)
|
||||
.border(
|
||||
width = 5.dp,
|
||||
width = global.dimens.borderWidth,
|
||||
color = getAvgColor(
|
||||
Util.avg(marks[global.subjectToShow]!!),
|
||||
Util.avg(global.marks[global.subjectToShow]!!),
|
||||
true
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.background(color = if (settings.useAmoledMode.checked.value) {
|
||||
Color.Black
|
||||
} else {
|
||||
getAvgColor(
|
||||
Util.avg(marks[global.subjectToShow]!!)
|
||||
Util.avg(global.marks[global.subjectToShow]!!)
|
||||
)
|
||||
},
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.padding(vertical = 15.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
val currAvg = Util.avg(marks[global.subjectToShow]!!).replace(".", ",")
|
||||
val currAvg = Util.avg(global.marks[global.subjectToShow]!!).replace(".", ",")
|
||||
var textToShow = currAvg
|
||||
if (currAvg.length == 3 && currAvg[2] == '0') {
|
||||
textToShow = currAvg[0].toString()
|
||||
@@ -321,7 +319,7 @@ fun MarksSubject() {
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Text(
|
||||
text = subjectNameMap[global.subjectToShow]!!,
|
||||
text = global.subjectNameMap[global.subjectToShow]!!,
|
||||
color = Color.White,
|
||||
textAlign = TextAlign.Center,
|
||||
fontSize = 30.sp,
|
||||
@@ -330,14 +328,14 @@ fun MarksSubject() {
|
||||
.border(
|
||||
width = 5.dp,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.background(color = if (settings.useAmoledMode.checked.value) {
|
||||
Color.Black
|
||||
} else {
|
||||
PastelYellowTransparent
|
||||
},
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.padding(vertical = 20.dp, horizontal = 10.dp)
|
||||
) // subject
|
||||
@@ -345,7 +343,7 @@ fun MarksSubject() {
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Column(modifier = Modifier.verticalScroll(scrollState)) {
|
||||
for ((i, mark) in marks[global.subjectToShow]!!.withIndex()) {
|
||||
for ((i, mark) in global.marks[global.subjectToShow]!!.withIndex()) {
|
||||
if (i > 0) {
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
}
|
||||
@@ -363,7 +361,7 @@ fun MarksSubject() {
|
||||
} else {
|
||||
getAvgColor(mark.grade)
|
||||
},
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.padding(vertical = 10.dp)
|
||||
.clickable {
|
||||
@@ -444,12 +442,12 @@ fun MarksDetail() {
|
||||
.width(70.dp)
|
||||
.height(70.dp)
|
||||
.border(
|
||||
width = borderWidthDimen,
|
||||
width = global.dimens.borderWidth,
|
||||
color = getAvgColor(
|
||||
Util.avg(mutableListOf(global.markToShow)),
|
||||
true
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.background(
|
||||
if (settings.useAmoledMode.checked.value) {
|
||||
@@ -485,7 +483,7 @@ fun MarksDetail() {
|
||||
.border(
|
||||
width = 5.dp,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.background(
|
||||
if (settings.useAmoledMode.checked.value) {
|
||||
@@ -510,7 +508,7 @@ fun MarksDetail() {
|
||||
} else {
|
||||
PastelYellowTransparent
|
||||
},
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.padding(vertical = 20.dp, horizontal = 10.dp)
|
||||
) {
|
||||
@@ -553,7 +551,7 @@ fun MarksDetail() {
|
||||
} else {
|
||||
PastelYellowTransparent
|
||||
},
|
||||
shape = RoundedCornerShape(roundedCornerDimen)
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)
|
||||
)
|
||||
.padding(vertical = 20.dp, horizontal = 10.dp)
|
||||
) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.odweta.solon.ui.theme.PastelYellow
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
@Composable
|
||||
fun MenuScreen(modifier: Modifier = Modifier) {
|
||||
fun MenuScreen() {
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
@@ -40,15 +40,15 @@ fun MenuScreen(modifier: Modifier = Modifier) {
|
||||
|
||||
Spacer(modifier = Modifier.height(80.dp))
|
||||
|
||||
MenuButton({ screenToShow.value = Screen.SignIn }, "Změnit přihlášení")
|
||||
MenuButton({ global.currentScreen = Screen.SignIn }, "Změnit přihlášení")
|
||||
|
||||
Spacer(modifier = Modifier.height(80.dp))
|
||||
|
||||
MenuButton({ isShowing = IsShowing.About }, "O aplikaci")
|
||||
MenuButton({ global.currentScreenElement = ScreenElement.About }, "O aplikaci")
|
||||
|
||||
Spacer(modifier = Modifier.height(80.dp))
|
||||
|
||||
MenuButton({ isShowing = IsShowing.Settings }, "Nastavení")
|
||||
MenuButton({ global.currentScreenElement = ScreenElement.Settings }, "Nastavení")
|
||||
}
|
||||
|
||||
// Dialog implementation
|
||||
@@ -63,16 +63,20 @@ fun MenuScreen(modifier: Modifier = Modifier) {
|
||||
},
|
||||
containerColor = Color.Black,
|
||||
modifier = Modifier
|
||||
.border(width = 5.dp, color = PastelYellow, shape = RoundedCornerShape(
|
||||
roundedCornerDimen)), // Yellow border
|
||||
.border(
|
||||
width = global.dimens.borderWidth,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)), // Yellow border
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
showDialog = false
|
||||
Util.deleteFile(userDataFilePath)
|
||||
Util.deleteFile(timeTableFilePath)
|
||||
Util.deleteFile(marksFilePath)
|
||||
Util.deleteFile(accountDataFilePath)
|
||||
Util.deleteFile(global.filePaths.userData)
|
||||
Util.deleteFile(global.filePaths.timetable)
|
||||
Util.deleteFile(global.filePaths.marks)
|
||||
Util.deleteFile(global.filePaths.accountData)
|
||||
Util.deleteFile(global.filePaths.lectureNotes)
|
||||
// do not delete settings
|
||||
exitProcess(0)
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
@@ -80,8 +84,10 @@ fun MenuScreen(modifier: Modifier = Modifier) {
|
||||
contentColor = Color.White // Yellow text for the button
|
||||
),
|
||||
modifier = Modifier
|
||||
.border(width = 5.dp, color = PastelYellow, shape = RoundedCornerShape(
|
||||
roundedCornerDimen)) // Yellow border
|
||||
.border(
|
||||
width = global.dimens.borderWidth,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)) // Yellow border
|
||||
) {
|
||||
Text("Ano")
|
||||
}
|
||||
@@ -97,8 +103,10 @@ fun MenuScreen(modifier: Modifier = Modifier) {
|
||||
// Yellow text for the button
|
||||
),
|
||||
modifier = Modifier
|
||||
.border(width = 5.dp, color = PastelYellow, shape = RoundedCornerShape(
|
||||
roundedCornerDimen)) // Yellow border
|
||||
.border(
|
||||
width = global.dimens.borderWidth,
|
||||
color = PastelYellow,
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner)) // Yellow border
|
||||
) {
|
||||
Text("Ne")
|
||||
}
|
||||
@@ -117,8 +125,8 @@ fun MenuButton(onClick: () -> Unit, text: String) {
|
||||
),
|
||||
modifier = Modifier
|
||||
.border(
|
||||
width = 5.dp,
|
||||
shape = RoundedCornerShape(roundedCornerDimen),
|
||||
width = global.dimens.borderWidth,
|
||||
shape = RoundedCornerShape(global.dimens.roundedCorner),
|
||||
color = PastelYellow
|
||||
)
|
||||
.width(230.dp)
|
||||
|
||||
@@ -352,7 +352,7 @@ class Parsing {
|
||||
subjectMap[subj.getString("id")] = subj.getString("abbrev")
|
||||
|
||||
// map names to abbrevs
|
||||
subjectNameMap[subj.getString("abbrev")] = subj.getString("name")
|
||||
global.subjectNameMap[subj.getString("abbrev")] = subj.getString("name")
|
||||
}
|
||||
|
||||
for (i in 0..<marksJSONArray.length()) {
|
||||
|
||||
@@ -48,9 +48,9 @@ private fun changeButtonText(s: String) {
|
||||
}
|
||||
|
||||
fun signInButtonCallback(ctx: Context, usernameText: String, passwordText: String) {
|
||||
username = usernameText
|
||||
password = passwordText
|
||||
val acc = Account(username, password, 0)
|
||||
global.username = usernameText
|
||||
global.password = passwordText
|
||||
val acc = Account(global.username, global.password, 0)
|
||||
var checked = false
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
Reference in New Issue
Block a user