Skip to content

Commit

Permalink
Replacing functions for new extension on util
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeMeow1027 committed Dec 9, 2023
1 parent 9a81e1b commit 1982713
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 16 deletions.
23 changes: 8 additions & 15 deletions lib/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ class Account {
// Subject credit
item.credit = int.tryParse(schCell[3].text) ?? 0;
// Subject is high quality
item.isHighQuality =
schCell[5].attributes['class']?.contains('GridCheck') ?? false;
item.isHighQuality = schCell[5].isGridChecked();
// Lecturer
item.lecturerName = schCell[6].text;
// Subject study
Expand All @@ -211,11 +210,10 @@ class Account {
SubjectScheduleStudy subjectStudyItem = SubjectScheduleStudy();
// Day of week
if (element.toUpperCase().contains('CN')) {
subjectStudyItem.dayOfWeek = 0;
subjectStudyItem.dayOfWeek = 1;
} else {
subjectStudyItem.dayOfWeek =
(int.tryParse(element.split(',')[0].split(' ')[1]) ?? 1) -
1;
int.tryParse(element.split(',')[0].split(' ')[1]) ?? 1;
}
// Lesson
subjectStudyItem.lesson = RangeInt(
Expand Down Expand Up @@ -263,9 +261,7 @@ class Account {
// Set group
schItem.subjectExam.group = schCell[3].text;
// Is global
schItem.subjectExam.isGlobal =
schCell[4].attributes['class']?.contains('GridCheck') ??
false;
schItem.subjectExam.isGlobal = schCell[4].isGridChecked();
// Date + room
final temp = schCell[5].text;
// Use above to split date and room, then add back to subject schedule item.
Expand Down Expand Up @@ -358,25 +354,22 @@ class Account {
continue;
}

SubjectFee item = SubjectFee();
SubjectFee item = SubjectFee.createDefault();
// Subject id
item.id = SubjectCode.fromString(input: schCell[1].text);
// Subject name
item.name = schCell[2].text;
// Subject credit
item.credit = int.tryParse(schCell[3].text) ?? 0;
// Subject is high quality
item.isHighQuality =
schCell[4].attributes['class']?.contains('GridCheck') ?? false;
item.isHighQuality = schCell[4].isGridChecked();
// Subject price
item.price =
double.tryParse(schCell[5].text.replaceAll(",", "")) ?? 0;
// Is debt
item.isDebt =
schCell[6].attributes['class']?.contains('GridCheck') ?? false;
item.isDebt = schCell[6].isGridChecked();
// Is restudy
item.isReStudy =
schCell[7].attributes['class']?.contains('GridCheck') ?? false;
item.isReStudy = schCell[7].isGridChecked();
// Payment at
item.confirmedPaymentAt = schCell[8].text;

Expand Down
97 changes: 97 additions & 0 deletions lib/model/account/subject_fee.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import '../subject_code.dart';

class SubjectFee {
Expand All @@ -9,4 +11,99 @@ class SubjectFee {
bool isDebt = false;
bool isReStudy = false;
String? confirmedPaymentAt;

SubjectFee.createDefault();

SubjectFee({
required this.name,
required this.credit,
required this.isHighQuality,
required this.price,
required this.isDebt,
required this.isReStudy,
this.confirmedPaymentAt,
});

SubjectFee copyWith({
String? name,
int? credit,
bool? isHighQuality,
double? price,
bool? isDebt,
bool? isReStudy,
String? confirmedPaymentAt,
}) {
return SubjectFee(
name: name ?? this.name,
credit: credit ?? this.credit,
isHighQuality: isHighQuality ?? this.isHighQuality,
price: price ?? this.price,
isDebt: isDebt ?? this.isDebt,
isReStudy: isReStudy ?? this.isReStudy,
confirmedPaymentAt: confirmedPaymentAt ?? this.confirmedPaymentAt,
);
}

Map<String, dynamic> toMap() {
final result = <String, dynamic>{};

result.addAll({'name': name});
result.addAll({'credit': credit});
result.addAll({'isHighQuality': isHighQuality});
result.addAll({'price': price});
result.addAll({'isDebt': isDebt});
result.addAll({'isReStudy': isReStudy});
if (confirmedPaymentAt != null) {
result.addAll({'confirmedPaymentAt': confirmedPaymentAt});
}

return result;
}

factory SubjectFee.fromMap(Map<String, dynamic> map) {
return SubjectFee(
name: map['name'] ?? '',
credit: map['credit']?.toInt() ?? 0,
isHighQuality: map['isHighQuality'] ?? false,
price: map['price']?.toDouble() ?? 0.0,
isDebt: map['isDebt'] ?? false,
isReStudy: map['isReStudy'] ?? false,
confirmedPaymentAt: map['confirmedPaymentAt'],
);
}

String toJson() => json.encode(toMap());

factory SubjectFee.fromJson(String source) =>
SubjectFee.fromMap(json.decode(source));

@override
String toString() {
return 'SubjectFee(name: $name, credit: $credit, isHighQuality: $isHighQuality, price: $price, isDebt: $isDebt, isReStudy: $isReStudy, confirmedPaymentAt: $confirmedPaymentAt)';
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;

return other is SubjectFee &&
other.name == name &&
other.credit == credit &&
other.isHighQuality == isHighQuality &&
other.price == price &&
other.isDebt == isDebt &&
other.isReStudy == isReStudy &&
other.confirmedPaymentAt == confirmedPaymentAt;
}

@override
int get hashCode {
return name.hashCode ^
credit.hashCode ^
isHighQuality.hashCode ^
price.hashCode ^
isDebt.hashCode ^
isReStudy.hashCode ^
confirmedPaymentAt.hashCode;
}
}
3 changes: 2 additions & 1 deletion lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class DutUtils {
}
}

if (schYear != null && schYearVal != null && week != null) {
// schYearVal != null
if (schYear != null && week != null) {
result = DutSchoolYear(
schoolYear: schYear,
schoolYearVal: schYearVal,
Expand Down

0 comments on commit 1982713

Please sign in to comment.