-
Notifications
You must be signed in to change notification settings - Fork 690
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
Sprint 06 #712
Open
s1zzen
wants to merge
7
commits into
Yandex-Practicum:project_sprint_3_start
Choose a base branch
from
s1zzen:sprint_06
base: project_sprint_3_start
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sprint 06 #712
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dbb6337
Закончил спринт
s1zzen 523c19b
почистил код
s1zzen dec1456
sprint 5
s1zzen 39f6fcb
выполнено задание sprint_05
s1zzen f31b956
sprint_05
s1zzen ec782e4
sprint_6 +randomquestions
s1zzen eec2f02
+loading indicator +bad image handler; cleaned code
s1zzen 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Float+Extensions.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 06.02.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Float { | ||
static var randomMovieRating: Float { | ||
let randomFloat = Float.random(in: 1.0...10.0) | ||
let intVal:Int = Int(randomFloat*10) | ||
return Float(intVal)/10.0 | ||
} | ||
} | ||
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import UIKit | ||
|
||
extension UIColor { } | ||
extension UIColor { | ||
static var ypBlack: UIColor { UIColor(named: "YP Black") ?? UIColor.black } | ||
static var ypGray: UIColor { UIColor(named: "YP Gray") ?? UIColor.gray } | ||
static var ypGreen: UIColor { UIColor(named: "YP Green") ?? UIColor.green } | ||
static var ypRed: UIColor { UIColor(named: "YP Red") ?? UIColor.red } | ||
static var ypWhite: UIColor { UIColor(named: "YP White") ?? UIColor.white } | ||
static var ypBackground: UIColor { UIColor(named: "YP Background") ?? UIColor.systemBackground } | ||
|
||
} |
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,15 @@ | ||
// | ||
// AlertModel.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AlertModel { | ||
let title: String | ||
let message: String | ||
let buttonText: String | ||
var buttonAction: (()->Void)? | ||
} |
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,18 @@ | ||
// | ||
// GameRecord.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GameRecord: Codable { | ||
let correct: Int | ||
let total: Int | ||
let date: Date | ||
|
||
func isBetterThan(_ another: GameRecord) -> Bool { | ||
correct > another.correct | ||
} | ||
} |
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,39 @@ | ||
// | ||
// MostPopularMovies.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 05.02.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct MostPopularMovies: Codable { | ||
let errorMessage: String | ||
let items: [MostPopularMovie] | ||
} | ||
|
||
struct MostPopularMovie: Codable { | ||
let title: String | ||
let rating: String | ||
let imageURL: URL | ||
|
||
var resizedImageURL: URL { | ||
// создаем строку из адреса | ||
let urlString = imageURL.absoluteString | ||
// обрезаем лишнюю часть и добавляем модификатор желаемого качества | ||
let imageUrlString = urlString.components(separatedBy: "._")[0] + "._V0_UX600_.jpg" | ||
|
||
// пытаемся создать новый адрес, если не получается возвращаем старый | ||
guard let newURL = URL(string: imageUrlString) else { | ||
return imageURL | ||
} | ||
|
||
return newURL | ||
} | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case title = "fullTitle" | ||
case rating = "imDbRating" | ||
case imageURL = "image" | ||
} | ||
} |
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 @@ | ||
// | ||
// QuizQuestion.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct QuizQuestion { | ||
let image: Data | ||
let text: String | ||
let correctAnswer: Bool | ||
} |
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 @@ | ||
// | ||
// QuizResultsViewModel.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct QuizResultsViewModel { | ||
let title: String | ||
let text: String | ||
let buttonText: String | ||
} |
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 @@ | ||
// | ||
// QuizStepViewModel.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import UIKit | ||
|
||
struct QuizStepViewModel { | ||
let image: UIImage | ||
let question: String | ||
let questionNumber: String | ||
} |
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,36 @@ | ||
// | ||
// AlertPresenter.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
import UIKit | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UIKit включает в себя Foundation, поэтому можно импортировать только UIKit :) |
||
final class AlertPresenter: AlertPresenterProtocol { | ||
|
||
weak var delegate: AlertPresenterDelegate? | ||
|
||
func show(alertModel: AlertModel) { | ||
let alert = UIAlertController( | ||
title: alertModel.title, | ||
message: alertModel.message, | ||
preferredStyle: .alert) | ||
|
||
let action = UIAlertAction( | ||
title: alertModel.buttonText, | ||
style: .default, | ||
handler: { _ in | ||
alertModel.buttonAction?() | ||
}) | ||
|
||
alert.addAction(action) | ||
delegate?.show(alert: alert) | ||
} | ||
|
||
init(delegate: AlertPresenterDelegate?) { | ||
self.delegate = delegate | ||
} | ||
} |
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,13 @@ | ||
// | ||
// AlertPresenterDelegate.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
protocol AlertPresenterDelegate: AnyObject { | ||
func show(alert: UIAlertController) | ||
} |
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,13 @@ | ||
// | ||
// AlertPresenterProtocol.swift | ||
// MovieQuiz | ||
// | ||
// Created by Сергей Баскаков on 24.01.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AlertPresenterProtocol: AnyObject { | ||
var delegate: AlertPresenterDelegate? { get set } | ||
func show(alertModel: AlertModel) | ||
} |
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.
extension не обязательно делать public, так как проект состоит из одного модуля и расширение Float используется только в рамках этого модуля.