grades: join code and category together

This commit is contained in:
Franek 2024-06-14 18:25:16 +02:00
parent 567dd8e6a2
commit 92ef6b211d
No known key found for this signature in database
GPG Key ID: 0329F871B2079351
21 changed files with 39 additions and 97 deletions

View File

@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 100,
"identityHash": "26b54e8e64642eb693587f983aaf3adc",
"identityHash": "4c141460d807d32d00faad4fb3c12522",
"entities": [
{
"tableName": "grades",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profileId` INTEGER NOT NULL, `gradeId` INTEGER NOT NULL, `gradeName` TEXT NOT NULL, `gradeType` INTEGER NOT NULL, `gradeValue` REAL NOT NULL, `gradeWeight` REAL NOT NULL, `gradeColor` INTEGER NOT NULL, `code` TEXT, `gradeCategory` TEXT, `gradeDescription` TEXT, `gradeComment` TEXT, `gradeSemester` INTEGER NOT NULL, `teacherId` INTEGER NOT NULL, `subjectId` INTEGER NOT NULL, `addedDate` INTEGER NOT NULL, `gradeValueMax` REAL, `gradeClassAverage` REAL, `gradeParentId` INTEGER, `gradeIsImprovement` INTEGER NOT NULL, `keep` INTEGER NOT NULL, PRIMARY KEY(`profileId`, `gradeId`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profileId` INTEGER NOT NULL, `gradeId` INTEGER NOT NULL, `gradeName` TEXT NOT NULL, `gradeType` INTEGER NOT NULL, `gradeValue` REAL NOT NULL, `gradeWeight` REAL NOT NULL, `gradeColor` INTEGER NOT NULL, `gradeCategory` TEXT, `gradeDescription` TEXT, `gradeComment` TEXT, `gradeSemester` INTEGER NOT NULL, `teacherId` INTEGER NOT NULL, `subjectId` INTEGER NOT NULL, `addedDate` INTEGER NOT NULL, `gradeValueMax` REAL, `gradeClassAverage` REAL, `gradeParentId` INTEGER, `gradeIsImprovement` INTEGER NOT NULL, `keep` INTEGER NOT NULL, PRIMARY KEY(`profileId`, `gradeId`))",
"fields": [
{
"fieldPath": "profileId",
@ -50,12 +50,6 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "code",
"columnName": "code",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "category",
"columnName": "gradeCategory",
@ -2320,7 +2314,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '26b54e8e64642eb693587f983aaf3adc')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '4c141460d807d32d00faad4fb3c12522')"
]
}
}

View File

@ -58,8 +58,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
semester = 1,
teacherId = -1,
subjectId = 1,
addedDate = profile.getSemesterStart(1).inMillis,
code = null
addedDate = profile.getSemesterStart(1).inMillis
)
data.gradeList.add(semester1StartGradeObject)
@ -87,8 +86,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
semester = 2,
teacherId = -1,
subjectId = 1,
addedDate = profile.getSemesterStart(2).inMillis,
code = null
addedDate = profile.getSemesterStart(2).inMillis
)
data.gradeList.add(semester2StartGradeObject)
@ -160,8 +158,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
semester = semester,
teacherId = teacherId,
subjectId = 1,
addedDate = addedDate,
code = null
addedDate = addedDate
).apply {
valueMax = valueTo
}

View File

@ -68,8 +68,7 @@ class LibrusApiDescriptiveGrades(override val data: DataLibrus,
semester = semester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
)
data.gradeList.add(gradeObject)

View File

