-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exam application content #329
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9682749
Install AlamofireNetworkActivityIndicator
ivan-magda 38d97e5
Create knowledge graph plain objects
ivan-magda c329776
Create StepicResult enumeration
ivan-magda d131fd3
Create GraphService protocol
ivan-magda 0b8b1ef
Decode JSON data
ivan-magda 526a9c6
Refactor graph service implementation
ivan-magda f1aad93
Add common UIKit and Foundation extensions
ivan-magda 8a69edf
Initial topics scene implementation
ivan-magda 5a907a6
Fix tests
ivan-magda ba2edd2
Graph base models are now classes
ivan-magda 409d64e
Refactor rename Vertex's data instance property to id
ivan-magda a85773b
Add dictionary subscript by index
ivan-magda d4bca10
Extend knowledge graph functionality
ivan-magda fe16bfe
Map graph response model to concrete knowledge graph
ivan-magda 7869a51
Display actual graph data
ivan-magda daf7fd6
Add pull-to-refresh
ivan-magda 587d511
Provide model as a parameter for the TopicsPresenter
ivan-magda 61e8b7c
Test topics presenter view did load success refresh topics view called
ivan-magda 008cdd0
Test topics presenter view did load failure display error
ivan-magda 70ea727
Test topics presenter configure cell
ivan-magda f246420
Service components as a properties instead of functions
ivan-magda c89bc2f
Move graph's service resource URL to the class implementation
ivan-magda ed886f2
Install PromiseKit Alamofire extensions
ivan-magda 2b48623
Use Alamofire in graph service implementation
ivan-magda 777dda7
Use Promise as a return type of GraphService's obtainGraph()
ivan-magda 0c3db15
Remove Dictionary+Subscript file
ivan-magda 6587028
Remove String+Localized file
ivan-magda 1a570b5
Refactor TopicsPresenter
ivan-magda f115ed0
Use TopicsPresenter's new selectTopic(with:) function insted of onTap…
ivan-magda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
ExamEGERussian/Sources/BusinessLogicLayer/Services/GraphService/GraphService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// GraphService.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 18/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
|
||
protocol GraphService: class { | ||
func obtainGraph() -> Promise<KnowledgeGraphPlainObject> | ||
} |
21 changes: 21 additions & 0 deletions
21
ExamEGERussian/Sources/BusinessLogicLayer/Services/GraphService/GraphServiceImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// GraphServiceImpl.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 18/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import PromiseKit | ||
import Alamofire | ||
|
||
final class GraphServiceImpl: GraphService { | ||
private static let url = URL(string: "https://www.dropbox.com/s/l8n1wny8qu0gbqt/example.json?dl=1")! | ||
|
||
func obtainGraph() -> Promise<KnowledgeGraphPlainObject> { | ||
return Alamofire | ||
.request(GraphServiceImpl.url) | ||
.responseDecodable(KnowledgeGraphPlainObject.self) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ExamEGERussian/Sources/Common/Builders/AbstractGraphBuilder/AbstractGraphBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// AbstractGraphBuilder.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AbstractGraphBuilder { | ||
associatedtype T: Hashable | ||
func build() -> AbstractGraph<T> | ||
} |
44 changes: 44 additions & 0 deletions
44
ExamEGERussian/Sources/Common/Builders/AbstractGraphBuilder/KnowledgeGraphBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// AbstractGraphBuilderImpl.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final class KnowledgeGraphBuilder: AbstractGraphBuilder { | ||
private let graphPlainObject: KnowledgeGraphPlainObject | ||
|
||
init(graphPlainObject: KnowledgeGraphPlainObject) { | ||
self.graphPlainObject = graphPlainObject | ||
} | ||
|
||
func build() -> AbstractGraph<String> { | ||
let graph = KnowledgeGraph() | ||
|
||
graphPlainObject.topics.forEach { | ||
graph.addVertex(KnowledgeGraphVertex(id: $0.id, title: $0.title)) | ||
} | ||
graphPlainObject.topics | ||
.filter { $0.requiredFor != nil } | ||
.forEach { topic in | ||
guard let (source, _) = graph[topic.id], | ||
let (destination, _) = graph[topic.requiredFor!] else { | ||
return | ||
} | ||
graph.add(from: source, to: destination) | ||
} | ||
graphPlainObject.topicsMap.forEach { topicMap in | ||
guard let (vertex, _) = graph[topicMap.id] else { return } | ||
vertex.lessons.append(contentsOf: | ||
topicMap.lessons.map { | ||
KnowledgeGraphLesson(id: $0.id, type: $0.type, courseId: $0.course) | ||
} | ||
) | ||
} | ||
|
||
return graph | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
ExamEGERussian/Sources/Common/Extensions/UITableView/UITableView+Registration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// UITableView+Registration.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UITableView { | ||
func registerNib(for cellClass: UITableViewCell.Type) { | ||
register(cellClass.nib, forCellReuseIdentifier: cellClass.identifier) | ||
} | ||
|
||
func registerHeaderNib(for headerClass: UITableViewHeaderFooterView.Type) { | ||
register(headerClass.nib, forHeaderFooterViewReuseIdentifier: headerClass.identifier) | ||
} | ||
|
||
func registerClass(for cellClass: UITableViewCell.Type) { | ||
register(cellClass, forCellReuseIdentifier: cellClass.identifier) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
ExamEGERussian/Sources/Common/Extensions/UITableView/UITableView+Reuse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// UITableView+Reuse.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import UIKit.UITableView | ||
|
||
extension UITableView { | ||
func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T { | ||
let identifier = T.identifier | ||
return dequeueReusableCell(withIdentifier: identifier, | ||
for: indexPath) as! T // swiftlint:disable:this force_cast | ||
} | ||
|
||
func dequeueReusableHeaderFooterView<T: UITableViewHeaderFooterView>() -> T { | ||
let identifier = T.identifier | ||
return dequeueReusableHeaderFooterView(withIdentifier: identifier) as! T // swiftlint:disable:this force_cast | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ExamEGERussian/Sources/Common/Extensions/UITableViewCell/UITableViewCell+ReusableCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// UITableViewCell+ReusableCell.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import UIKit | ||
|
||
protocol ReusableCell { | ||
static var identifier: String { get } | ||
static var nib: UINib { get } | ||
} | ||
|
||
extension UITableViewCell: ReusableCell { | ||
static var identifier: String { | ||
return String(describing: self) | ||
} | ||
|
||
static var nib: UINib { | ||
return UINib(nibName: identifier, bundle: nil) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...mon/Extensions/UITableViewHeaderFooterView/UITableViewHeaderFooterView+ReusableCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// UITableViewHeaderFooterView+ReusableCell.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension UITableViewHeaderFooterView: ReusableCell { | ||
static var identifier: String { | ||
return String(describing: self) | ||
} | ||
|
||
static var nib: UINib { | ||
return UINib(nibName: identifier, bundle: nil) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ExamEGERussian/Sources/Common/Extensions/UIViewController/UIViewController+Alert.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// UIViewController+Alert.swift | ||
// ExamEGERussian | ||
// | ||
// Created by Ivan Magda on 19/07/2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIViewController { | ||
func presentAlert(withTitle title: String?, message: String? = nil, | ||
actionTitle: String? = NSLocalizedString("Ок", comment: ""), | ||
action actionCallback: (() -> Void)? = nil) { | ||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | ||
alert.addAction(UIAlertAction(title: actionTitle, style: .cancel) { _ in | ||
actionCallback?() | ||
}) | ||
present(alert, animated: true, completion: nil) | ||
} | ||
|
||
func presentConfirmationAlert(withTitle title: String?, message: String? = nil, | ||
buttonFirstTitle: String? = NSLocalizedString("Ок", comment: ""), | ||
buttonSecondTitle: String? = NSLocalizedString("Cancel", comment: ""), | ||
firstAction: (() -> Void)? = nil, secondAction: (() -> Void)? = nil) { | ||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | ||
alert.addAction(UIAlertAction(title: buttonFirstTitle, style: .default) { _ in | ||
firstAction?() | ||
}) | ||
alert.addAction(UIAlertAction(title: buttonSecondTitle, style: .default) { _ in | ||
secondAction?() | ||
}) | ||
present(alert, animated: true, completion: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удобно, кстати 👍
Я бы вместо
identifier
, использовалString(describing: self)
, вдругidentifier
поменяет формат (он всё таки больше reuseIdentifier).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так тут и используется
String(describing: self)
, спрятано.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, но это справедливо для соглашения "в качестве reuse identificator используем имя класса" :)
Завтра я захочу изменить его на "в качестве reuse identificator используем имя класса + суффикс -reuseId". Тогда в качестве nibName поле
identificator
уже не поюзать и все сломается.Но да, это не очень реалистичный кейс и можно не обращать внимание
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если мы захотим использовать идентификатор, отличный от имени класса, то всегда же можно переопределить это поле в наследнике.