From 7f0aea29cdd0a8f88e0ff6c1da7c65ab87dbbff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Thu, 2 Apr 2020 12:56:24 +0200 Subject: [PATCH] [API/Librus] Fix HTML to string conversion in homework. Add force download homework button in debug mode. --- app/build.gradle | 2 + .../java/pl/szczodrzynski/edziennik/App.kt | 2 +- .../szczodrzynski/edziennik/MainActivity.kt | 2 +- .../synergia/LibrusSynergiaGetHomework.kt | 3 +- .../ui/dialogs/event/EventDetailsDialog.kt | 7 +++ .../dialogs/timetable/LessonDetailsDialog.kt | 2 +- .../ui/modules/error/ErrorDetailsDialog.kt | 2 +- .../edziennik/ui/modules/grades/GradeView.kt | 25 ++++----- .../modules/settings/SettingsNewFragment.java | 2 +- .../main/res/layout/dialog_event_details.xml | 53 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 11 files changed, 64 insertions(+), 37 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 21392ed3..06caeb83 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -196,6 +196,8 @@ dependencies { implementation project(":annotation") kapt project(":codegen") + + implementation 'com.google.android:flexbox:2.0.1' } repositories { mavenCentral() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt index 59db1ab2..b3772fd9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.kt @@ -168,7 +168,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope { db.profileDao().firstId?.let { profileLoadById(it) } } - devMode = "f054761fbdb6a238" == deviceId || BuildConfig.DEBUG + devMode = BuildConfig.DEBUG Signing.getCert(this) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index 6abe7be6..47a951fd 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -518,7 +518,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope { .withIcon(CommunityMaterial.Icon2.cmd_help_circle_outline) .withOnClickListener(View.OnClickListener { loadTarget(TARGET_FEEDBACK) }) ) - if (App.devMode) { + if (App.debugMode) { bottomSheet += BottomSheetPrimaryItem(false) .withTitle(R.string.menu_debug) .withIcon(CommunityMaterial.Icon.cmd_android_studio) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt index 32729a7e..379bd42d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt @@ -1,5 +1,6 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia +import android.text.Html import org.greenrobot.eventbus.EventBus import org.jsoup.Jsoup import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus @@ -22,7 +23,7 @@ class LibrusSynergiaGetHomework(override val data: DataLibrus, val table = doc.select("table.decorated tbody > tr") event.topic = table[1].select("td")[1].text() - event.homeworkBody = table[5].select("td")[1].text() + event.homeworkBody = Html.fromHtml(table[5].select("td")[1].html()).toString() event.attachmentIds = mutableListOf() event.attachmentNames = mutableListOf() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt index 6bda72e2..83df5e77 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt @@ -192,6 +192,13 @@ class EventDetailsDialog( } b.goToTimetableButton.attachToastHint(R.string.hint_go_to_timetable) + // RE-DOWNLOAD + b.downloadButton.isVisible = App.debugMode + b.downloadButton.onClick { + EdziennikTask.eventGet(event.profileId, event).enqueue(activity) + } + b.downloadButton.attachToastHint(R.string.hint_download_again) + b.topic.text = event.topic BetterLink.attach(b.topic) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/timetable/LessonDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/timetable/LessonDetailsDialog.kt index 2957f593..51b0eb03 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/timetable/LessonDetailsDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/timetable/LessonDetailsDialog.kt @@ -78,7 +78,7 @@ class LessonDetailsDialog( ) } - if (App.devMode) + if (App.debugMode) b.lessonId.visibility = View.VISIBLE update() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/error/ErrorDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/error/ErrorDetailsDialog.kt index 32ec46b9..36a64a3e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/error/ErrorDetailsDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/error/ErrorDetailsDialog.kt @@ -45,7 +45,7 @@ class ErrorDetailsDialog( listOf( it.getStringReason(activity).asBoldSpannable().asColoredSpannable(R.attr.colorOnBackground.resolveAttr(activity)), activity.getString(R.string.error_unknown_format, it.errorCode, it.tag), - if (App.devMode) + if (App.debugMode) it.throwable?.stackTraceString ?: it.throwable?.localizedMessage else it.throwable?.localizedMessage diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradeView.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradeView.kt index 334ff238..b80ad2ac 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradeView.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradeView.kt @@ -49,28 +49,29 @@ class GradeView : AppCompatTextView { val gradeColor = manager.getGradeColor(grade) - text = if (periodGradesTextual) - when (grade.type) { + text = when { + periodGradesTextual -> when (grade.type) { TYPE_SEMESTER1_PROPOSED, TYPE_SEMESTER2_PROPOSED -> context.getString( - R.string.grade_semester_proposed_format, - gradeName + R.string.grade_semester_proposed_format, + gradeName ) TYPE_SEMESTER1_FINAL, TYPE_SEMESTER2_FINAL -> context.getString( - R.string.grade_semester_final_format, - gradeName + R.string.grade_semester_final_format, + gradeName ) TYPE_YEAR_PROPOSED -> context.getString( - R.string.grade_year_proposed_format, - gradeName + R.string.grade_year_proposed_format, + gradeName ) TYPE_YEAR_FINAL -> context.getString( - R.string.grade_year_final_format, - gradeName + R.string.grade_year_final_format, + gradeName ) else -> gradeName } - else - gradeName + gradeName.isBlank() -> " " + else -> gradeName + } setTextColor(when (grade.type) { TYPE_SEMESTER1_PROPOSED, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index 7aaa7f3a..cc72c46c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -1217,7 +1217,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) .build());*/ - if (App.Companion.getDevMode()) { + if (App.Companion.getDebugMode()) { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_crash_text) .subText(R.string.settings_about_crash_subtext) diff --git a/app/src/main/res/layout/dialog_event_details.xml b/app/src/main/res/layout/dialog_event_details.xml index d31565ef..11f57902 100644 --- a/app/src/main/res/layout/dialog_event_details.xml +++ b/app/src/main/res/layout/dialog_event_details.xml @@ -4,10 +4,14 @@ --> + xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto"> + @@ -196,57 +200,68 @@ android:layout_marginTop="8dp" android:background="@drawable/divider"/> - + app:flexWrap="wrap" + app:justifyContent="flex_end"> + android:textSize="20sp" /> + android:textSize="20sp" /> + android:textSize="20sp" /> - + android:textSize="20sp" /> + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index efbdd875..6281da7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1285,4 +1285,5 @@ Czy chcesz oznaczyć to zadanie jako wykonane?\n\nNie będzie ono się wyświetlać na stronie głównej oraz w aktualnych zadaniach domowych. Będzie wciąż dostępne w Terminarzu. Treść Załączniki + Pobierz ponownie