Skip to content

Commit

Permalink
Personal deadlines (#300)
Browse files Browse the repository at this point in the history
* Removed unused StreaksView files

* widget in sections

* fixed header size

* Created deadline mode selection dialog

* fixed mode selection controller

* fixed layout for mode buttons

* Added StorageRecord model

* Added StorageRecordsAPI class

* Added deadline counting & updated core data model

* displaying deadlines now & they work correctly now

* Added notification scheduling

* Added notification scheduling

* Added PersonalDeadlineManager with manager operations & some refactoring

* multiple fixes for sync to work

* Added sync for enrolled courses

* Added deadline deletion & started change UI

* pbxproj fix

* fixes

* Added deadline editing

* fixed iPad crash

* saving state for deadline widget

* Added localizations

* Added iOS analytics

* Added error handling in DeadlineCounter

* time intervals to constants

* added minor comment

* Analytics fixes

* removed default realizations

* refactored mode selection layout

* minor fixes & new blue color

* Localizations and notifications fix
  • Loading branch information
Ostrenkiy authored Jun 4, 2018
1 parent 50f41d8 commit a858911
Show file tree
Hide file tree
Showing 47 changed files with 2,210 additions and 369 deletions.
1 change: 1 addition & 0 deletions DefaultsContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ import Foundation
class DefaultsContainer {
private init() {}
static let launch = LaunchDefaultsContainer()
static let personalDeadlines = PersonalDeadlinesDefaultsContainer()
}
424 changes: 353 additions & 71 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Stepic/AnalyticsEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,29 @@ struct AnalyticsEvents {
static let hard = "adaptive_reaction_hard"
}
}

struct PersonalDeadlines {
struct Widget {
static let shown = "personal_deadlines_widget_shown"
static let clicked = "personal_deadlines_widget_clicked"
static let hidden = "personal_deadlines_widget_hidden"
}

struct Mode {
static let opened = "personal_deadline_mode_opened"
static let chosen = "personal_deadline_mode_chosen"
static let closed = "personal_deadline_mode_closed"
}

struct EditSchedule {
static let changePressed = "personal_deadline_change_pressed"
struct Time {
static let opened = "personal_deadline_time_opened"
static let closed = "personal_deadline_time_closed"
static let saved = "personal_deadline_time_saved"
}
}
static let deleted = "personal_deadline_deleted"
static let notSupportedNotification = "personal_deadline_not_supported_notification_scheduled"
}
}
44 changes: 6 additions & 38 deletions Stepic/Course.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ final class Course: NSManagedObject, IDFetchable {
}
}

var sectionDeadlines: [SectionDeadline]? {
get {
return (PersonalDeadlineLocalStorageManager().getRecord(for: self)?.data as? DeadlineStorageData)?.deadlines
}
}

