Skip to content

5. domaća zadaća #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 QuizApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
5294A444264D53780000FE74 /* QuestionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5294A443264D53780000FE74 /* QuestionController.swift */; };
5294A44A264D54580000FE74 /* QuestionPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5294A449264D54580000FE74 /* QuestionPageController.swift */; };
5294A44D264D60640000FE74 /* QuizResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5294A44C264D60640000FE74 /* QuizResultsController.swift */; };
52A591A5266C1B7F0000196C /* LoginController+Animations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52A591A4266C1B7F0000196C /* LoginController+Animations.swift */; };
52B826882662EA39008A47DE /* QuizRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B826872662EA39008A47DE /* QuizRepository.swift */; };
52B8268D2662EAED008A47DE /* QuizDatabaseDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B8268C2662EAED008A47DE /* QuizDatabaseDataSource.swift */; };
52B826912662EB42008A47DE /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B826902662EB42008A47DE /* CoreDataStack.swift */; };
Expand Down Expand Up @@ -82,6 +83,7 @@
5294A443264D53780000FE74 /* QuestionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionController.swift; sourceTree = "<group>"; };
5294A449264D54580000FE74 /* QuestionPageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionPageController.swift; sourceTree = "<group>"; };
5294A44C264D60640000FE74 /* QuizResultsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizResultsController.swift; sourceTree = "<group>"; };
52A591A4266C1B7F0000196C /* LoginController+Animations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LoginController+Animations.swift"; sourceTree = "<group>"; };
52B826872662EA39008A47DE /* QuizRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizRepository.swift; sourceTree = "<group>"; };
52B8268C2662EAED008A47DE /* QuizDatabaseDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizDatabaseDataSource.swift; sourceTree = "<group>"; };
52B826902662EB42008A47DE /* CoreDataStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStack.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -239,6 +241,7 @@
children = (
52B826D4266396F1008A47DE /* ViewModels */,
52FFDEC8262608820093D775 /* LoginController.swift */,
52A591A4266C1B7F0000196C /* LoginController+Animations.swift */,
523FFF2D262631EC00813AAE /* QuizzesController.swift */,
52B826F0266406B6008A47DE /* SearchQuizViewController.swift */,
527AE29426455B1700C23283 /* QuizController.swift */,
Expand Down Expand Up @@ -417,6 +420,7 @@
52092917265122B900637600 /* NetworkService.swift in Sources */,
52B826912662EB42008A47DE /* CoreDataStack.swift in Sources */,
52B826CC26637BA1008A47DE /* QuizRepositoryProtocol.swift in Sources */,
52A591A5266C1B7F0000196C /* LoginController+Animations.swift in Sources */,
52B826ED2663E9A8008A47DE /* CDQuestion+CoreDataClass.swift in Sources */,
52B826DA26639FEF008A47DE /* QuestionViewModel.swift in Sources */,
52B826CF26637CB1008A47DE /* FilterSettings.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion QuizApp/LeaderboardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class LeaderboardController : UIViewController {

networkService.fetchLeaderboard(quizId: quizId) { [weak self] results, error in
guard let results = results, let self = self else { return }
self.results = Array(results.prefix(10))
self.results = Array(results
.sorted(by: {Double($0.score ?? "0")! > Double($1.score ?? "0")!})
.prefix(10))
DispatchQueue.main.async {
self.table.reloadData()
}
Expand Down
86 changes: 86 additions & 0 deletions QuizApp/LoginController+Animations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import UIKit

extension LoginController {
override func viewWillAppear(_ animated: Bool) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a good practice to have life cycle methods (viewDidLoad, viewDidAppear etc.) outside of the original file. Especially not to have a few here and a few there. You could extract this code into a separate method, e.g. prepareForAnimations(), and have that be in this extension and call it from viewWillAppear in the original file.

titleLabel.transform = titleLabel.transform.scaledBy(x: 0, y: 0)
titleLabel.alpha = 0

emailField.transform = emailField.transform.translatedBy(x: -view.frame.width, y: 0)
emailField.alpha = 0

passwordField.transform = passwordField.transform.translatedBy(x: -view.frame.width, y: 0)
passwordField.alpha = 0

loginButton.transform = loginButton.transform.translatedBy(x: -view.frame.width, y: 0)
loginButton.alpha = 0
}

override func viewDidAppear(_ animated: Bool) {
UIView.animate(
withDuration: 1.5,
delay: 0,
options: .curveEaseInOut,
animations: {
self.titleLabel.transform = .identity
self.titleLabel.alpha = 1
})
UIView.animate(
withDuration: 1.5,
delay: 0,
options: .curveEaseInOut,
animations: {
self.emailField.transform = .identity
self.emailField.alpha = 1
})
UIView.animate(
withDuration: 1.5,
delay: 0.25,
options: .curveEaseInOut,
animations: {
self.passwordField.transform = .identity
self.passwordField.alpha = 1
})
UIView.animate(
withDuration: 1.5,
delay: 0.50,
options: .curveEaseInOut,
animations: {
self.loginButton.transform = .identity
self.loginButton.alpha = 1
})
}

func finishLogin(){
UIView.animate(
withDuration: 1.5,
delay: 0,
options: .curveEaseInOut,
animations: {
self.titleLabel.transform = self.titleLabel.transform.translatedBy(x: 0, y: -self.view.frame.height)
})
UIView.animate(
withDuration: 1.5,
delay: 0.25,
options: .curveEaseInOut,
animations: {
self.emailField.transform = self.emailField.transform.translatedBy(x: 0, y: -self.view.frame.height)
})
UIView.animate(
withDuration: 1.5,
delay: 0.50,
options: .curveEaseInOut,
animations: {
self.passwordField.transform = self.passwordField.transform.translatedBy(x: 0, y: -self.view.frame.height)
})
UIView.animate(
withDuration: 1.5,
delay: 0.75,
options: .curveEaseInOut,
animations: {
self.loginButton.transform = self.loginButton.transform.translatedBy(x: 0, y: -self.view.frame.height)
}, completion: {_ in
self.router.showHomeController()
})

}
}
3 changes: 2 additions & 1 deletion QuizApp/LoginController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LoginController: UIViewController {
switch response{
case .success:
DispatchQueue.main.async {
self.router.showHomeController()
self.finishLogin()
}
case .error(let code, _):
if code == 1 {
Expand Down Expand Up @@ -151,6 +151,7 @@ class LoginController: UIViewController {

}
}

}

extension LoginController: UITextFieldDelegate {
Expand Down
2 changes: 0 additions & 2 deletions QuizApp/QuizzesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class QuizzesController: UIViewController {
DispatchQueue.main.async {
self.collectionView.backgroundColor = .white



self.factText.text = "There are \(factNumber) questions that contain the word \"NBA\""

self.collectionView.reloadData()
Expand Down
3 changes: 2 additions & 1 deletion QuizApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window?.makeKeyAndVisible()

let networkDS = QuizNetworkDataSource(networkService: NetworkService())

let coreDataContext = CoreDataStack(modelName: "QuizApp").managedContext
print(coreDataContext.debugDescription)
let coreDataDS = QuizDatabaseDataSource(coreDataContext: coreDataContext)

let quizRepository = QuizRepository(networkDataSource: networkDS, coreDataSource: coreDataDS)
let useCase = QuizUseCase(quizRepository: quizRepository)

Expand Down
8 changes: 4 additions & 4 deletions QuizApp/SearchQuizViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,26 @@ extension SearchQuizViewController: UICollectionViewDelegateFlowLayout {
}

extension SearchQuizViewController: UISearchBarDelegate {
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {


}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
let filter = FilterSettings(searchText: searchBar.text)

filterQuizzes(filter: filter)
collectionView.reloadData()
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
let filter = FilterSettings(searchText: searchBar.text)

filterQuizzes(filter: filter)
collectionView.reloadData()
}

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
let filter = FilterSettings(searchText: searchBar.text)

filterQuizzes(filter: filter)
Expand Down