@ -82,8 +82,7 @@ class LibrusApiGrades(override val data: DataLibrus,
semester = semester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
)
grade.getJsonObject("Improvement")?.also {

View File

@ -59,8 +59,7 @@ class LibrusApiPointGrades(override val data: DataLibrus,
semester = semester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
).apply {
valueMax = category?.valueTo ?: 0f
}

View File

@ -63,8 +63,7 @@ class LibrusApiTextGrades(override val data: DataLibrus,
semester = semester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
)
data.gradeList.add(gradeObject)

View File

@ -81,8 +81,7 @@ class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
semester = semester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
)
if (data.profile?.empty == true) {

View File

@ -128,8 +128,7 @@ class MobidziennikWebGrades(override val data: DataMobidziennik,
semester = gradeSemester,
teacherId = teacherId,
subjectId = subjectId,
addedDate = gradeAddedDateMillis,
code = null
addedDate = gradeAddedDateMillis
)
gradeObject.classAverage = gradeClassAverage

View File

@ -57,8 +57,7 @@ class PodlasieApiFinalGrades(val data: DataPodlasie, val rows: List<JsonObject>)
semester = semester,
teacherId = -1,
subjectId = subject.id,
addedDate = addedDate,
code = null
addedDate = addedDate
)
data.gradeList.add(gradeObject)
@ -95,8 +94,7 @@ class PodlasieApiFinalGrades(val data: DataPodlasie, val rows: List<JsonObject>)
semester = semester,
teacherId = -1,
subjectId = subject.id,
addedDate = addedDate,
code = null
addedDate = addedDate
)
data.gradeList.add(proposedGradeObject)

View File

