Skip to content

Commit

Permalink
Merge pull request #158 from sparcs-kaist/feat@large-widget-scroll-to…
Browse files Browse the repository at this point in the history
…-top

Resolve #157, Scrolls large widget to the top when there is no more upcoming lecture.
  • Loading branch information
sboh1214 authored Sep 23, 2023
2 parents c6f0fc4 + a1d5d5e commit 99d6cca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
21 changes: 17 additions & 4 deletions ios/OTLWidgets/WeekClassesWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct WeekClassesWidgetEntryView : View {
}
, alignment: .top
)
.offset(y: getOffsetByDate(date: entry.date))
.offset(y: getOffsetByDate(timetable: entry.timetableData?[Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
}
}.padding(16)
GeometryReader { proxy in
Expand Down Expand Up @@ -93,15 +93,28 @@ struct WeekClassesWidgetEntryView : View {
}
}

func getOffsetByDate(date: Date) -> CGFloat {
func getOffsetByDate(timetable: Timetable?, date: Date) -> CGFloat {
if (timetable == nil || timetable?.lectures.count == 0) {
return 0
}

var tmp = 0
let hour = Calendar.current.component(.hour, from: date) >= 2 ? Calendar.current.component(.hour, from: date)-2 : Calendar.current.component(.hour, from: date)
let calendar = Calendar.current
let hour = calendar.component(.hour, from: date) >= 2 ? calendar.component(.hour, from: date)-2 : calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date) + calendar.component(.hour, from: date) * 60

if hour > 9 {
tmp = hour >= 18 ? -387 : -43*(hour-9)
}

return CGFloat(tmp)
var end = 0
for lecture in timetable!.lectures {
for classtime in lecture.classtimes {
end = (classtime.end > end) ? classtime.end : end
}
}

return (end >= minutes) ? CGFloat(tmp) : 0
}

func getLecturesData(data: [(Int, Lecture)]) -> [WeekClassesWidgetData] {
Expand Down
24 changes: 0 additions & 24 deletions ios/OTLWidgets/WidgetBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,6 @@ func getDayInString(day: Int) -> String {
}
}

func getTodayLectures(timetable: Timetable?, date: Date) -> [(Int, Lecture)] {
var tmp: [(Int, Lecture)] = [(Int, Lecture)]()
if (timetable == nil) {
return tmp
}

let calendar = Calendar.current
var day = getDayWithWeekDay(weekday: calendar.component(.weekday, from: date))

while tmp.count == 0 {
for l in timetable!.lectures {
for i in 0..<l.classtimes.count {
let c = l.classtimes[i]
if c.day == day {
tmp.append((i, l))
}
}
}
day = (day >= 7) ? 0 : day + 1
}

return tmp
}

func getLecturesForDay(timetable: Timetable?, day: Int) -> [(Int, Lecture)] {
var tmp: [(Int, Lecture)] = [(Int, Lecture)]()
if (timetable == nil) {
Expand Down
10 changes: 6 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
8BB3457F2A012C99008A0E30 = {
Expand All @@ -384,7 +384,7 @@
);
mainGroup = 97C146E51CF9000F007C117D;
packageReferences = (
8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire" */,
8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire.git" */,
);
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -523,6 +523,7 @@
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/PromisesSwift/Promises.framework",
"${BUILT_PRODUCTS_DIR}/flutter_native_splash/flutter_native_splash.framework",
"${BUILT_PRODUCTS_DIR}/flutter_web_browser/flutter_web_browser.framework",
"${BUILT_PRODUCTS_DIR}/flutter_widgetkit/flutter_widgetkit.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
Expand All @@ -545,6 +546,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Promises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_native_splash.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_web_browser.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_widgetkit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
Expand Down Expand Up @@ -1201,7 +1203,7 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire" */ = {
8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire.git" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
requirement = {
Expand All @@ -1214,7 +1216,7 @@
/* Begin XCSwiftPackageProductDependency section */
8BB397442A8E003300DD352E /* Alamofire */ = {
isa = XCSwiftPackageProductDependency;
package = 8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire" */;
package = 8BB397432A8E003300DD352E /* XCRemoteSwiftPackageReference "Alamofire.git" */;
productName = Alamofire;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 99d6cca

Please sign in to comment.