Skip to content
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

Fix quiz title visibility #861

Merged
merged 3 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
2C1AC313255B466100E6ECA9 /* CatalogBlocksNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1AC312255B466100E6ECA9 /* CatalogBlocksNetworkService.swift */; };
2C1AC31E255B476A00E6ECA9 /* CatalogBlocksRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1AC31D255B476A00E6ECA9 /* CatalogBlocksRepository.swift */; };
2C1B75B722CE1E4400262707 /* CommentsNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1B75B622CE1E4400262707 /* CommentsNetworkService.swift */; };
2C1C37DF25938CAF009CC761 /* TitlePresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1C37DE25938CAF009CC761 /* TitlePresentable.swift */; };
2C1E429824977EAC009F4C69 /* CoursePurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1E429724977EAC009F4C69 /* CoursePurchase.swift */; };
2C1E429A24978114009F4C69 /* CoursePurchasesAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1E429924978114009F4C69 /* CoursePurchasesAPI.swift */; };
2C1E429C2497830F009F4C69 /* CoursePurchasesNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C1E429B2497830F009F4C69 /* CoursePurchasesNetworkService.swift */; };
Expand Down Expand Up @@ -1958,6 +1959,7 @@
2C1AC312255B466100E6ECA9 /* CatalogBlocksNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogBlocksNetworkService.swift; sourceTree = "<group>"; };
2C1AC31D255B476A00E6ECA9 /* CatalogBlocksRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogBlocksRepository.swift; sourceTree = "<group>"; };
2C1B75B622CE1E4400262707 /* CommentsNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsNetworkService.swift; sourceTree = "<group>"; };
2C1C37DE25938CAF009CC761 /* TitlePresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitlePresentable.swift; sourceTree = "<group>"; };
2C1E429724977EAC009F4C69 /* CoursePurchase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoursePurchase.swift; sourceTree = "<group>"; };
2C1E429924978114009F4C69 /* CoursePurchasesAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoursePurchasesAPI.swift; sourceTree = "<group>"; };
2C1E429B2497830F009F4C69 /* CoursePurchasesNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoursePurchasesNetworkService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6488,6 +6490,7 @@
62E98F9F759D04EFACC2579D /* NibLoadable.swift */,
62E980F9CFE23B23B5720F5E /* ProgrammaticallyInitializableViewProtocol.swift */,
62E98128FE2C79FBA6AD7D4B /* Reusable.swift */,
2C1C37DE25938CAF009CC761 /* TitlePresentable.swift */,
62E98B6565A0041AD519798A /* UniqueIdentifiable.swift */,
);
path = Protocols;
Expand Down Expand Up @@ -9070,6 +9073,7 @@
62E98905245F33B16D020586 /* ContinueActionButton.swift in Sources */,
62E98736DE8178FA36A565B6 /* UserCoursesAPI.swift in Sources */,
2CECFEF9252F235A006BA883 /* VisitedCoursesNetworkService.swift in Sources */,
2C1C37DF25938CAF009CC761 /* TitlePresentable.swift in Sources */,
62E98FAF7FFEFCAB3196CF16 /* UserCourse.swift in Sources */,
2C295A6A222D8BAB008878B6 /* EnrollmentsAPI.swift in Sources */,
2CF4663C25405F4C002415AF /* TableQuizSelectColumnsHeaderView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ protocol QuizInputProtocol: AnyObject {
func update(dataset: Dataset?)
func update(feedback: SubmissionFeedback?)
func update(codeDetails: CodeDetails?)
func update(quizTitleVisibility isVisible: Bool)

func isReplyValid(_ reply: Reply) -> ReplyValidationResultType
}
Expand All @@ -22,6 +21,5 @@ extension QuizInputProtocol {
func update(dataset: Dataset?) {}
func update(feedback: SubmissionFeedback?) {}
func update(codeDetails: CodeDetails?) {}
func update(quizTitleVisibility isVisible: Bool) {}
func isReplyValid(_ reply: Reply) -> ReplyValidationResultType { .success }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ enum CodeQuiz {
let languageName: String?
let codeDetails: CodeDetails
let status: QuizStatus?
// FIXME: Extract to protocol `TitlePresentable`
let isQuizTitleVisible: Bool
}

struct ViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ final class CodeQuizInteractor: CodeQuizInteractorProtocol {
}
}

private var isQuizTitleVisible = true

var isCurrentUserCodeTemplateUpdateEnabled: Bool = true

init(
Expand Down Expand Up @@ -108,8 +106,7 @@ final class CodeQuizInteractor: CodeQuizInteractorProtocol {
language: self.language,
languageName: self.languageName,
codeDetails: codeDetails,
status: self.currentStatus,
isQuizTitleVisible: self.isQuizTitleVisible
status: self.currentStatus
)
)
}
Expand Down Expand Up @@ -204,10 +201,6 @@ extension CodeQuizInteractor: QuizInputProtocol {
self.codeDetails = codeDetails
}

func update(quizTitleVisibility isVisible: Bool) {
self.isQuizTitleVisible = isVisible
}

private func handleEmptyReply() {
if self.language == CodeLanguage.sql {
guard self.currentCode?.isEmpty ?? true else {
Expand Down
11 changes: 3 additions & 8 deletions Stepic/Sources/Modules/Quizzes/CodeQuiz/CodeQuizPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ final class CodeQuizPresenter: CodeQuizPresenterProtocol {
)
}()

let title: String? = {
if response.isQuizTitleVisible {
return response.language == .sql
? NSLocalizedString("SQLQuizTitle", comment: "")
: nil
}
return nil
}()
let title = response.language == .sql
? NSLocalizedString("SQLQuizTitle", comment: "")
: nil

let viewModel = CodeQuizViewModel(
title: title,
Expand Down
15 changes: 12 additions & 3 deletions Stepic/Sources/Modules/Quizzes/CodeQuiz/CodeQuizView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension CodeQuizView {
}
}

final class CodeQuizView: UIView {
final class CodeQuizView: UIView, TitlePresentable {
let appearance: Appearance
weak var delegate: CodeQuizViewDelegate?

Expand Down Expand Up @@ -100,6 +100,16 @@ final class CodeQuizView: UIView {

private lazy var titleLabelContainerView = UIView()

var title: String? {
get {
self.titleLabel.text
}
set {
self.titleLabel.text = newValue
self.titleLabelContainerView.isHidden = newValue?.isEmpty ?? true
}
}

init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)
Expand Down Expand Up @@ -153,8 +163,7 @@ final class CodeQuizView: UIView {

// Hide toolbar and show title for sql quiz.
if viewModel.language == .sql {
self.titleLabel.text = viewModel.title
self.titleLabelContainerView.isHidden = viewModel.title?.isEmpty ?? true
self.title = viewModel.title
self.toolbarView.isHidden = !self.titleLabelContainerView.isHidden
} else {
self.titleLabelContainerView.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension FillBlanksQuizView {
}
}

final class FillBlanksQuizView: UIView {
final class FillBlanksQuizView: UIView, TitlePresentable {
let appearance: Appearance

private lazy var titleLabel: UILabel = {
Expand Down Expand Up @@ -49,15 +49,27 @@ final class FillBlanksQuizView: UIView {
return collectionView
}()

var title: String? {
get {
self.titleLabel.text
}
set {
self.titleLabel.text = newValue
self.titleLabel.isHidden = newValue?.isEmpty ?? true
}
}

override var intrinsicContentSize: CGSize {
let titleLabelHeight = self.titleLabel.isHidden
? 0
: self.titleLabel.intrinsicContentSize.height
let collectionViewHeight = max(
self.appearance.collectionViewMinHeight,
self.collectionView.collectionViewLayout.collectionViewContentSize.height
)
return CGSize(
width: UIView.noIntrinsicMetric,
height: self.titleLabel.intrinsicContentSize.height + collectionViewHeight
)
let height = titleLabelHeight + collectionViewHeight

return CGSize(width: UIView.noIntrinsicMetric, height: height)
}

init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ enum NewChoiceQuiz {
let isMultipleChoice: Bool
let choices: [Choice]
let status: QuizStatus?
let isQuizTitleVisible: Bool
}

struct ViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ final class NewChoiceQuizInteractor: NewChoiceQuizInteractorProtocol {
private var currentChoices: [Bool]?
private var currentChoicesFeedback: [String?]?

private var isQuizTitleVisible = true

init(presenter: NewChoiceQuizPresenterProtocol) {
self.presenter = presenter
}
Expand Down Expand Up @@ -47,8 +45,7 @@ final class NewChoiceQuizInteractor: NewChoiceQuizInteractorProtocol {
let (text, (isSelected, hint)) = result
return NewChoiceQuiz.Choice(text: text, isSelected: isSelected, hint: hint)
},
status: self.currentStatus,
isQuizTitleVisible: self.isQuizTitleVisible
status: self.currentStatus
)
)
}
Expand Down Expand Up @@ -98,10 +95,6 @@ extension NewChoiceQuizInteractor: QuizInputProtocol {
}
}

func update(quizTitleVisibility isVisible: Bool) {
self.isQuizTitleVisible = isVisible
}

func isReplyValid(_ reply: Reply) -> ReplyValidationResultType {
let errorMessage = NSLocalizedString("ChoiceQuizEmptyReplyMessage", comment: "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ final class NewChoiceQuizPresenter: NewChoiceQuizPresenterProtocol {
}
}()

let title: String? = {
if response.isQuizTitleVisible {
return response.isMultipleChoice
? NSLocalizedString("MultipleChoiceQuizTitle", comment: "")
: NSLocalizedString("SingleChoiceQuizTitle", comment: "")
}
return nil
}()
let title = response.isMultipleChoice
? NSLocalizedString("MultipleChoiceQuizTitle", comment: "")
: NSLocalizedString("SingleChoiceQuizTitle", comment: "")

let viewModel = NewChoiceQuizViewModel(
title: title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

struct NewChoiceQuizViewModel {
let title: String?
let title: String
let choices: [NewChoiceQuiz.Choice]
let finalState: State?
let isMultipleChoice: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension NewChoiceQuizView {
}
}

final class NewChoiceQuizView: UIView {
final class NewChoiceQuizView: UIView, TitlePresentable {
let appearance: Appearance
weak var delegate: NewChoiceQuizViewDelegate?

Expand Down Expand Up @@ -63,8 +63,12 @@ final class NewChoiceQuizView: UIView {
private var loadGroup: DispatchGroup?

var title: String? {
didSet {
self.titleLabel.text = self.title
get {
self.titleLabel.text
}
set {
self.titleLabel.text = newValue
self.titleLabelContainerView.isHidden = newValue?.isEmpty ?? true
}
}

Expand All @@ -90,8 +94,6 @@ final class NewChoiceQuizView: UIView {
// MARK: - Public API

func updateFeedback(text: [String?]) {
assert(self.choicesStackView.arrangedSubviews.count == text.count)

for (index, hint) in text.enumerated() {
guard let choiceView = self.choicesStackView.arrangedSubviews[safe: index] as? ChoiceElementView else {
continue
Expand Down Expand Up @@ -188,8 +190,6 @@ final class NewChoiceQuizView: UIView {
return
}

assert(self.choicesStackView.arrangedSubviews.count == selectionMask.count)

for (isSelected, view) in zip(selectionMask, self.choicesStackView.arrangedSubviews) {
if let elementView = view as? ChoiceElementView, isSelected {
elementView.state = state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ enum NewFreeAnswerQuiz {
struct Response {
let text: String?
let status: QuizStatus?
let isQuizTitleVisible: Bool
}

struct ViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ final class NewFreeAnswerQuizInteractor: NewFreeAnswerQuizInteractorProtocol {
private var currentText: String?
private var currentStatus: QuizStatus?

private var isQuizTitleVisible = true

init(presenter: NewFreeAnswerQuizPresenterProtocol) {
self.presenter = presenter
}
Expand All @@ -29,8 +27,7 @@ final class NewFreeAnswerQuizInteractor: NewFreeAnswerQuizInteractorProtocol {
self.presenter.presentReply(
response: .init(
text: self.currentText,
status: self.currentStatus,
isQuizTitleVisible: self.isQuizTitleVisible
status: self.currentStatus
)
)
}
Expand Down Expand Up @@ -61,8 +58,4 @@ extension NewFreeAnswerQuizInteractor: QuizInputProtocol {
self.currentStatus = status
self.presentNewData()
}

func update(quizTitleVisibility isVisible: Bool) {
self.isQuizTitleVisible = isVisible
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class NewFreeAnswerQuizPresenter: NewFreeAnswerQuizPresenterProtocol {

func presentReply(response: NewFreeAnswerQuiz.ReplyLoad.Response) {
let viewModel = NewFreeAnswerQuizViewModel(
title: response.isQuizTitleVisible ? NSLocalizedString("FreeAnswerQuizTitle", comment: "") : nil,
title: NSLocalizedString("FreeAnswerQuizTitle", comment: ""),
text: response.text,
placeholderText: self.quizPlaceholder,
isEnabled: response.status != .correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension NewFreeAnswerQuizView {
}
}

final class NewFreeAnswerQuizView: UIView {
final class NewFreeAnswerQuizView: UIView, TitlePresentable {
let appearance: Appearance
weak var delegate: NewFreeAnswerQuizViewDelegate?

Expand Down Expand Up @@ -72,8 +72,12 @@ final class NewFreeAnswerQuizView: UIView {
private lazy var textFieldContainerView = UIView()

var title: String? {
didSet {
self.titleLabel.text = self.title
get {
self.titleLabel.text
}
set {
self.titleLabel.text = newValue
self.titleLabelContainerView.isHidden = newValue?.isEmpty ?? true
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

struct NewFreeAnswerQuizViewModel {
let title: String?
let title: String
let text: String?
let placeholderText: String
let isEnabled: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ enum NewMatchingQuiz {
struct Response {
let items: [MatchItem]
let status: QuizStatus?
let isQuizTitleVisible: Bool
}

struct ViewModel {
Expand Down
Loading