Skip to content

Commit

Permalink
Merge pull request #77 from NKUST-ITC/develop
Browse files Browse the repository at this point in the history
Update to v3.2.6
  • Loading branch information
abc873693 authored Sep 17, 2019
2 parents c469378 + 5d8118f commit e569dd6
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 114 deletions.
4 changes: 2 additions & 2 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/rainvisitor/development/flutter/bin/cache/artifacts/engine/ios-release"
export "FLUTTER_BUILD_NAME=3.2.4"
export "FLUTTER_BUILD_NUMBER=30204"
export "FLUTTER_BUILD_NAME=3.2.6"
export "FLUTTER_BUILD_NUMBER=30206"
38 changes: 28 additions & 10 deletions lib/api/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class Helper {
static JsonCodec jsonCodec;
static CancelToken cancelToken;

static String username;
static String password;
static DateTime expireTime;

bool isExpire() {
return DateTime.now().isAfter(expireTime.add(Duration(hours: 8)));
}

static Helper get instance {
if (_instance == null) {
_instance = Helper();
Expand Down Expand Up @@ -93,7 +101,6 @@ class Helper {
}

Future<LoginResponse> login(String username, String password) async {
dio.options.headers = _createBasicAuth(username, password);
try {
var response = await dio.post(
'/oauth/token',
Expand All @@ -105,6 +112,9 @@ class Helper {
if (response == null) print('null');
var loginResponse = LoginResponse.fromJson(response.data);
options.headers = _createBearerTokenAuth(loginResponse.token);
expireTime = loginResponse.expireTime;
Helper.username = username;
Helper.password = password;
return loginResponse;
} on DioError catch (dioError) {
throw dioError;
Expand Down Expand Up @@ -153,6 +163,7 @@ class Helper {
}

Future<UserInfo> getUsersInfo() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get('/user/info');
return UserInfo.fromJson(response.data);
Expand All @@ -161,16 +172,8 @@ class Helper {
}
}

Future<String> getUsersPicture() async {
try {
var response = await dio.get("/$VERSION/ap/users/picture");
return response.data;
} on DioError catch (dioError) {
throw dioError;
}
}

Future<SemesterData> getSemester() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get("/user/semesters");
return SemesterData.fromJson(response.data);
Expand All @@ -180,6 +183,7 @@ class Helper {
}

Future<ScoreData> getScores(String year, String semester) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
"/user/scores",
Expand All @@ -199,6 +203,7 @@ class Helper {
}

Future<CourseData> getCourseTables(String year, String semester) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
'/user/coursetable',
Expand All @@ -219,6 +224,7 @@ class Helper {

Future<RewardAndPenaltyData> getRewardAndPenalty(
String year, String semester) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
"/user/reward-and-penalty",
Expand All @@ -239,6 +245,7 @@ class Helper {

Future<MidtermAlertsData> getMidtermAlerts(
String year, String semester) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
"/user/midterm-alerts",
Expand Down Expand Up @@ -298,6 +305,7 @@ class Helper {
}

Future<BusData> getBusTimeTables(DateTime dateTime) async {
if (isExpire()) await login(username, password);
var formatter = DateFormat('yyyy-MM-dd');
var date = formatter.format(dateTime);
try {
Expand All @@ -318,6 +326,7 @@ class Helper {
}

Future<BusReservationsData> getBusReservations() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get("/bus/reservations");
if (response.statusCode == 204)
Expand All @@ -330,6 +339,7 @@ class Helper {
}

Future<BookingBusData> bookingBusReservation(String busId) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.put(
"/bus/reservations",
Expand All @@ -344,6 +354,7 @@ class Helper {
}

Future<CancelBusData> cancelBusReservation(String cancelKey) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.delete(
"/bus/reservations",
Expand All @@ -358,6 +369,7 @@ class Helper {
}

Future<BusViolationRecordsData> getBusViolationRecords() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get('/bus/violation-records');
print(response.statusCode);
Expand All @@ -384,6 +396,7 @@ class Helper {
}

Future<LeavesData> getLeaves(String year, String semester) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
'/leaves',
Expand All @@ -400,6 +413,7 @@ class Helper {
}

Future<LeavesSubmitInfoData> getLeavesSubmitInfo() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
'/leaves/submit/info',
Expand All @@ -412,6 +426,7 @@ class Helper {
}

Future<Response> sendLeavesSubmit(LeavesSubmitData data) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.post(
'/leaves/submit',
Expand All @@ -425,6 +440,7 @@ class Helper {
}

Future<LibraryInfo> getLibraryInfo() async {
if (isExpire()) await login(username, password);
try {
var response = await dio.get(
'/leaves/submit/info',
Expand All @@ -439,6 +455,7 @@ class Helper {
}
}

@deprecated
_createBasicAuth(String username, String password) {
var text = username + ":" + password;
var encoded = utf8.encode(text);
Expand All @@ -448,6 +465,7 @@ class Helper {
};
}

// v3 api Authorization
_createBearerTokenAuth(String token) {
return {
'Authorization': 'Bearer $token',
Expand Down
8 changes: 4 additions & 4 deletions lib/models/bus_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ class BusTime {
String getStart(AppLocalizations local) {
switch (startStation) {
case "建工":
return local.yanchao;
case "燕巢":
return local.jiangong;
case "燕巢":
return local.yanchao;
default:
return local.unknown;
}
Expand All @@ -179,9 +179,9 @@ class BusTime {
String getEnd(AppLocalizations local) {
switch (startStation) {
case "建工":
return local.jiangong;
case "燕巢":
return local.yanchao;
case "燕巢":
return local.jiangong;
default:
return local.unknown;
}
Expand Down
111 changes: 98 additions & 13 deletions lib/models/course_data.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,115 @@
import 'dart:convert';

import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:intl/intl.dart';

class CourseData {
int status;
String messages;
List<CourseDetail> courses;
CourseTables courseTables;

CourseData({this.status, this.messages, this.courseTables});
CourseData({this.courses, this.courseTables});

CourseData.fromJson(Map<String, dynamic> json) {
courseTables = json['coursetable'] != null
? CourseTables.fromJson(json['coursetable'])
: null;
}
factory CourseData.fromRawJson(String str) =>
CourseData.fromJson(json.decode(str));

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

factory CourseData.fromJson(Map<String, dynamic> json) => CourseData(
courses: json["courses"] == null
? null
: List<CourseDetail>.from(
json["courses"].map((x) => CourseDetail.fromJson(x))),
courseTables: json["coursetable"] == null
? null
: CourseTables.fromJson(json["coursetable"]),
);

Map<String, dynamic> toJson() => {
"courses": courses == null
? null
: List<dynamic>.from(courses.map((x) => x.toJson())),
"coursetable": courseTables == null ? null : courseTables.toJson(),
};

bool get hasHoliday {
return ((courseTables.saturday?.isEmpty) ?? false) &&
((courseTables.sunday?.isEmpty) ?? false);
}
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
if (this.courseTables != null) {
data['coursetable'] = this.courseTables.toJson();
class CourseDetail {
String code;
String title;
String className;
String group;
String units;
String hours;
String required;
String at;
String times;
Location location;
List<String> instructors;

CourseDetail({
this.code,
this.title,
this.className,
this.group,
this.units,
this.hours,
this.required,
this.at,
this.times,
this.location,
this.instructors,
});

factory CourseDetail.fromRawJson(String str) =>
CourseDetail.fromJson(json.decode(str));

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

factory CourseDetail.fromJson(Map<String, dynamic> json) => CourseDetail(
code: json["code"] == null ? null : json["code"],
title: json["title"] == null ? null : json["title"],
className: json["className"] == null ? null : json["className"],
group: json["group"] == null ? null : json["group"],
units: json["units"] == null ? null : json["units"],
hours: json["hours"] == null ? null : json["hours"],
required: json["required"] == null ? null : json["required"],
at: json["at"] == null ? null : json["at"],
times: json["times"] == null ? null : json["times"],
location: json["location"] == null
? null
: Location.fromJson(json["location"]),
instructors: json["instructors"] == null
? null
: List<String>.from(json["instructors"].map((x) => x)),
);

Map<String, dynamic> toJson() => {
"code": code == null ? null : code,
"title": title == null ? null : title,
"className": className == null ? null : className,
"group": group == null ? null : group,
"units": units == null ? null : units,
"hours": hours == null ? null : hours,
"required": required == null ? null : required,
"at": at == null ? null : at,
"times": times == null ? null : times,
"location": location == null ? null : location.toJson(),
"instructors": instructors == null
? null
: List<dynamic>.from(instructors.map((x) => x)),
};

String getInstructors() {
String text = "";
if (instructors.length > 0) {
text += instructors[0];
for (var i = 1; i < instructors.length; i++) text += ",${instructors[i]}";
}
return data;
return text;
}
}

Expand Down
6 changes: 6 additions & 0 deletions lib/pages/home/about/about_us_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class AboutUsPageState extends State<AboutUsPage> {
Card(
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
padding: EdgeInsets.only(
top: 24.0, left: 16.0, bottom: 16.0, right: 16.0),
Expand Down Expand Up @@ -192,6 +195,9 @@ class AboutUsPageState extends State<AboutUsPage> {
_item(String text, String subText) => Card(
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
padding:
EdgeInsets.only(top: 24.0, left: 16.0, bottom: 16.0, right: 16.0),
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/home/about/open_source_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ class OpenSourcePageState extends State<OpenSourcePage> {
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
SelectableText(
items[index].text,
style: TextStyle(fontSize: 18.0),
),
SizedBox(
height: 4.0,
),
RichText(
text: TextSpan(
SelectableText.rich(
TextSpan(
style: TextStyle(
fontSize: 14.0, color: Resource.Colors.grey),
text: items[index].subText,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/home/bus/bus_reservations_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class BusReservationsPageState extends State<BusReservationsPage>
case _State.error:
return app.clickToRetry;
case _State.empty:
return app.busEmpty;
return app.busReservationEmpty;
case _State.campusNotSupport:
return app.campusNotSupport;
case _State.userNotSupport:
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/home/bus/bus_rule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class BusRulePageState extends State<BusRulePage> {
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: RichText(
textAlign: TextAlign.left,
text: TextSpan(
child: SelectableText.rich(
TextSpan(
style: TextStyle(
color: Resource.Colors.grey, height: 1.3, fontSize: 16.0),
children: [
Expand Down
Loading

0 comments on commit e569dd6

Please sign in to comment.