@ -26,8 +26,8 @@ class PodlasieApiGrades(val data: DataPodlasie, val rows: List<JsonObject>) {
val weight = grade.getFloat("Weight") ?: 0f
val includeToAverage = grade.getInt("IncludeToAverage") != 0
val color = grade.getString("Color")?.let { Color.parseColor(it) } ?: -1
val category = grade.getString("Category") ?: ""
val code = grade.getString("Code") ?: ""
val category = grade.getString("Category")
val code = grade.getString("Code")
val comment = grade.getString("Comment") ?: ""
val semester = grade.getString("TermShortcut")?.length ?: data.currentSemester
@ -41,6 +41,12 @@ class PodlasieApiGrades(val data: DataPodlasie, val rows: List<JsonObject>) {
val addedDate = grade.getString("ReceivedDate")?.let { Date.fromY_m_d(it).inMillis }
?: System.currentTimeMillis()
val categoryText: String = when {
code != null && category != null -> "$code - $category"
code != null -> code
else -> category ?: ""
}
val gradeObject = Grade(
profileId = data.profileId,
id = id,
@ -49,14 +55,13 @@ class PodlasieApiGrades(val data: DataPodlasie, val rows: List<JsonObject>) {
value = value,
weight = if (includeToAverage) weight else 0f,
color = color,
category = category,
category = categoryText,
description = null,
comment = comment,
semester = semester,
teacherId = teacher.id,
subjectId = subject.id,
addedDate = addedDate,
code = code
addedDate = addedDate
)
data.gradeList.add(gradeObject)

View File

@ -66,8 +66,7 @@ class VulcanHebeGradeSummary(
semester = data.studentSemesterNumber,
teacherId = -1,
subjectId = subjectId,
addedDate = addedDate,
code = null
addedDate = addedDate
)
data.gradeList.add(gradeObject)

View File

@ -91,6 +91,12 @@ class VulcanHebeGrades(
else
columnColor
val categoryFormattedText: String = when {
code != null && category != null -> "$code - $categoryText"
code != null -> code
else -> categoryText ?: ""
}
val gradeObject = Grade(
profileId = profileId,
id = id,
@ -99,8 +105,7 @@ class VulcanHebeGrades(
value = value ?: 0.0f,
weight = weight,
color = color,
category = categoryText,
code = code,
category = categoryFormattedText,
description = finalDescription,
comment = null,
semester = getSemester(column),

View File

@ -44,7 +44,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
TimetableManual::class,
Note::class,
Metadata::class
], version = 101)
], version = 100)
@TypeConverters(
ConverterTime::class,
ConverterDate::class,
@ -188,8 +188,7 @@ abstract class AppDb : RoomDatabase() {
Migration97(),
Migration98(),
Migration99(),
Migration100(),
Migration101()
Migration100()
).allowMainThreadQueries().build()
}
}

View File

@ -29,12 +29,6 @@ open class Grade(
@ColumnInfo(name = "gradeColor")
var color: Int,
/**
* Applies only for Vulcan (i think)
*/
@ColumnInfo(name = "code")
var code: String?,
@ColumnInfo(name = "gradeCategory")
var category: String?,
@ColumnInfo(name = "gradeDescription")

View File

@ -10,12 +10,12 @@ import pl.szczodrzynski.edziennik.data.db.entity.Noteable
class GradeFull(
profileId: Int, id: Long, name: String, type: Int,
value: Float, weight: Float, color: Int, code: String?,
value: Float, weight: Float, color: Int,
category: String?, description: String?, comment: String?,
semester: Int, teacherId: Long, subjectId: Long, addedDate: Long = System.currentTimeMillis()
) : Grade(
profileId, id, name, type,
value, weight, color, code,
value, weight, color,
category, description, comment,
semester, teacherId, subjectId, addedDate
), Noteable {

View File

@ -1,15 +0,0 @@
/*
* Copyright (c) Kuba Szczodrzyński 2022-10-25.
* Copyright (c) Franciszek Pilch 2024-06-14.
*/
package pl.szczodrzynski.edziennik.data.db.migration
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
class Migration101 : Migration(100, 101) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE grades ADD COLUMN code TEXT DEFAULT NULL;")
}
}

View File

@ -30,11 +30,6 @@ class GradeViewHolder(
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
override fun onBind(activity: AppCompatActivity, app: App, grade: GradeFull, position: Int, adapter: GradesAdapter) {
val manager = app.gradesManager
val gradeCategoryText: String = when {
grade.category != null && grade.code != null -> "${grade.code} - ${grade.category}"
grade.code != null -> grade.code!!
else -> grade.category!!
}
b.gradeName.setGrade(grade, manager, bigView = true)
@ -45,15 +40,15 @@ class GradeViewHolder(
if (grade.isImprovement)
app.getString(R.string.grades_improvement_category_format, "")
else
if (grade.code != null) gradeCategoryText else null
grade.category
} else {
b.gradeDescription.text =
grade.getNoteSubstituteText(adapter.showNotes) ?: grade.description
b.gradeCategory.text =
if (grade.isImprovement)
app.getString(R.string.grades_improvement_category_format, gradeCategoryText)
app.getString(R.string.grades_improvement_category_format, grade.category)
else
gradeCategoryText
grade.category
}
if (adapter.showNotes)

View File

@ -157,23 +157,6 @@
android:textIsSelectable="true"
tools:text="@string/dialog_grade_details_no_category" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/dialog_grade_details_code"
android:textAppearance="@style/NavView.TextView.BodyMedium"
android:textStyle="bold"
android:textColor="?colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="@{Utils.ns(@string/dialog_grade_details_no_code, grade.code)}"
android:textIsSelectable="true"
tools:text="@string/dialog_grade_details_no_code" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -1229,6 +1229,4 @@
<string name="edziennik_progress_endpoint_addressbook">Addressbuch herunterladen…</string>
<string name="settings_ui_lock_layout_text">Sperren des Startbildschirm-Layouts</string>
<string name="settings_ui_lock_layout_subtext">Sie können keine Elemente auf dem Startbildschirm bearbeiten</string>
<string name="dialog_grade_details_code">Notenspaltencode</string>
<string name="dialog_grade_details_no_code">(kein Notenspaltencode)</string>
</resources>

View File

@ -1436,6 +1436,4 @@
<string name="home_timetable_all_lessons">All lessons:</string>
<string name="settings_ui_lock_layout_text">Lock home screen layout</string>
<string name="settings_ui_lock_layout_subtext">You will not be able to edit items on the home screen</string>
<string name="dialog_grade_details_code">Grade column code</string>
<string name="dialog_grade_details_no_code">(no column code)</string>
</resources>

View File

@ -1556,6 +1556,4 @@
<string name="menu_timetable_sync">Odśwież wybrany tydzień</string>
<string name="settings_ui_lock_layout_text">Zablokuj układ ekranu głównego</string>
<string name="settings_ui_lock_layout_subtext">Nie będzie można edytować przedmiotów na ekranie głównym</string>
<string name="dialog_grade_details_code">Kod oceny</string>
<string name="dialog_grade_details_no_code">(brak kodu)</string>
</resources>