var metaInfo: String {
//percent of completion = n_steps_passed/n_steps
if let p = self.progress {
Expand All @@ -72,13 +78,6 @@ final class Course: NSManagedObject, IDFetchable {

var metaInfoContainer: CourseMetainfoContainer {
var metaArr = [CourseMetainfoEntity]()

// if summary != "" {
// metaArr += [CourseMetainfoEntity(title: NSLocalizedString("Summary", comment: ""), subtitle: summary)]
// }
// if courseDescription != "" {
// metaArr += [CourseMetainfoEntity(title: NSLocalizedString("Description", comment: ""), subtitle: courseDescription)]
// }
if workload != "" {
metaArr += [CourseMetainfoEntity(title: NSLocalizedString("Workload", comment: ""), subtitle: workload)]
}
Expand All @@ -91,10 +90,6 @@ final class Course: NSManagedObject, IDFetchable {
if format != "" {
metaArr += [CourseMetainfoEntity(title: NSLocalizedString("Format", comment: ""), subtitle: format)]
}
// if requirements != "" {
// metaArr += [CourseMetainfoEntity(title: NSLocalizedString("Requirements", comment: ""), subtitle: requirements)]
// }
//
return CourseMetainfoContainer(courseId: id, metainfo: metaArr)
}

Expand Down Expand Up @@ -132,22 +127,6 @@ final class Course: NSManagedObject, IDFetchable {
initialize(json)
}

// func loadLastStep(success: @escaping ((Void) -> Void)) {
// guard let id = self.lastStepId else {
// return
// }
// _ = ApiDataDownloader.lastSteps.retrieve(ids: [id], success: {
// [weak self]
// lastSteps in
//
// self?.changeLastStepTo(lastStep: lastSteps.first!)
// success()
// }, error: {
// error in
// print("error while loading last step")
// })
// }

func loadAllInstructors(success: @escaping (() -> Void)) {
_ = ApiDataDownloader.users.retrieve(ids: self.instructorsArray, existing: self.instructors, refreshMode: .update, success: {
users in
Expand Down Expand Up @@ -178,7 +157,6 @@ final class Course: NSManagedObject, IDFetchable {
idsArray[dimCount - 1].append(sectionId)
}

// let sectionsToDownload = idsArray.count
var downloadedSections = [Section]()

let idsDownloaded: ([Section]) -> Void = {
Expand Down Expand Up @@ -237,7 +215,6 @@ final class Course: NSManagedObject, IDFetchable {
return
}

// print("progress ids array -> \(progressIds)")
_ = ApiDataDownloader.progresses.retrieve(ids: progressIds, existing: progresses, refreshMode: .update, success: {
newProgresses -> Void in
progresses = Sorter.sort(newProgresses, byIds: progressIds)
Expand Down Expand Up @@ -362,7 +339,6 @@ final class Course: NSManagedObject, IDFetchable {
} catch {
print("Error while getting courses")
return []
// throw FetchError.RequestExecution
}
}

Expand All @@ -385,12 +361,4 @@ final class Course: NSManagedObject, IDFetchable {
return sections.filter({ $0.id == nextId }).first
}
}

// func changeLastStepTo(lastStep: LastStep?) {
// let objectToDelete = self.lastStep
// self.lastStep = lastStep
// if let deletingObject = objectToDelete {
// CoreDataHelper.instance.deleteFromStore(deletingObject, save: true)
// }
// }
}
5 changes: 5 additions & 0 deletions Stepic/CourseListPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ class CourseListPresenter {
return
}
strongSelf.lastStepDataSource?.didLoadWithProgresses(courses: strongSelf.courses)
if let userID = AuthInfo.shared.userId {
for course in strongSelf.courses {
PersonalDeadlineManager.shared.syncDeadline(for: course, userID: userID)
}
}
})
default:
state = courses.isEmpty ? .emptyRefreshing : .displayingWithRefreshing
Expand Down
40 changes: 40 additions & 0 deletions Stepic/DeadlineMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// DeadlineMode.swift
// Stepic
//
// Created by Ostrenkiy on 15.05.2018.
// Copyright © 2018 Alex Karpov. All rights reserved.
//

import Foundation

struct DeadlineModeInfo {
var title: String
var weeklyLoadHours: Int
var image: UIImage

init(title: String, weeklyLoadHours: Int, image: UIImage) {
self.title = title
self.weeklyLoadHours = weeklyLoadHours
self.image = image
}

var dailyLoadSeconds: Int {
return weeklyLoadHours * 60 * 60 / 7
}
}

enum DeadlineMode {
case hobby, standard, extreme

func getModeInfo() -> DeadlineModeInfo {
switch self {
case .hobby:
return DeadlineModeInfo(title: NSLocalizedString("HobbyDeadlineMode", comment: ""), weeklyLoadHours: 3, image: #imageLiteral(resourceName: "25-science-growth-sprout"))
case .standard:
return DeadlineModeInfo(title: NSLocalizedString("StandardDeadlineMode", comment: ""), weeklyLoadHours: 7, image: #imageLiteral(resourceName: "27-science-study-learn-graduate"))
case .extreme:
return DeadlineModeInfo(title: NSLocalizedString("ExtremeDeadlineMode", comment: ""), weeklyLoadHours: 15, image: #imageLiteral(resourceName: "1-science-rocket-spaceship-rocket-launch"))
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "1-science-rocket-spaceship-rocket-launch.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "25-science-growth-sprout.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "27-science-study-learn-graduate.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
6 changes: 6 additions & 0 deletions Stepic/Images.xcassets/Deadline Modes/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
21 changes: 10 additions & 11 deletions Stepic/Lesson+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extension Lesson {
@NSManaged var managedTitle: String?
@NSManaged var managedSlug: String?
@NSManaged var managedCoverURL: String?
@NSManaged var managedTimeToComplete: NSNumber?

@NSManaged var managedStepsArray: NSObject?

@NSManaged var managedSteps: NSOrderedSet?

@NSManaged var managedUnit: Unit?
// @NSManaged var managedIsCached : NSNumber?

class var oldEntity: NSEntityDescription {
return NSEntityDescription.entity(forEntityName: "Lesson", in: CoreDataHelper.instance.context)!
Expand All @@ -45,16 +45,6 @@ extension Lesson {
}
}

// var isCached : Bool {
// set(value){
// self.managedIsCached = value
// CoreDataHelper.instance.save()
// }
// get {
// return managedIsCached?.boolValue ?? false
// }
// }

var title: String {
set(value) {
self.managedTitle = value
Expand Down Expand Up @@ -121,6 +111,15 @@ extension Lesson {
}
}

var timeToComplete: Double {
get {
return managedTimeToComplete?.doubleValue ?? 0
}
set(value) {
managedTimeToComplete = value as NSNumber?
}
}

var unit: Unit? {
return managedUnit
}
Expand Down
1 change: 1 addition & 0 deletions Stepic/Lesson.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Lesson: NSManagedObject, JSONSerializable {
isPublic = json["is_public"].boolValue
slug = json["slug"].stringValue
coverURL = json["cover_url"].string
timeToComplete = json["time_to_complete"].doubleValue
stepsArray = json["steps"].arrayObject as! [Int]
}

Expand Down
2 changes: 1 addition & 1 deletion Stepic/Model.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>Model_courselists_v21.xcdatamodel</string>
<string>Model_timetocomplete_v22.xcdatamodel</string>
</dict>
</plist>
Loading

0 comments on commit a858911

Please sign in to comment.