Skip to content

Commit

Permalink
Refactor score page (Only score parts) (#157)
Browse files Browse the repository at this point in the history
* feat: rewrite score tile widget

* feat: extract & rewrite the section of course score

* feat: add i18n text for key of class and department

* refactor: define highlight color for origin divider color

* feat: add metrics title widget

* feat: add grade metrics cell widget

* feat: rewrite semester score section to new metrics style

* feat: rewrite two rank sections to new metrics style

* refactor: rename widget

* fix: incorrect theme divider color use

* feat: rewrite warning widget and extract from score page

* refactor: use refactored widgets to tidy up the score page, and seperate appbar buttons to two

* fix: i10n key typo

* refactor: use getter to generate sub widgets while it is not depend on any params for building

* refactor: seperate appbar action buttons into isolate widget and wrap buttons with tooltip
  • Loading branch information
Xanonymous-GitHub authored Jan 4, 2023
1 parent 9683d3d commit 8f7cae4
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 451 deletions.
4 changes: 3 additions & 1 deletion lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class MessageLookup extends MessageLookupByLibrary {
"isNewVersion": MessageLookupByLibrary.simpleMessage("Already the latest version"),
"isVideo": MessageLookupByLibrary.simpleMessage("Is a video"),
"jointElective": MessageLookupByLibrary.simpleMessage("Joint elective"),
"kClass": MessageLookupByLibrary.simpleMessage("class"),
"kDepartment": MessageLookupByLibrary.simpleMessage("department"),
"languageSetting": MessageLookupByLibrary.simpleMessage("Language"),
"languageSwitch": MessageLookupByLibrary.simpleMessage("Use English interface"),
"loadFavorite": MessageLookupByLibrary.simpleMessage("Load favorite"),
Expand Down Expand Up @@ -232,7 +234,7 @@ class MessageLookup extends MessageLookupByLibrary {
"ruleDimension": MessageLookupByLibrary.simpleMessage("Rule of law"),
"sameOldPassword": MessageLookupByLibrary.simpleMessage("Same password as before"),
"save": MessageLookupByLibrary.simpleMessage("Save"),
"scoreCalculationWarring": MessageLookupByLibrary.simpleMessage(
"scoreCalculationWarning": MessageLookupByLibrary.simpleMessage(
"This calculation is for reference only. Actually, please focus on the school."),
"scoreSearch": MessageLookupByLibrary.simpleMessage("Score query"),
"search": MessageLookupByLibrary.simpleMessage("Search"),
Expand Down
4 changes: 3 additions & 1 deletion lib/generated/intl/messages_zh_TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class MessageLookup extends MessageLookupByLibrary {
"isNewVersion": MessageLookupByLibrary.simpleMessage("已經是最新版本了"),
"isVideo": MessageLookupByLibrary.simpleMessage("上課錄影"),
"jointElective": MessageLookupByLibrary.simpleMessage("共同選修"),
"kClass": MessageLookupByLibrary.simpleMessage("班級"),
"kDepartment": MessageLookupByLibrary.simpleMessage("系所"),
"languageSetting": MessageLookupByLibrary.simpleMessage("語言"),
"languageSwitch": MessageLookupByLibrary.simpleMessage("使用英文介面"),
"loadFavorite": MessageLookupByLibrary.simpleMessage("載入常用課表"),
Expand Down Expand Up @@ -224,7 +226,7 @@ class MessageLookup extends MessageLookupByLibrary {
"ruleDimension": MessageLookupByLibrary.simpleMessage("法治向度"),
"sameOldPassword": MessageLookupByLibrary.simpleMessage("不可以與之前密碼相同"),
"save": MessageLookupByLibrary.simpleMessage("儲存"),
"scoreCalculationWarring": MessageLookupByLibrary.simpleMessage("此計算僅供參考,實際請以學校為主"),
"scoreCalculationWarning": MessageLookupByLibrary.simpleMessage("此計算僅供參考,實際請以學校為主"),
"scoreSearch": MessageLookupByLibrary.simpleMessage("分數查詢"),
"search": MessageLookupByLibrary.simpleMessage("搜尋"),
"searchCredit": MessageLookupByLibrary.simpleMessage("查詢學分"),
Expand Down
24 changes: 22 additions & 2 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"takeSelect": "Take select",
"takeForeignDepartmentCredits": "Foreign Department Credits",
"takeForeignDepartmentCreditsLimit": "Credit limit",
"scoreCalculationWarring": "This calculation is for reference only. Actually, please focus on the school.",
"scoreCalculationWarning": "This calculation is for reference only. Actually, please focus on the school.",
"resultsOfVariousSubjects": "Results of various subjects",
"semesterGrades": "Semester grades",
"totalAverage": "Total average",
Expand Down Expand Up @@ -251,5 +251,7 @@
"zuvioAutoRollCallFeatureReleaseNotice": "Zuvio's (auto) roll-call reminder is coming soon!",
"comingSoon": "Coming Soon!",
"androidPrivateBrowseGuideTitle": "About Incognito Browse",
"androidPrivateBrowseGuideSubTitle": "Open Incognito browsing to enhanced security"
"androidPrivateBrowseGuideSubTitle": "Open Incognito browsing to enhanced security",
"kClass": "class",
"kDepartment": "department"
}
6 changes: 4 additions & 2 deletions lib/l10n/intl_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"takeSelect": "實得選修",
"takeForeignDepartmentCredits": "外系學分",
"takeForeignDepartmentCreditsLimit": "學分上限",
"scoreCalculationWarring": "此計算僅供參考,實際請以學校為主",
"scoreCalculationWarning": "此計算僅供參考,實際請以學校為主",
"resultsOfVariousSubjects": "各科成績",
"semesterGrades": "學期成績",
"totalAverage": "總平均",
Expand Down Expand Up @@ -251,5 +251,7 @@
"zuvioAutoRollCallFeatureReleaseNotice": "Zuvio (自動)點名提醒的功能即將上線\n敬請期待!",
"comingSoon": "即將上線!",
"androidPrivateBrowseGuideTitle": "關於隱私瀏覽",
"androidPrivateBrowseGuideSubTitle": "開啟隱私瀏覽,安全更有保障"
"androidPrivateBrowseGuideSubTitle": "開啟隱私瀏覽,安全更有保障",
"kClass": "班級",
"kDepartment": "系所"
}
4 changes: 1 addition & 3 deletions lib/src/config/app_colors.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: remove sdk version selector after migrating to null-safety.
// @dart=2.10
import 'package:flutter/material.dart';

class AppColors {
Expand All @@ -9,7 +7,7 @@ class AppColors {
// font color
static const Color darkFontColor = Colors.black87;
static const Color lightFontColor = Colors.white;
static final Color greyFontColor = Colors.grey[700];
static final Color greyFontColor = Colors.grey[700]!;

//Colors for theme
static Color lightPrimary = Colors.white;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/config/app_themes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: remove sdk version selector after migrating to null-safety.
// @dart=2.10
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/src/config/app_colors.dart';
Expand All @@ -15,7 +13,8 @@ class AppThemes {
appBarTheme: const AppBarTheme(
color: Colors.blueAccent,
),
dividerColor: const Color(0xFFF8F8F8),
dividerColor: const Color(0xFF2F2F2F),
highlightColor: const Color(0xFFF8F8F8),
scaffoldBackgroundColor: AppColors.lightBG,
cupertinoOverrideTheme: const CupertinoThemeData(
primaryColor: AppColors.mainColor,
Expand All @@ -32,7 +31,8 @@ class AppThemes {
primaryColor: AppColors.darkPrimary,
scaffoldBackgroundColor: AppColors.darkBG,
toggleableActiveColor: Colors.blueAccent,
dividerColor: const Color(0xFF2F2F2F),
dividerColor: const Color(0xFFF8F8F8),
highlightColor: const Color(0xFF2F2F2F),
appBarTheme: const AppBarTheme(
color: Colors.black26,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/coursedetail/screen/course_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class _CourseInfoPageState extends State<CourseInfoPage> with AutomaticKeepAlive
}

Widget _buildClassmateInfo(int index, ClassmateJson classmate) {
final color = (index % 2 == 1) ? Theme.of(context).backgroundColor : Theme.of(context).dividerColor;
final color = (index % 2 == 1) ? Theme.of(context).backgroundColor : Theme.of(context).highlightColor;
return Container(
decoration: BoxDecoration(
color: color,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/coursetable/course_table_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class _CourseTablePageState extends State<CourseTablePage> {

Widget _buildCourseTable(int index) {
final section = courseTableControl.getSectionIntList[index];
final color = ((index % 2 == 1) ? Theme.of(context).backgroundColor : Theme.of(context).dividerColor)
final color = ((index % 2 == 1) ? Theme.of(context).backgroundColor : Theme.of(context).highlightColor)
.withAlpha(courseTableWithAlpha);
final List<Widget> widgetList = [];
widgetList.add(
Expand Down
38 changes: 38 additions & 0 deletions lib/ui/pages/score/app_bar_action_buttons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:flutter_app/src/r.dart';

class ScorePageAppBarActionButtons extends StatelessWidget {
const ScorePageAppBarActionButtons({
super.key,
required VoidCallback onRefreshPressed,
required VoidCallback onCalculateCreditPressed,
}) : _onRefreshPressed = onRefreshPressed,
_onCalculateCreditPressed = onCalculateCreditPressed;

final VoidCallback _onRefreshPressed;
final VoidCallback _onCalculateCreditPressed;

Widget get _refreshButton => Tooltip(
message: R.current.refresh,
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: _onRefreshPressed,
),
);

Widget get _calculateCreditButton => Tooltip(
message: R.current.calculationCredit,
child: IconButton(
icon: const Icon(Icons.calculate),
onPressed: _onCalculateCreditPressed,
),
);

@override
Widget build(BuildContext context) => Row(
children: [
_refreshButton,
_calculateCreditButton,
],
);
}
44 changes: 44 additions & 0 deletions lib/ui/pages/score/course_score_section.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ignore_for_file: import_of_legacy_library_into_null_safe

import 'package:flutter/material.dart';
import 'package:flutter_app/src/model/course/course_score_json.dart';
import 'package:flutter_app/src/r.dart';
import 'package:flutter_app/ui/pages/score/widgets/score_tile_widget.dart';
import 'package:flutter_app/ui/pages/score/widgets/metrics_title_widget.dart';

class CourseScoreSection extends StatelessWidget {
const CourseScoreSection({
super.key,
required List<CourseScoreInfoJson> scoreInfoList,
}) : _scoreInfoList = scoreInfoList;

final List<CourseScoreInfoJson> _scoreInfoList;

void _onCategoryChanged(int? category) {
// TODO(TU): implement this method in view model or controller.
}

@override
Widget build(BuildContext context) => Column(
children: [
MetricsTitle(title: R.current.resultsOfVariousSubjects),
ListView.builder(
shrinkWrap: true,
itemCount: _scoreInfoList.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (_, index) {
final scoreInfo = _scoreInfoList[index];
return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: ScoreTile(
courseName: scoreInfo.name,
category: scoreInfo.category,
scoreValue: scoreInfo.score,
onCategoryChanged: _onCategoryChanged,
),
);
},
),
],
);
}
64 changes: 64 additions & 0 deletions lib/ui/pages/score/rank_grade_metrics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ignore_for_file: import_of_legacy_library_into_null_safe

import 'package:flutter/material.dart';
import 'package:flutter_app/src/model/course/course_score_json.dart';
import 'package:flutter_app/src/r.dart';
import 'package:flutter_app/ui/pages/score/widgets/grade_metrics_cell_widget.dart';
import 'package:flutter_app/ui/pages/score/widgets/metrics_title_widget.dart';

class RankGradeMetrics extends StatelessWidget {
const RankGradeMetrics({
super.key,
required String title,
required RankJson rankInfo,
}) : _title = title,
_rankInfo = rankInfo;

final String _title;
final RankJson _rankInfo;

Widget _buildSingleRankMetric(String categoryName, RankItemJson rankInfo) => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Text(
'($categoryName)',
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GradeMetricsCell(
name: R.current.rank,
value: '${rankInfo.rank.toInt()} / ${rankInfo.total.toInt()}',
),
GradeMetricsCell(
name: R.current.percentage,
value: '${rankInfo.percentage.toStringAsFixed(1)}%',
),
],
),
],
);

@override
Widget build(BuildContext context) {
final classRankInfo = _rankInfo.course;
final departmentRankInfo = _rankInfo.department;

return Column(
children: [
MetricsTitle(title: _title),
_buildSingleRankMetric(R.current.kClass, classRankInfo),
_buildSingleRankMetric(R.current.kDepartment, departmentRankInfo),
],
);
}
}
Loading

0 comments on commit 8f7cae4

Please sign in to comment.