fixed a couple of bugs, added colors to certain lecture types and fixed issue #5
This commit is contained in:
@@ -104,6 +104,13 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
rootLayout.addView(nameDateTextView)
|
||||
|
||||
for (subj in day.subjects) {
|
||||
val subjectBackground = when (subj.substitute) {
|
||||
"0" -> if (subj.place != "Volno") { R.color.cal_week_subject } else { R.color.cal_week_free }
|
||||
"1" -> if (subj.place != "Volno") { R.color.cal_week_substitute } else { R.color.cal_week_free }
|
||||
"2" -> if (subj.place != "Volno") { R.color.cal_week_event } else { R.color.cal_week_free }
|
||||
else -> R.color.cal_week_subject
|
||||
}
|
||||
|
||||
val subjectDrawable = GradientDrawable()
|
||||
subjectDrawable.shape = GradientDrawable.RECTANGLE
|
||||
subjectDrawable.cornerRadius =
|
||||
@@ -111,7 +118,7 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
subjectDrawable.setColor(
|
||||
ContextCompat.getColor(
|
||||
requireContext(),
|
||||
R.color.cal_week_subject
|
||||
subjectBackground
|
||||
)
|
||||
) // Use your desired background color
|
||||
|
||||
@@ -256,6 +263,27 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
resources.getDimensionPixelSize(R.dimen.cal_week_separator_height) // Specify separator height in resources
|
||||
)
|
||||
|
||||
// drawables
|
||||
val substituteDrawable = GradientDrawable()
|
||||
substituteDrawable.shape = GradientDrawable.RECTANGLE
|
||||
substituteDrawable.cornerRadius = resources.getDimension(R.dimen.corner_radius)
|
||||
substituteDrawable.setColor(
|
||||
ContextCompat.getColor(
|
||||
requireContext(),
|
||||
R.color.cal_week_substitute
|
||||
)
|
||||
)
|
||||
|
||||
val eventDrawable = GradientDrawable()
|
||||
eventDrawable.shape = GradientDrawable.RECTANGLE
|
||||
eventDrawable.cornerRadius = resources.getDimension(R.dimen.corner_radius)
|
||||
eventDrawable.setColor(
|
||||
ContextCompat.getColor(
|
||||
requireContext(),
|
||||
R.color.cal_week_event
|
||||
)
|
||||
)
|
||||
|
||||
// Attach an OnPreDrawListener to the rootLayout's ViewTreeObserver
|
||||
rootLayout.viewTreeObserver.addOnPreDrawListener(object :
|
||||
ViewTreeObserver.OnPreDrawListener {
|
||||
@@ -263,6 +291,15 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
// Remove the listener to avoid multiple callbacks
|
||||
rootLayout.viewTreeObserver.removeOnPreDrawListener(this)
|
||||
|
||||
if (dayLayout.height < rootLayout.height) {
|
||||
val sepr = Space(requireContext())
|
||||
sepr.layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
rootLayout.height - dayLayout.height
|
||||
)
|
||||
rootLayout.addView(sepr)
|
||||
}
|
||||
|
||||
// Call your function or perform an action here
|
||||
if (day.subjects[0].substitute != "2") {
|
||||
subjectPlaceTextView.setPadding(
|
||||
@@ -278,6 +315,15 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
subjectNameTextView.gravity = Gravity.CENTER_VERTICAL
|
||||
}
|
||||
|
||||
// check for substitute hours and change the background
|
||||
/*for (s in day.subjects) {
|
||||
when (s.substitute) {
|
||||
"1" -> subjectLayout.background = substituteDrawable
|
||||
"2" -> subjectLayout.background = eventDrawable
|
||||
else -> break
|
||||
}
|
||||
}*/
|
||||
|
||||
// Return true to continue with the drawing, or false to cancel
|
||||
return true
|
||||
}
|
||||
@@ -319,6 +365,11 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
resources.getDimensionPixelSize(R.dimen.cal_week_separator_height) // Specify separator height in resources
|
||||
)
|
||||
val dayEndSeparator2 = Space(requireContext())
|
||||
dayEndSeparator2.layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
resources.getDimensionPixelSize(R.dimen.cal_week_separator_height) // Specify separator height in resources
|
||||
)
|
||||
|
||||
val endParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
@@ -330,6 +381,7 @@ class DayFragment(private val position: Int) : Fragment(R.layout.fragment_day) {
|
||||
if (day.subjects[0].substitute != "2") {
|
||||
dayLayout.addView(dayEndSeparator)
|
||||
dayLayout.addView(dayEndTextView)
|
||||
dayLayout.addView(dayEndSeparator2)
|
||||
}
|
||||
|
||||
scrollView.addView(dayLayout)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.odweta.solen
|
||||
|
||||
import android.R.attr.maxHeight
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.drawable.AnimatedImageDrawable
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.View.MeasureSpec
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
@@ -27,6 +28,7 @@ import java.nio.charset.Charset
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
companion object {
|
||||
val dayMap = mutableMapOf<Int, Day>()
|
||||
@@ -50,14 +52,12 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
|
||||
private suspend fun setupAPI() {
|
||||
return withContext(Dispatchers.IO) {
|
||||
//Log.d("debug", "setting up API...")
|
||||
token = JSONObject(getToken()).get("access_token").toString()
|
||||
if (token == "") {
|
||||
return@withContext
|
||||
}
|
||||
userData = getUserDataJSON()
|
||||
studentId = getStudentId()
|
||||
//Log.d("debug", "API set up!")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,14 +137,11 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
password = acc.password
|
||||
|
||||
val token = getToken()
|
||||
//Log.d("debug", "token: '$token'")
|
||||
!JSONObject(token).has("error")
|
||||
}
|
||||
}
|
||||
|
||||
private fun onSignIn() {
|
||||
//Log.d("debug", "onSignIn called!")
|
||||
|
||||
val acc = Account(
|
||||
findViewById<EditText>(R.id.usernameField).text.toString(),
|
||||
findViewById<EditText>(R.id.passwordField).text.toString(),
|
||||
@@ -157,9 +154,6 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
|
||||
lifecycleScope.launch {
|
||||
val valid = accountIsValid(acc)
|
||||
//Log.d("debug", "account valid? $valid")
|
||||
//Log.d("debug", acc.username)
|
||||
//Log.d("debug", acc.password)
|
||||
|
||||
if (valid) {
|
||||
launch()
|
||||
@@ -171,7 +165,6 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
//Log.d("debug", "onSignIn finished!")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +216,6 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
file.createNewFile()
|
||||
false
|
||||
} else {
|
||||
//Log.d("debug", "account file found")
|
||||
// it exists, so it shall be parsed
|
||||
val acc: Account = parseAccountDataFile(file)
|
||||
username = acc.username
|
||||
@@ -257,7 +249,6 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
private fun launchPhase2(week: List<Day>) {
|
||||
days = week
|
||||
for ((i, day) in week.withIndex()) {
|
||||
//Log.d("debug", "$i, ${day.name}\n${day.date}\n${day.subjects}")
|
||||
dayMap[i] = day
|
||||
}
|
||||
|
||||
@@ -282,17 +273,12 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
*/
|
||||
|
||||
val accSaved: Boolean = haveSavedAccount()
|
||||
//val valid: Boolean = accountIsValid(Account(username, password, 0))
|
||||
|
||||
//Log.d("debug", "username: $username")
|
||||
//Log.d("debug", "password: $password")
|
||||
//Log.d("debug", "saved? $accSaved")//; valid? $valid")
|
||||
|
||||
if (!accSaved) {
|
||||
//Log.d("debug", "showing sign in screen")
|
||||
// show the sign in screen
|
||||
showSignInScreen()
|
||||
} else {
|
||||
//Log.d("debug", "launching timetable")
|
||||
// launch!
|
||||
launchPhase1()
|
||||
}
|
||||
}
|
||||
@@ -348,7 +334,6 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
try {
|
||||
val resp = client.newCall(request).execute()
|
||||
val respString = resp.body?.string().toString()
|
||||
//Log.d("debug", "userData: $respString")
|
||||
respString
|
||||
} catch (e: IOException) {
|
||||
"""{"error": "network"}"""
|
||||
@@ -362,18 +347,12 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
}
|
||||
|
||||
private suspend fun getTimeTableJSON(): String {
|
||||
// I now figured out how to use the SOL API (kinda), yay
|
||||
|
||||
//Log.d("debug", "getting timetable")
|
||||
|
||||
return withContext(Dispatchers.IO) {
|
||||
val userIsParent = userIsParent()
|
||||
//Log.d("debug", "userIsParent? $userIsParent")
|
||||
var url = timeTableUrl
|
||||
if (userIsParent) {
|
||||
url += "?studentId=$studentId"
|
||||
}
|
||||
//Log.d("debug", "url: $url")
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@@ -384,9 +363,7 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
|
||||
try {
|
||||
val resp = client.newCall(request).execute()
|
||||
val respString = resp.body?.string().toString()
|
||||
//Log.d("debug", "timetable: $respString")
|
||||
respString
|
||||
resp.body?.string().toString()
|
||||
} catch (e: IOException) {
|
||||
"""{"error": "network"}"""
|
||||
}
|
||||
@@ -405,15 +382,12 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
val week = mutableListOf<Day>()
|
||||
|
||||
if (jsonObject.has("error")) {
|
||||
//Log.d("debug error", "network")
|
||||
return week
|
||||
}
|
||||
//Log.d("debug", "no network error\n\n$jsonString")
|
||||
|
||||
// Access the "body" array from the main JSON object
|
||||
val bodyArray = jsonObject.getJSONArray("days")
|
||||
|
||||
|
||||
// Convert the JSON array to a list of JSON objects
|
||||
val jsonObjectList = mutableListOf<JSONObject>()
|
||||
for (i in 0 until bodyArray.length()) {
|
||||
@@ -422,6 +396,7 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
}
|
||||
|
||||
for (obj in jsonObjectList) {
|
||||
// for each day
|
||||
val dateRAW = obj.get("date").toString()
|
||||
var dayStr = dateRAW.split("T")[0].split("-")[2]
|
||||
var monthStr = dateRAW.split("T")[0].split("-")[1]
|
||||
@@ -455,13 +430,17 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
}
|
||||
|
||||
for (subj in subjectJSONList) {
|
||||
// for each subject in one particular day
|
||||
val subject = Subject()
|
||||
val kind = subj.getJSONObject("hourKind").get("id")
|
||||
val type = subj.getJSONObject("hourType").get("id")
|
||||
|
||||
if (
|
||||
(subj.getJSONObject("hourType").get("id") == "SUPLOVANA") ||
|
||||
(kind != "SUPLOVANI" && kind != "")
|
||||
(type == "SUPLOVANA") ||
|
||||
(type != "SUPLOVANI" && type != "ROZVRH")
|
||||
) {
|
||||
if (kind == "ZRUSENI_VYUKY_ROZVRH") {
|
||||
when (kind) {
|
||||
"ZRUSENI_VYUKY_ROZVRH" -> {
|
||||
subject.name = subj.get("title").toString()
|
||||
subject.place = ""
|
||||
subject.teacher = ""
|
||||
@@ -476,29 +455,20 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
|
||||
subjects.add(subject)
|
||||
}
|
||||
continue
|
||||
}
|
||||
//Log.d("debug", subj.toString())
|
||||
"S_NAHRADOU_SKOL_AKCE" -> {
|
||||
subject.name = subj.get("title").toString()
|
||||
subject.place = ""
|
||||
subject.teacher = ""
|
||||
subject.substitute = "2" // 2 means school event
|
||||
|
||||
subject.name = subj.getJSONObject("subject").get("abbrev").toString()
|
||||
subject.place = subj.getJSONArray("rooms").getJSONObject(0).get("abbrev").toString()
|
||||
subject.teacher = "" +
|
||||
"${subj.getJSONArray("teachers").getJSONObject(0).get("name")} " +
|
||||
"${subj.getJSONArray("teachers").getJSONObject(0).get("surname")}"
|
||||
if (subj.getJSONObject("hourType").get("id").toString() == "ROZVRH") {
|
||||
subject.substitute = "0"
|
||||
} else if (subj.getJSONObject("hourType").get("id").toString() == "SUPLOVANI") {
|
||||
subject.substitute = "1"
|
||||
}
|
||||
val hourspan = subj.getJSONArray("detailHours").length()
|
||||
if (hourspan == 1) {
|
||||
val detailHours = subj.getJSONArray("detailHours")
|
||||
subject.number = detailHours.getJSONObject(0).get("id").toString()
|
||||
subject.start = detailHours.getJSONObject(0).get("timeFrom").toString()
|
||||
subject.start = subject.start.slice(0..subject.start.length-4)
|
||||
subject.start = subject.start.slice(0..subject.start.length - 4)
|
||||
subject.end = detailHours.getJSONObject(0).get("timeto").toString()
|
||||
subject.end = subject.end.slice(0..subject.end.length-4)
|
||||
//Log.d("push", "pushing day...")
|
||||
subject.end = subject.end.slice(0..subject.end.length - 4)
|
||||
subjects.add(subject)
|
||||
} else {
|
||||
for (i in 0..<hourspan) {
|
||||
@@ -510,18 +480,63 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
|
||||
|
||||
val detailHours = subj.getJSONArray("detailHours")
|
||||
newSubject.number = detailHours.getJSONObject(i).get("id").toString()
|
||||
//Log.d("debug", "${date}\n\n$detailHours\n\n${subject.number}")
|
||||
newSubject.start = detailHours.getJSONObject(i).get("timeFrom").toString()
|
||||
newSubject.start = newSubject.start.slice(0..newSubject.start.length-4)
|
||||
newSubject.start =
|
||||
detailHours.getJSONObject(i).get("timeFrom").toString()
|
||||
newSubject.start =
|
||||
newSubject.start.slice(0..newSubject.start.length - 4)
|
||||
newSubject.end = detailHours.getJSONObject(i).get("timeto").toString()
|
||||
newSubject.end = newSubject.end.slice(0..newSubject.end.length-4)
|
||||
//Log.d("push", "pushing day...")
|
||||
newSubject.end = newSubject.end.slice(0..newSubject.end.length - 4)
|
||||
subjects.add(newSubject)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
subject.name = subj.getJSONObject("subject").get("abbrev").toString()
|
||||
subject.place =
|
||||
subj.getJSONArray("rooms").getJSONObject(0).get("abbrev").toString()
|
||||
subject.teacher = "" +
|
||||
"${subj.getJSONArray("teachers").getJSONObject(0).get("name")} " +
|
||||
"${subj.getJSONArray("teachers").getJSONObject(0).get("surname")}"
|
||||
if (type == "ROZVRH") {
|
||||
subject.substitute = "0"
|
||||
} else if (type == "SUPLOVANI") {
|
||||
subject.substitute = "1"
|
||||
}
|
||||
val hourspan = subj.getJSONArray("detailHours").length()
|
||||
if (hourspan == 1) {
|
||||
val detailHours = subj.getJSONArray("detailHours")
|
||||
subject.number = detailHours.getJSONObject(0).get("id").toString()
|
||||
subject.start = detailHours.getJSONObject(0).get("timeFrom").toString()
|
||||
subject.start = subject.start.slice(0..subject.start.length - 4)
|
||||
subject.end = detailHours.getJSONObject(0).get("timeto").toString()
|
||||
subject.end = subject.end.slice(0..subject.end.length - 4)
|
||||
subjects.add(subject)
|
||||
} else {
|
||||
for (i in 0..<hourspan) {
|
||||
val newSubject = Subject()
|
||||
newSubject.name = subject.name
|
||||
newSubject.place = subject.place
|
||||
newSubject.teacher = subject.teacher
|
||||
newSubject.substitute = subject.substitute
|
||||
|
||||
val detailHours = subj.getJSONArray("detailHours")
|
||||
newSubject.number = detailHours.getJSONObject(i).get("id").toString()
|
||||
newSubject.start =
|
||||
detailHours.getJSONObject(i).get("timeFrom").toString()
|
||||
newSubject.start =
|
||||
newSubject.start.slice(0..newSubject.start.length - 4)
|
||||
newSubject.end = detailHours.getJSONObject(i).get("timeto").toString()
|
||||
newSubject.end = newSubject.end.slice(0..newSubject.end.length - 4)
|
||||
subjects.add(newSubject)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// rust pseudocode
|
||||
|
||||
let mut res: Vec<i32> = vec![];
|
||||
for i in 0..v.len()-1 {
|
||||
if v[i] == v[i+1]-1 {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/Theme.Solen.PopupOverlay"
|
||||
app:theme="@style/Theme.Solen.AppBarOverlay">
|
||||
android:theme="@style/Theme.Solen.AppBarOverlay">
|
||||
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
<color name="teal_700">#FFF6F1EE</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="cal_week_bg">#696969</color>
|
||||
<color name="cal_week_subject">#f1f1f1</color>
|
||||
|
||||
<color name="cal_week_bg">#FF696969</color>
|
||||
<color name="cal_week_subject">#FFF1F1F1</color>
|
||||
<color name="cal_week_substitute">#FFDD2200</color>
|
||||
<color name="cal_week_event">#FFFDAA22</color>
|
||||
<color name="cal_week_free">#FFAAFF66</color>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user