diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..4138998a Binary files /dev/null and b/.DS_Store differ diff --git a/AppScreens/TheMovieAppMockup.png b/AppScreens/TheMovieAppMockup.png new file mode 100644 index 00000000..3d6dec28 Binary files /dev/null and b/AppScreens/TheMovieAppMockup.png differ diff --git a/README.md b/README.md index 8bb0c38d..b02fb537 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,30 @@ -# Work sample - Application developer - -## Assignment - -- Build an awesome movie app that shows popular and high rated movies. -- Code it for the platform (Android, iOS, web) you applied for or the one you prefer. - -## Requirements - -- Use an open https://developers.themoviedb.org/open source API. Please read the API [Authentication section](https://developers.themoviedb.org/3/getting-started/authentication) to get started. -- Discover most popular and highly rated movies. -- Display the movies with creative look and feel of an app to meet design guidelines for your platform (Material Design etc.). -- Launch a detail screen whenever a particular movie is selected. - -## Examples of bonus features - -- Allow user to save a favorite movie for offline access. -- Allow user to read movie reviews. - -## We expect you to - -- Write clean code. -- Create a responsive design. -- Handle error cases. -- Use the latest libraries and technologies. -- Tested code is a big plus. - -### User experience - -The features of the app might be few, but we expect you to deliver a solution with a high user experience. Imagine this application to be used by real users, with real needs. Make it interesting, fun and intuitive to use. And of course you are allowed to extend your applications functionality. - -### Code - -We expect that the code is of high quality and under source control. Expect the solution to be continuously worked on by other developers and should therefore be easy to understand, adjust and extend. True beauty starts on the inside! - -## Delivery - -Fork the repository, code in your fork and make a pull request when done. A nice commit history describing your work is preferred over squashing it into one commit. -Also send us an e-mail to let us know! - -### Good luck! - ---- - +# The Movie DB + +
+
+ +
+ +# Features +- [x] Home view: Shows list of movies could be filtered by popular or top rated by a segment +- [x] Movie details view: Shows details of a movie including the overview, genres and posters. +- [x] Pagination for movie lists +- [x] Memory caching for filtering: No extra requests are sent to backend when filter is changed if data already exists in memory. +- [x] Architecture: MVVM, protocol oriented, covering SOLID principles, inversion of control (dependency injection via protocols instead of concerete types), error handlings. +- [x] Unit Test demonstration for movie details view model +- [x] UI Test demonstration + + +# Tech discussions + +* Due to my UI/UX design experience we have discussed earlier, I used my budget for both tech and design parts to demonstrate both. + * Due to simplicity of the requirements no complex or advanced networking is been implemented and the shared `URLSession` has been used. Usually I go with using Almofire which was an overkill for this project. + * For the binding between view and viewmodel I have used clousures. + * There is no coordinator implemeted since there is very few navigations in the project. + * Dependency Injection: Please check the view models where there API services are injected as protocols instead of concerete types. So we can easily create fakes for our unit testing purposes. + * I have put a few unit tests to just demonstrate the testability of the the view models but in a real project full unit test coverage for view models is preffered. + * I have put a few UI tests to just demonstrate it but due to shortage of time I did not use mocked data and am testing against real data which should definitely be changed, thus I have put a TODO in code instead of putting more time than the budget. + * I have used storyboard and XIB for creating the most of UI parts but have also created the `LoadingView` programmatically to just demonstrate the preffered way of creating UIs for biggers teams to avoid conflicts. + +## How to run: +Clone the repo and open TheMovieDB.xcodeproj. diff --git a/TheMovieDB/TheMovieDB.xcodeproj/project.pbxproj b/TheMovieDB/TheMovieDB.xcodeproj/project.pbxproj new file mode 100644 index 00000000..94a205fa --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/project.pbxproj @@ -0,0 +1,787 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + 228129CF27649576002A8878 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228129CE27649576002A8878 /* AppDelegate.swift */; }; + 228129D127649576002A8878 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228129D027649576002A8878 /* SceneDelegate.swift */; }; + 228129D327649576002A8878 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228129D227649576002A8878 /* ViewController.swift */; }; + 228129D627649576002A8878 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 228129D427649576002A8878 /* Main.storyboard */; }; + 228129D827649578002A8878 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 228129D727649578002A8878 /* Assets.xcassets */; }; + 228129DB27649578002A8878 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 228129D927649578002A8878 /* LaunchScreen.storyboard */; }; + 228129E627649579002A8878 /* TheMovieDBTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228129E527649579002A8878 /* TheMovieDBTests.swift */; }; + 228129F127649579002A8878 /* TheMovieDBUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 228129F027649579002A8878 /* TheMovieDBUITests.swift */; }; + 22812A0227649B3A002A8878 /* Movie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A0127649B3A002A8878 /* Movie.swift */; }; + 22812A0527649D92002A8878 /* MovieListAPIServiceImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A0427649D92002A8878 /* MovieListAPIServiceImpl.swift */; }; + 22812A0827649E2A002A8878 /* TMError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A0727649E2A002A8878 /* TMError.swift */; }; + 22812A0D2764A090002A8878 /* HTTPRequestImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A0C2764A090002A8878 /* HTTPRequestImpl.swift */; }; + 22812A102764A8C0002A8878 /* MovieListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A0F2764A8C0002A8878 /* MovieListViewModel.swift */; }; + 22812A122764A8EA002A8878 /* MovieListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A112764A8EA002A8878 /* MovieListVC.swift */; }; + 22812A172764BFB2002A8878 /* MovieTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A152764BFB2002A8878 /* MovieTableViewCell.swift */; }; + 22812A182764BFB2002A8878 /* MovieTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22812A162764BFB2002A8878 /* MovieTableViewCell.xib */; }; + 22812A1B2764C990002A8878 /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 22812A1A2764C990002A8878 /* SDWebImage */; }; + 22812A1E2764D0DA002A8878 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A1D2764D0DA002A8878 /* LoadingView.swift */; }; + 22812A202764D252002A8878 /* UIViewController+UIAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A1F2764D252002A8878 /* UIViewController+UIAlert.swift */; }; + 22812A222764DA98002A8878 /* MovieDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A212764DA98002A8878 /* MovieDetails.swift */; }; + 22812A242764DBB0002A8878 /* MovieDetailsAPIServiceImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A232764DBB0002A8878 /* MovieDetailsAPIServiceImpl.swift */; }; + 22812A272764E39E002A8878 /* MovieDetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A262764E39E002A8878 /* MovieDetailsViewModel.swift */; }; + 22812A292764E3B5002A8878 /* MovieDetailsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A282764E3B5002A8878 /* MovieDetailsVC.swift */; }; + 22812A2D2764E4F2002A8878 /* MovieDetailsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A2B2764E4F2002A8878 /* MovieDetailsTableViewCell.swift */; }; + 22812A2E2764E4F2002A8878 /* MovieDetailsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22812A2C2764E4F2002A8878 /* MovieDetailsTableViewCell.xib */; }; + 22812A312764EFAA002A8878 /* MovieDetailsAPIServiceFake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A302764EFAA002A8878 /* MovieDetailsAPIServiceFake.swift */; }; + 22812A332764EFC4002A8878 /* FakeModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22812A322764EFC4002A8878 /* FakeModels.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 228129E227649579002A8878 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 228129C327649576002A8878 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 228129CA27649576002A8878; + remoteInfo = TheMovieDB; + }; + 228129ED27649579002A8878 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 228129C327649576002A8878 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 228129CA27649576002A8878; + remoteInfo = TheMovieDB; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 228129CB27649576002A8878 /* TheMovieDB.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TheMovieDB.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 228129CE27649576002A8878 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 228129D027649576002A8878 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 228129D227649576002A8878 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 228129D527649576002A8878 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 228129D727649578002A8878 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 228129DA27649578002A8878 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 228129DC27649578002A8878 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 228129E127649579002A8878 /* TheMovieDBTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TheMovieDBTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 228129E527649579002A8878 /* TheMovieDBTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TheMovieDBTests.swift; sourceTree = ""; }; + 228129E727649579002A8878 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 228129EC27649579002A8878 /* TheMovieDBUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TheMovieDBUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 228129F027649579002A8878 /* TheMovieDBUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TheMovieDBUITests.swift; sourceTree = ""; }; + 228129F227649579002A8878 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 22812A0127649B3A002A8878 /* Movie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Movie.swift; sourceTree = ""; }; + 22812A0427649D92002A8878 /* MovieListAPIServiceImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieListAPIServiceImpl.swift; sourceTree = ""; }; + 22812A0727649E2A002A8878 /* TMError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TMError.swift; sourceTree = ""; }; + 22812A0C2764A090002A8878 /* HTTPRequestImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPRequestImpl.swift; sourceTree = ""; }; + 22812A0F2764A8C0002A8878 /* MovieListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieListViewModel.swift; sourceTree = ""; }; + 22812A112764A8EA002A8878 /* MovieListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieListVC.swift; sourceTree = ""; }; + 22812A152764BFB2002A8878 /* MovieTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieTableViewCell.swift; sourceTree = ""; }; + 22812A162764BFB2002A8878 /* MovieTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MovieTableViewCell.xib; sourceTree = ""; }; + 22812A1D2764D0DA002A8878 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; + 22812A1F2764D252002A8878 /* UIViewController+UIAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+UIAlert.swift"; sourceTree = ""; }; + 22812A212764DA98002A8878 /* MovieDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetails.swift; sourceTree = ""; }; + 22812A232764DBB0002A8878 /* MovieDetailsAPIServiceImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailsAPIServiceImpl.swift; sourceTree = ""; }; + 22812A262764E39E002A8878 /* MovieDetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailsViewModel.swift; sourceTree = ""; }; + 22812A282764E3B5002A8878 /* MovieDetailsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailsVC.swift; sourceTree = ""; }; + 22812A2B2764E4F2002A8878 /* MovieDetailsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailsTableViewCell.swift; sourceTree = ""; }; + 22812A2C2764E4F2002A8878 /* MovieDetailsTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MovieDetailsTableViewCell.xib; sourceTree = ""; }; + 22812A302764EFAA002A8878 /* MovieDetailsAPIServiceFake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailsAPIServiceFake.swift; sourceTree = ""; }; + 22812A322764EFC4002A8878 /* FakeModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakeModels.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 228129C827649576002A8878 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 22812A1B2764C990002A8878 /* SDWebImage in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129DE27649579002A8878 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129E927649579002A8878 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 228129C227649576002A8878 = { + isa = PBXGroup; + children = ( + 228129CD27649576002A8878 /* TheMovieDB */, + 228129E427649579002A8878 /* TheMovieDBTests */, + 228129EF27649579002A8878 /* TheMovieDBUITests */, + 228129CC27649576002A8878 /* Products */, + ); + sourceTree = ""; + }; + 228129CC27649576002A8878 /* Products */ = { + isa = PBXGroup; + children = ( + 228129CB27649576002A8878 /* TheMovieDB.app */, + 228129E127649579002A8878 /* TheMovieDBTests.xctest */, + 228129EC27649579002A8878 /* TheMovieDBUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 228129CD27649576002A8878 /* TheMovieDB */ = { + isa = PBXGroup; + children = ( + 228129FE27649AAF002A8878 /* App */, + 22812A3427651E4C002A8878 /* Features */, + 228129FF27649ABD002A8878 /* Storyboard */, + 22812A1C2764D0C2002A8878 /* Shared Views */, + 22812A0627649DEC002A8878 /* Utilities */, + 22812A0327649D68002A8878 /* Networking */, + 22812A0027649B26002A8878 /* Models */, + 228129D727649578002A8878 /* Assets.xcassets */, + 228129DC27649578002A8878 /* Info.plist */, + ); + path = TheMovieDB; + sourceTree = ""; + }; + 228129E427649579002A8878 /* TheMovieDBTests */ = { + isa = PBXGroup; + children = ( + 22812A2F2764EF88002A8878 /* Fakes */, + 228129E527649579002A8878 /* TheMovieDBTests.swift */, + 228129E727649579002A8878 /* Info.plist */, + ); + path = TheMovieDBTests; + sourceTree = ""; + }; + 228129EF27649579002A8878 /* TheMovieDBUITests */ = { + isa = PBXGroup; + children = ( + 228129F027649579002A8878 /* TheMovieDBUITests.swift */, + 228129F227649579002A8878 /* Info.plist */, + ); + path = TheMovieDBUITests; + sourceTree = ""; + }; + 228129FE27649AAF002A8878 /* App */ = { + isa = PBXGroup; + children = ( + 228129CE27649576002A8878 /* AppDelegate.swift */, + 228129D027649576002A8878 /* SceneDelegate.swift */, + 228129D227649576002A8878 /* ViewController.swift */, + ); + path = App; + sourceTree = ""; + }; + 228129FF27649ABD002A8878 /* Storyboard */ = { + isa = PBXGroup; + children = ( + 228129D427649576002A8878 /* Main.storyboard */, + 228129D927649578002A8878 /* LaunchScreen.storyboard */, + ); + path = Storyboard; + sourceTree = ""; + }; + 22812A0027649B26002A8878 /* Models */ = { + isa = PBXGroup; + children = ( + 22812A0127649B3A002A8878 /* Movie.swift */, + 22812A212764DA98002A8878 /* MovieDetails.swift */, + ); + path = Models; + sourceTree = ""; + }; + 22812A0327649D68002A8878 /* Networking */ = { + isa = PBXGroup; + children = ( + 22812A0427649D92002A8878 /* MovieListAPIServiceImpl.swift */, + 22812A232764DBB0002A8878 /* MovieDetailsAPIServiceImpl.swift */, + 22812A0C2764A090002A8878 /* HTTPRequestImpl.swift */, + ); + path = Networking; + sourceTree = ""; + }; + 22812A0627649DEC002A8878 /* Utilities */ = { + isa = PBXGroup; + children = ( + 22812A0727649E2A002A8878 /* TMError.swift */, + 22812A1F2764D252002A8878 /* UIViewController+UIAlert.swift */, + ); + path = Utilities; + sourceTree = ""; + }; + 22812A0E2764A8A2002A8878 /* Movie List */ = { + isa = PBXGroup; + children = ( + 22812A142764BF91002A8878 /* MovieCell */, + 22812A112764A8EA002A8878 /* MovieListVC.swift */, + 22812A0F2764A8C0002A8878 /* MovieListViewModel.swift */, + ); + path = "Movie List"; + sourceTree = ""; + }; + 22812A142764BF91002A8878 /* MovieCell */ = { + isa = PBXGroup; + children = ( + 22812A152764BFB2002A8878 /* MovieTableViewCell.swift */, + 22812A162764BFB2002A8878 /* MovieTableViewCell.xib */, + ); + path = MovieCell; + sourceTree = ""; + }; + 22812A1C2764D0C2002A8878 /* Shared Views */ = { + isa = PBXGroup; + children = ( + 22812A1D2764D0DA002A8878 /* LoadingView.swift */, + ); + path = "Shared Views"; + sourceTree = ""; + }; + 22812A252764E368002A8878 /* Movie Details */ = { + isa = PBXGroup; + children = ( + 22812A2A2764E4D6002A8878 /* MovieDetailsCell */, + 22812A282764E3B5002A8878 /* MovieDetailsVC.swift */, + 22812A262764E39E002A8878 /* MovieDetailsViewModel.swift */, + ); + path = "Movie Details"; + sourceTree = ""; + }; + 22812A2A2764E4D6002A8878 /* MovieDetailsCell */ = { + isa = PBXGroup; + children = ( + 22812A2B2764E4F2002A8878 /* MovieDetailsTableViewCell.swift */, + 22812A2C2764E4F2002A8878 /* MovieDetailsTableViewCell.xib */, + ); + path = MovieDetailsCell; + sourceTree = ""; + }; + 22812A2F2764EF88002A8878 /* Fakes */ = { + isa = PBXGroup; + children = ( + 22812A302764EFAA002A8878 /* MovieDetailsAPIServiceFake.swift */, + 22812A322764EFC4002A8878 /* FakeModels.swift */, + ); + path = Fakes; + sourceTree = ""; + }; + 22812A3427651E4C002A8878 /* Features */ = { + isa = PBXGroup; + children = ( + 22812A0E2764A8A2002A8878 /* Movie List */, + 22812A252764E368002A8878 /* Movie Details */, + ); + path = Features; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 228129CA27649576002A8878 /* TheMovieDB */ = { + isa = PBXNativeTarget; + buildConfigurationList = 228129F527649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDB" */; + buildPhases = ( + 228129C727649576002A8878 /* Sources */, + 228129C827649576002A8878 /* Frameworks */, + 228129C927649576002A8878 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = TheMovieDB; + packageProductDependencies = ( + 22812A1A2764C990002A8878 /* SDWebImage */, + ); + productName = TheMovieDB; + productReference = 228129CB27649576002A8878 /* TheMovieDB.app */; + productType = "com.apple.product-type.application"; + }; + 228129E027649579002A8878 /* TheMovieDBTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 228129F827649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDBTests" */; + buildPhases = ( + 228129DD27649579002A8878 /* Sources */, + 228129DE27649579002A8878 /* Frameworks */, + 228129DF27649579002A8878 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 228129E327649579002A8878 /* PBXTargetDependency */, + ); + name = TheMovieDBTests; + productName = TheMovieDBTests; + productReference = 228129E127649579002A8878 /* TheMovieDBTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 228129EB27649579002A8878 /* TheMovieDBUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 228129FB27649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDBUITests" */; + buildPhases = ( + 228129E827649579002A8878 /* Sources */, + 228129E927649579002A8878 /* Frameworks */, + 228129EA27649579002A8878 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 228129EE27649579002A8878 /* PBXTargetDependency */, + ); + name = TheMovieDBUITests; + productName = TheMovieDBUITests; + productReference = 228129EC27649579002A8878 /* TheMovieDBUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 228129C327649576002A8878 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1250; + LastUpgradeCheck = 1250; + TargetAttributes = { + 228129CA27649576002A8878 = { + CreatedOnToolsVersion = 12.5.1; + }; + 228129E027649579002A8878 = { + CreatedOnToolsVersion = 12.5.1; + TestTargetID = 228129CA27649576002A8878; + }; + 228129EB27649579002A8878 = { + CreatedOnToolsVersion = 12.5.1; + TestTargetID = 228129CA27649576002A8878; + }; + }; + }; + buildConfigurationList = 228129C627649576002A8878 /* Build configuration list for PBXProject "TheMovieDB" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 228129C227649576002A8878; + packageReferences = ( + 22812A192764C990002A8878 /* XCRemoteSwiftPackageReference "SDWebImage" */, + ); + productRefGroup = 228129CC27649576002A8878 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 228129CA27649576002A8878 /* TheMovieDB */, + 228129E027649579002A8878 /* TheMovieDBTests */, + 228129EB27649579002A8878 /* TheMovieDBUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 228129C927649576002A8878 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 228129DB27649578002A8878 /* LaunchScreen.storyboard in Resources */, + 228129D827649578002A8878 /* Assets.xcassets in Resources */, + 22812A182764BFB2002A8878 /* MovieTableViewCell.xib in Resources */, + 22812A2E2764E4F2002A8878 /* MovieDetailsTableViewCell.xib in Resources */, + 228129D627649576002A8878 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129DF27649579002A8878 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129EA27649579002A8878 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 228129C727649576002A8878 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 22812A172764BFB2002A8878 /* MovieTableViewCell.swift in Sources */, + 22812A0527649D92002A8878 /* MovieListAPIServiceImpl.swift in Sources */, + 22812A2D2764E4F2002A8878 /* MovieDetailsTableViewCell.swift in Sources */, + 22812A0827649E2A002A8878 /* TMError.swift in Sources */, + 22812A202764D252002A8878 /* UIViewController+UIAlert.swift in Sources */, + 22812A222764DA98002A8878 /* MovieDetails.swift in Sources */, + 22812A272764E39E002A8878 /* MovieDetailsViewModel.swift in Sources */, + 22812A1E2764D0DA002A8878 /* LoadingView.swift in Sources */, + 22812A122764A8EA002A8878 /* MovieListVC.swift in Sources */, + 228129D327649576002A8878 /* ViewController.swift in Sources */, + 22812A242764DBB0002A8878 /* MovieDetailsAPIServiceImpl.swift in Sources */, + 22812A102764A8C0002A8878 /* MovieListViewModel.swift in Sources */, + 228129CF27649576002A8878 /* AppDelegate.swift in Sources */, + 22812A0D2764A090002A8878 /* HTTPRequestImpl.swift in Sources */, + 22812A0227649B3A002A8878 /* Movie.swift in Sources */, + 22812A292764E3B5002A8878 /* MovieDetailsVC.swift in Sources */, + 228129D127649576002A8878 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129DD27649579002A8878 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 22812A312764EFAA002A8878 /* MovieDetailsAPIServiceFake.swift in Sources */, + 22812A332764EFC4002A8878 /* FakeModels.swift in Sources */, + 228129E627649579002A8878 /* TheMovieDBTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 228129E827649579002A8878 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 228129F127649579002A8878 /* TheMovieDBUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 228129E327649579002A8878 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 228129CA27649576002A8878 /* TheMovieDB */; + targetProxy = 228129E227649579002A8878 /* PBXContainerItemProxy */; + }; + 228129EE27649579002A8878 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 228129CA27649576002A8878 /* TheMovieDB */; + targetProxy = 228129ED27649579002A8878 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 228129D427649576002A8878 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 228129D527649576002A8878 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 228129D927649578002A8878 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 228129DA27649578002A8878 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 228129F327649579002A8878 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 228129F427649579002A8878 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 228129F627649579002A8878 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDB/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDB; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; + }; + name = Debug; + }; + 228129F727649579002A8878 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDB/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDB; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; + }; + name = Release; + }; + 228129F927649579002A8878 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDBTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TheMovieDB.app/TheMovieDB"; + }; + name = Debug; + }; + 228129FA27649579002A8878 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDBTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDBTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TheMovieDB.app/TheMovieDB"; + }; + name = Release; + }; + 228129FC27649579002A8878 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDBUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDBUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = TheMovieDB; + }; + name = Debug; + }; + 228129FD27649579002A8878 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = TheMovieDBUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.AliNaranjeeSani.TheMovieDBUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = TheMovieDB; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 228129C627649576002A8878 /* Build configuration list for PBXProject "TheMovieDB" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 228129F327649579002A8878 /* Debug */, + 228129F427649579002A8878 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 228129F527649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDB" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 228129F627649579002A8878 /* Debug */, + 228129F727649579002A8878 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 228129F827649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDBTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 228129F927649579002A8878 /* Debug */, + 228129FA27649579002A8878 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 228129FB27649579002A8878 /* Build configuration list for PBXNativeTarget "TheMovieDBUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 228129FC27649579002A8878 /* Debug */, + 228129FD27649579002A8878 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 22812A192764C990002A8878 /* XCRemoteSwiftPackageReference "SDWebImage" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/SDWebImage/SDWebImage.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 5.12.1; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 22812A1A2764C990002A8878 /* SDWebImage */ = { + isa = XCSwiftPackageProductDependency; + package = 22812A192764C990002A8878 /* XCRemoteSwiftPackageReference "SDWebImage" */; + productName = SDWebImage; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 228129C327649576002A8878 /* Project object */; +} diff --git a/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..57bbad42 --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "SDWebImage", + "repositoryURL": "https://github.com/SDWebImage/SDWebImage.git", + "state": { + "branch": null, + "revision": "a72df4849408da7e5d3c1b586797b7c601c41d1b", + "version": "5.12.1" + } + } + ] + }, + "version": 1 +} diff --git a/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcuserdata/Sani.xcuserdatad/UserInterfaceState.xcuserstate b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcuserdata/Sani.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..65bb2374 Binary files /dev/null and b/TheMovieDB/TheMovieDB.xcodeproj/project.xcworkspace/xcuserdata/Sani.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..c35e7a73 --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcschemes/xcschememanagement.plist b/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..3a4ccaac --- /dev/null +++ b/TheMovieDB/TheMovieDB.xcodeproj/xcuserdata/Sani.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + TheMovieDB.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/TheMovieDB/TheMovieDB/App/AppDelegate.swift b/TheMovieDB/TheMovieDB/App/AppDelegate.swift new file mode 100644 index 00000000..97667f58 --- /dev/null +++ b/TheMovieDB/TheMovieDB/App/AppDelegate.swift @@ -0,0 +1,36 @@ +// +// AppDelegate.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/TheMovieDB/TheMovieDB/App/SceneDelegate.swift b/TheMovieDB/TheMovieDB/App/SceneDelegate.swift new file mode 100644 index 00000000..4cdda12c --- /dev/null +++ b/TheMovieDB/TheMovieDB/App/SceneDelegate.swift @@ -0,0 +1,52 @@ +// +// SceneDelegate.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/TheMovieDB/TheMovieDB/App/ViewController.swift b/TheMovieDB/TheMovieDB/App/ViewController.swift new file mode 100644 index 00000000..478a224c --- /dev/null +++ b/TheMovieDB/TheMovieDB/App/ViewController.swift @@ -0,0 +1,19 @@ +// +// ViewController.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +class ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + } + + +} + diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AccentColor.colorset/Contents.json b/TheMovieDB/TheMovieDB/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Appicon-2.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Appicon-2.png new file mode 100644 index 00000000..8b48a3ef Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Appicon-2.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Contents.json b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..0f97677c --- /dev/null +++ b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,123 @@ +{ + "images" : [ + { + "filename" : "Icon-Spotlight-41.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "filename" : "Icon-61.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "filename" : "Icon-Small.png", + "idiom" : "iphone", + "scale" : "1x", + "size" : "29x29" + }, + { + "filename" : "Icon-Small@2x.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "filename" : "Icon-Small@3x.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "filename" : "Icon-Spotlight-40@2x.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "filename" : "Icon-Spotlight-40@3x.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "1x", + "size" : "57x57" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "57x57" + }, + { + "filename" : "Icon-60@2x.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "filename" : "Icon-60@3x.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "filename" : "Appicon-2.png", + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png new file mode 100644 index 00000000..d19f8c83 Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png new file mode 100644 index 00000000..697b55ca Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-61.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-61.png new file mode 100644 index 00000000..2f5a1fa4 Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-61.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small.png new file mode 100644 index 00000000..9478f568 Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png new file mode 100644 index 00000000..55afd6ea Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png new file mode 100644 index 00000000..9908831a Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@2x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@2x.png new file mode 100644 index 00000000..d55b7e00 Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@2x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@3x.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@3x.png new file mode 100644 index 00000000..dddc7c83 Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-40@3x.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-41.png b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-41.png new file mode 100644 index 00000000..eeadb9de Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/AppIcon.appiconset/Icon-Spotlight-41.png differ diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/Contents.json b/TheMovieDB/TheMovieDB/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/Contents.json b/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/Contents.json new file mode 100644 index 00000000..d7a6ec89 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "placeholder.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/placeholder.png b/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/placeholder.png new file mode 100644 index 00000000..7911c57e Binary files /dev/null and b/TheMovieDB/TheMovieDB/Assets.xcassets/placeholder.imageset/placeholder.png differ diff --git a/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.swift b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.swift new file mode 100644 index 00000000..7897ecc6 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.swift @@ -0,0 +1,58 @@ +// +// MovieDetailsTableViewCell.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +class MovieDetailsTableViewCell: UITableViewCell { + + + @IBOutlet private weak var backdropImageView: UIImageView! + @IBOutlet private weak var posterImageView: UIImageView! + @IBOutlet private weak var titleLabel: UILabel! + @IBOutlet private weak var overviewLabel: UILabel! + @IBOutlet private weak var genresLabel: UILabel! + @IBOutlet private weak var titleView: UIView! + @IBOutlet private weak var genresView: UIView! + + static let identifier = "MovieDetailsCell" + + override func awakeFromNib() { + super.awakeFromNib() + configureUI() + } + + func configureUI() { + self.layoutIfNeeded() + titleView.layer.cornerRadius = 15 + genresView.layer.cornerRadius = 15 + + posterImageView.layer.cornerRadius = 12 + posterImageView.layer.borderWidth = 3 + posterImageView.layer.borderColor = UIColor.white.cgColor + posterImageView.layer.masksToBounds = true + + backdropImageView.layer.cornerRadius = 15 + backdropImageView.layer.masksToBounds = true + } + + /// Configure your cell + /// - Parameter movieDatails: The data model required to configue the cell + func configure(movieDatails: MovieDetails) { + + titleLabel.text = movieDatails.title + overviewLabel.text = movieDatails.overview + + posterImageView.sd_setImage(with: movieDatails.posterURL, placeholderImage: UIImage(named: "placeholder.png")) + backdropImageView.sd_setImage(with: movieDatails.backdropURL, placeholderImage: UIImage(named: "placeholder.png")) + + let genres: String = movieDatails.genres.map { $0.name } + .joined(separator: ", ") + + genresLabel.text = genres + } + +} diff --git a/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.xib b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.xib new file mode 100644 index 00000000..87a7174e --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsCell/MovieDetailsTableViewCell.xib @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsVC.swift b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsVC.swift new file mode 100644 index 00000000..2607e215 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsVC.swift @@ -0,0 +1,77 @@ +// +// MovieDetailsVC.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +class MovieDetailsVC: UIViewController { + + @IBOutlet weak var moviesTableView: UITableView! + @IBOutlet weak var loadingView: LoadingView! + + var viewModel: MovieDetailsViewModel! + + private var loading = UIActivityIndicatorView(style: .large) + + override func viewDidLoad() { + + super.viewDidLoad() + // tableview + moviesTableView.dataSource = self + + registerMovieCell() + bind() + viewModel.viewDidLoad() + } + + func registerMovieCell() { + //FIXME: use R library + let movieDetailsCell = UINib(nibName: "MovieDetailsTableViewCell", bundle: nil) + self.moviesTableView.register(movieDetailsCell, forCellReuseIdentifier: MovieDetailsTableViewCell.identifier) + } + + func bind() { + viewModel.onShouldReloadTableView = { + self.moviesTableView.reloadData() + } + + viewModel.onLoadingStateShouldChange = { [weak self] state in + switch state { + case .loading: + self?.loadingView.unHide() + case .loaded: + self?.loadingView.hide() + case .failed(let error): + self?.loadingView.hide() + self?.showErrorIfDisplayable(error: error) + } + } + } +} + +extension MovieDetailsVC : UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + + return viewModel.numberOfRows + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let cell: MovieDetailsTableViewCell = tableView.dequeueReusableCell(withIdentifier: MovieDetailsTableViewCell.identifier, for: indexPath) as? MovieDetailsTableViewCell else { + let cell: UITableViewCell = UITableViewCell() + return cell + } + + guard let cellData = viewModel.getCellData(for: indexPath) else { + return cell + } + cell.configure(movieDatails: cellData) + + cell.selectionStyle = .none + return cell + } +} diff --git a/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsViewModel.swift b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsViewModel.swift new file mode 100644 index 00000000..61d67131 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie Details/MovieDetailsViewModel.swift @@ -0,0 +1,63 @@ +// +// MovieDetailsViewModel.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation +import UIKit + +class MovieDetailsViewModel { + + var onShouldReloadTableView: (() -> Void)? + var onLoadingStateShouldChange: ((LoadingState) -> Void)? + + var movieId: Int + + var movieDetails: MovieDetails? { + didSet { + onShouldReloadTableView?() + } + } + + var numberOfRows: Int { + guard self.movieDetails != nil else { + return 0 + } + return 1 + } + + private var MovieDetailsService: MovieDetailsAPIService + + init(MovieDetailsService: MovieDetailsAPIService, movieId: Int) { + self.MovieDetailsService = MovieDetailsService + self.movieId = movieId + } + + private func fetchMovieDetails(withID id: Int){ + onLoadingStateShouldChange?(.loading) + MovieDetailsService.getMovieDetails(for: id) { [weak self] result in + guard let self = self else { return } + switch result { + case .success(let response): + self.movieDetails = response + self.onLoadingStateShouldChange?(.loaded) + case .failure(let error): + self.onLoadingStateShouldChange?(.failed(error)) + } + } + } + + func getCellData(for _: IndexPath) -> MovieDetails? { + // We have only one cell at the moment + return self.movieDetails + } +} + +extension MovieDetailsViewModel { + + func viewDidLoad() { + fetchMovieDetails(withID: movieId) + } +} diff --git a/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.swift b/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.swift new file mode 100644 index 00000000..650dee1f --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.swift @@ -0,0 +1,53 @@ +// +// MovieTableViewCell.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit +import SDWebImage + +class MovieTableViewCell: UITableViewCell { + + @IBOutlet private weak var titleLabel: UILabel! + @IBOutlet private weak var posterImageView: UIImageView! + @IBOutlet private weak var releaseDateLabel: UILabel! + @IBOutlet private weak var rateLabel: UILabel! + @IBOutlet private weak var roundedView: UIView! + + static let identifier = "MovieCell" + + override func awakeFromNib() { + super.awakeFromNib() + configureUI() + } + + /// Configure your cell + /// - Parameter movieData: The data model required to configue the cell + func configure(movieData: Movie) { + + titleLabel.text = movieData.title + releaseDateLabel.text = movieData.releaseDate.releaseFormattedDate + rateLabel.text = "\(movieData.voteAverage)" + posterImageView.sd_setImage(with: movieData.posterURL, placeholderImage: UIImage(named: "placeholder.png")) + } + + // MARK: - Private + + private func configureUI() { + self.layoutIfNeeded() + roundedView.layer.cornerRadius = 15 + posterImageView.layer.cornerRadius = 12 + posterImageView.layer.masksToBounds = true + } +} + +private extension Date { + var releaseFormattedDate: String { + let dateformat = DateFormatter() + dateformat.dateFormat = "MMM d, yyyy" + return dateformat.string(from: self) + } +} + diff --git a/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.xib b/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.xib new file mode 100644 index 00000000..7b602528 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie List/MovieCell/MovieTableViewCell.xib @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TheMovieDB/TheMovieDB/Features/Movie List/MovieListVC.swift b/TheMovieDB/TheMovieDB/Features/Movie List/MovieListVC.swift new file mode 100644 index 00000000..b36c210c --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie List/MovieListVC.swift @@ -0,0 +1,114 @@ +// +// MovieListVC.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +class MovieListVC: UIViewController { + + @IBOutlet weak var moviesTableView: UITableView! + @IBOutlet weak var filterSegment: UISegmentedControl! + @IBOutlet weak var loadingView: LoadingView! + + var viewModel: MoviesListViewModel! + + override func viewDidLoad() { + + super.viewDidLoad() + + // tableview + moviesTableView.dataSource = self + moviesTableView.delegate = self + + viewModel = MoviesListViewModel(movieListServices: MovieListAPIServiceImpl(httpRequest: HTTPRequestImpl())) + registerMovieCell() + bind() + viewModel.viewDidLoad() + } + + func registerMovieCell() { + let movieCell = UINib(nibName: "MovieTableViewCell", bundle: nil) + self.moviesTableView.register(movieCell, forCellReuseIdentifier: MovieTableViewCell.identifier) + } + + func bind() { + viewModel.onShouldReloadTableView = { [weak self] in + self?.moviesTableView.reloadData() + } + viewModel.onLoadingStateShouldChange = { [weak self] state in + switch state { + case .loading: + self?.loadingView.unHide() + case .loaded: + self?.loadingView.hide() + case .failed(let error): + self?.loadingView.hide() + self?.showErrorIfDisplayable(error: error) + } + } + viewModel.onShowDetailViewController = { viewModel in + + let storyboard = UIStoryboard(name: "Main", bundle: nil) + guard let movieDetailsVC = storyboard.instantiateViewController(withIdentifier: "MovieDetailsVC") as? MovieDetailsVC else { + assertionFailure("Failed to create movie details view controller") + return + } + movieDetailsVC.viewModel = viewModel + self.navigationController?.pushViewController(movieDetailsVC, animated: true) + } + } + + @IBAction func filterSegmentChanged(_ sender: Any) { + + viewModel.movieSegmentDidChange(selectedSegmentIndex: self.filterSegment.selectedSegmentIndex) + } + +} + +//MARK: - Tableview DataSource +extension MovieListVC : UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return viewModel.numberOfRows + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let cell:MovieTableViewCell = tableView.dequeueReusableCell(withIdentifier: MovieTableViewCell.identifier, + for: indexPath) as? MovieTableViewCell else { + let cell: UITableViewCell = UITableViewCell() + return cell + } + + guard let cellData = viewModel.getCellData(for: indexPath) else { + return cell + } + cell.configure(movieData: cellData) + + cell.selectionStyle = .none + return cell + } +} + +//MARK: - Tableview Delegate +extension MovieListVC : UITableViewDelegate { + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + viewModel.didSelectMovie(at: indexPath) + } +} + +//MARK: - UIScrollViewDelegate +extension MovieListVC : UIScrollViewDelegate { + func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + let currentOffset = scrollView.contentOffset.y + let maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height + + if maximumOffset - currentOffset <= 20.0 { + viewModel.listReachedBottom() + } + } +} diff --git a/TheMovieDB/TheMovieDB/Features/Movie List/MovieListViewModel.swift b/TheMovieDB/TheMovieDB/Features/Movie List/MovieListViewModel.swift new file mode 100644 index 00000000..ba145888 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Features/Movie List/MovieListViewModel.swift @@ -0,0 +1,166 @@ +// +// MovieListViewModel.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation +import UIKit + +enum LoadingState { + case loading + case loaded + case failed(TMSError) +} + +class MoviesListViewModel { + + var onShouldReloadTableView: (() -> Void)? + var onLoadingStateShouldChange: ((LoadingState) -> Void)? + var onShowDetailViewController: ((MovieDetailsViewModel) -> Void)? + + typealias PopularInfo = (nextPage: Int, totalPage: Int) + typealias TopRatedInfo = (nextPage: Int, totalPage: Int) + private var listConfig: (popular: PopularInfo, topRated: TopRatedInfo) + + var listType: MovieListType + + var popularMoviesArray: [Movie] = [] { + didSet { + onShouldReloadTableView?() + } + } + var topRatedMoviesArray: [Movie] = [] { + didSet { + onShouldReloadTableView?() + } + } + + private var movieListService : MovieListAPIService! + + init(movieListServices: MovieListAPIService) { + self.movieListService = movieListServices + // Defaults + listConfig = ((1,1), (1,1)) + self.listType = .popular + } + + private func didSuccessfullyReceiveResponse(response: MoviesResponse) { + + switch listType { + case .popular: + self.listConfig.popular.nextPage = self.listConfig.popular.nextPage + 1 + self.listConfig.popular.totalPage = response.totalPages + self.popularMoviesArray.append(contentsOf: response.results) + case .topRated: + self.listConfig.topRated.nextPage = self.listConfig.topRated.nextPage + 1 + self.listConfig.topRated.totalPage = response.totalPages + self.topRatedMoviesArray.append(contentsOf: response.results) + } + } + + private func fetchMovieList() { + + onLoadingStateShouldChange?(.loading) + + let pageNumber = (listType == .popular) ? listConfig.popular.nextPage : listConfig.topRated.nextPage + movieListService.getMoviesList(for: listType, pageNumber: pageNumber ) { [weak self] result in + + switch result { + case .success(let response): + self?.didSuccessfullyReceiveResponse(response: response) + self?.onLoadingStateShouldChange?(.loaded) + case .failure(let error): + self?.onLoadingStateShouldChange?(.failed(error)) + } + } + } + + private func shouldLoadMorePages() -> Bool { + + return (listType == .popular) ? + listConfig.popular.nextPage <= listConfig.popular.totalPage: + listConfig.topRated.nextPage <= listConfig.topRated.totalPage + } +} + +// MARK: - View Actions + +extension MoviesListViewModel { + + func viewDidLoad(){ + fetchMovieList() + } + + func didSelectMovie(at indexPath: IndexPath) { + + var selectedMovieId: Int? + switch self.listType + { + case .popular: + selectedMovieId = self.popularMoviesArray[indexPath.row].id + case .topRated: + selectedMovieId = self.topRatedMoviesArray[indexPath.row].id + } + + guard let selectedMovieId = selectedMovieId else { + assertionFailure("Internal failure: MovieId not found") + return + } + + let movieDetailsVM = MovieDetailsViewModel(MovieDetailsService: MovieDetailsAPIServiceImpl(httpRequest: HTTPRequestImpl()), movieId: selectedMovieId) + onShowDetailViewController?(movieDetailsVM) + } + + func movieSegmentDidChange(selectedSegmentIndex: Int) { + + switch selectedSegmentIndex + { + case 0: + self.listType = .popular + guard self.popularMoviesArray.count == 0 else { + onShouldReloadTableView?() + return + } + case 1: + self.listType = .topRated + guard self.topRatedMoviesArray.count == 0 else { + onShouldReloadTableView?() + return + } + default: () + } + + fetchMovieList() + } + + func getCellData(for indexPath: IndexPath) -> Movie? { + + switch self.listType + { + case .popular: + return self.popularMoviesArray[indexPath.row] + case .topRated: + return self.topRatedMoviesArray[indexPath.row] + } + } + + var numberOfRows: Int { + + switch self.listType + { + case .popular: + return self.popularMoviesArray.count + case .topRated: + return self.topRatedMoviesArray.count + } + } + + func listReachedBottom(){ + guard shouldLoadMorePages() else { return } + + fetchMovieList() + } + +} diff --git a/TheMovieDB/TheMovieDB/Info.plist b/TheMovieDB/TheMovieDB/Info.plist new file mode 100644 index 00000000..2b43ebcf --- /dev/null +++ b/TheMovieDB/TheMovieDB/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/TheMovieDB/TheMovieDB/Models/Movie.swift b/TheMovieDB/TheMovieDB/Models/Movie.swift new file mode 100644 index 00000000..e4aa6c7b --- /dev/null +++ b/TheMovieDB/TheMovieDB/Models/Movie.swift @@ -0,0 +1,28 @@ +// +// Movie.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +// MARK: - Movie +struct Movie: Decodable { + let id: Int + let title: String + let voteAverage: Double + let releaseDate: Date + private let posterPath: String? + + var posterURL: URL? { + guard let path = posterPath else { return nil } + return URL(string: "https://image.tmdb.org/t/p/w500\(path)") + } +} + +// MARK: - MoviesResponse +struct MoviesResponse: Decodable { + let totalPages : Int + let results: [Movie] +} diff --git a/TheMovieDB/TheMovieDB/Models/MovieDetails.swift b/TheMovieDB/TheMovieDB/Models/MovieDetails.swift new file mode 100644 index 00000000..6f3f614b --- /dev/null +++ b/TheMovieDB/TheMovieDB/Models/MovieDetails.swift @@ -0,0 +1,36 @@ +// +// MovieDetails.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +struct MovieDetails: Decodable, Equatable { + + let id: Int + let genres: [Genre] + let overview: String? + let title: String + let posterPath: String? + let backdropPath: String? + + private var baseImageUrl: String { + return "https://image.tmdb.org/t/p/original" + } + + var posterURL: URL? { + guard let path = posterPath else { return nil } + return URL(string: "\(baseImageUrl)\(path)") + } + var backdropURL: URL? { + guard let path = backdropPath else { return nil } + return URL(string: "\(baseImageUrl)\(path)") + } +} + +struct Genre: Decodable, Equatable { + let id: Int + let name: String +} diff --git a/TheMovieDB/TheMovieDB/Networking/HTTPRequestImpl.swift b/TheMovieDB/TheMovieDB/Networking/HTTPRequestImpl.swift new file mode 100644 index 00000000..5dc19c5b --- /dev/null +++ b/TheMovieDB/TheMovieDB/Networking/HTTPRequestImpl.swift @@ -0,0 +1,91 @@ +// +// HTTPRequestImpl.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +struct MovieEndpointBuilder { + private static let baseURL = "https://api.themoviedb.org" + private static let apiVersion = "3" + + /// Create a movie endpoint + /// - Parameter pathComponent: all the path components that needs to be added to the endpoint. + /// - Returns: Movie endpoint that containts all required default path components and passed path components + static func movieEndpoint(pathComponents: [String]? = nil) -> URL { + var url = URL(string: baseURL)! + url.appendPathComponent(apiVersion) + url.appendPathComponent("movie") + _ = pathComponents?.map { url.appendPathComponent($0)} + return url + } +} + +protocol HTTPRequest { + func get(from url: URL, params: [String: String]?, returnType: T.Type, completed: @escaping (Result) -> Void) +} + +final class HTTPRequestImpl: HTTPRequest { + + let apiKey = "26f394bff527625c8ae37bcfc6fa720d" + + private lazy var jsonDecoder: JSONDecoder = { + let dateFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + return dateFormatter + }() + + let jsonDecoder = JSONDecoder() + jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase + jsonDecoder.dateDecodingStrategy = .formatted(dateFormatter) + return jsonDecoder + }() + + func get(from url: URL, params: [String: String]?, returnType: T.Type, completed: @escaping (Result) -> Void) where T : Decodable { + + let urlComponents = NSURLComponents(string: url.absoluteString) + + // Add api key to all requests + urlComponents?.queryItems = [ + URLQueryItem(name: "api_key", value: self.apiKey) + ] + + // Add params if any + _ = params?.map { key, value in + urlComponents?.queryItems?.append(URLQueryItem(name: key, value: value)) + } + + guard let parameterizedURL = urlComponents?.url else { + completed(.failure(.invalidURL)) + return + } + + let task = URLSession.shared.dataTask(with: parameterizedURL) { data, response, error in + + DispatchQueue.main.async { + + if let error = error { + completed(.failure(.apiError(error))) + return + } + + guard let data = data else { + completed(.failure(.noData)) + return + } + + do { + let decodedResponse = try self.jsonDecoder.decode(returnType, from: data) + completed(.success(decodedResponse)) + } + catch { + completed(.failure(.invalidResponse)) + } + } + } + task.resume() + } +} diff --git a/TheMovieDB/TheMovieDB/Networking/MovieDetailsAPIServiceImpl.swift b/TheMovieDB/TheMovieDB/Networking/MovieDetailsAPIServiceImpl.swift new file mode 100644 index 00000000..7f1a3d72 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Networking/MovieDetailsAPIServiceImpl.swift @@ -0,0 +1,33 @@ +// +// MovieDetailsAPIServiceImpl.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +protocol MovieDetailsAPIService { + func getMovieDetails(for movieId: Int, completed: @escaping (Result) -> Void ) +} + +class MovieDetailsAPIServiceImpl: MovieDetailsAPIService { + private var httpRequest: HTTPRequest + + init(httpRequest: HTTPRequest) { + self.httpRequest = httpRequest + } + + func getMovieDetails(for movieId: Int, completed: @escaping (Result) -> Void ) { + + httpRequest.get(from: MovieEndpointBuilder.movieEndpoint(pathComponents: [String(movieId)]), params: nil, returnType: MovieDetails.self) { result in + + switch result { + case .success(let movieDetails): + completed(.success(movieDetails)) + case .failure(let error): + completed(.failure(error)) + } + } + } +} diff --git a/TheMovieDB/TheMovieDB/Networking/MovieListAPIServiceImpl.swift b/TheMovieDB/TheMovieDB/Networking/MovieListAPIServiceImpl.swift new file mode 100644 index 00000000..f11c6e4e --- /dev/null +++ b/TheMovieDB/TheMovieDB/Networking/MovieListAPIServiceImpl.swift @@ -0,0 +1,42 @@ +// +// MovieListAPIServiceImpl.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +protocol MovieListAPIService { + func getMoviesList(for type: MovieListType, pageNumber:Int, completed: @escaping (Result) -> Void) +} + +final class MovieListAPIServiceImpl: MovieListAPIService { + + private var httpRequest: HTTPRequest + + init(httpRequest: HTTPRequest) { + self.httpRequest = httpRequest + } + + func getMoviesList(for type: MovieListType, pageNumber page:Int, completed: @escaping (Result) -> Void ) { + let params: [String: String] = ["page": String(page)] + + httpRequest.get(from: MovieEndpointBuilder.movieEndpoint(pathComponents: [type.rawValue]), params: params, returnType: MoviesResponse.self) { result in + switch result { + case .success(let movieResponse): + completed(.success(movieResponse)) + case .failure(let error): + completed(.failure(error)) + } + } + } +} + +// MARK: - MovieListType +enum MovieListType: String { + + case topRated = "top_rated" + case popular + +} diff --git a/TheMovieDB/TheMovieDB/Shared Views/LoadingView.swift b/TheMovieDB/TheMovieDB/Shared Views/LoadingView.swift new file mode 100644 index 00000000..4523288d --- /dev/null +++ b/TheMovieDB/TheMovieDB/Shared Views/LoadingView.swift @@ -0,0 +1,49 @@ +// +// LoadingView.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation +import UIKit + +final class LoadingView: UIView { + private var loading = UIActivityIndicatorView(style: .large) + + override init(frame: CGRect) { + super.init(frame: frame) + setupView() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + setupView() + } + + private func setupView() { + self.layer.cornerRadius = 15 + loading.translatesAutoresizingMaskIntoConstraints = false + loading.startAnimating() + self.addSubview(loading) + + loading.translatesAutoresizingMaskIntoConstraints = false + let horizontalConstraint = loading + .centerXAnchor.constraint(equalTo: self.centerXAnchor) + let verticalConstraint = loading + .centerYAnchor.constraint(equalTo: self.centerYAnchor) + NSLayoutConstraint.activate([horizontalConstraint, verticalConstraint]) + } + + func hide() { + self.loading.stopAnimating() + self.loading.isHidden = true + self.isHidden = true + } + + func unHide() { + self.loading.startAnimating() + self.loading.isHidden = false + self.isHidden = false + } +} diff --git a/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/LaunchScreen.storyboard b/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..865e9329 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/Main.storyboard b/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/Main.storyboard new file mode 100644 index 00000000..98f3e7d5 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Storyboard/Base.lproj/Main.storyboard @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TheMovieDB/TheMovieDB/Utilities/TMError.swift b/TheMovieDB/TheMovieDB/Utilities/TMError.swift new file mode 100644 index 00000000..ef8fd9c8 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Utilities/TMError.swift @@ -0,0 +1,34 @@ +// +// TMError.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation + +enum TMSError: Error, CustomNSError { + + case apiError(Error) + case invalidResponse + case noData + case invalidURL + + var localizedDescription: String { + switch self { + case .apiError(let error): return error.localizedDescription + case .invalidResponse: return "Invalid response" + case .noData: return "No data found" + case .invalidURL: return "The provided URL is invalid" + } + } + + var isDisplayable: Bool { + switch self { + case .apiError: + return true + default: + return false + } + } +} diff --git a/TheMovieDB/TheMovieDB/Utilities/UIViewController+UIAlert.swift b/TheMovieDB/TheMovieDB/Utilities/UIViewController+UIAlert.swift new file mode 100644 index 00000000..fc2dc511 --- /dev/null +++ b/TheMovieDB/TheMovieDB/Utilities/UIViewController+UIAlert.swift @@ -0,0 +1,26 @@ +// +// UIViewController+UIAlert.swift +// TheMovieDB +// +// Created by Ali Sani on 12/11/21. +// + +import UIKit + +extension UIViewController { + + func showErrorIfDisplayable(error: TMSError) { + if error.isDisplayable { + let alert = UIAlertController(title: "Oops!", + message: error.localizedDescription, + preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: "OK", + style: .default, + handler: nil) + ) + + self.present(alert, animated: true, completion: nil) + } + } +} diff --git a/TheMovieDB/TheMovieDBTests/Fakes/FakeModels.swift b/TheMovieDB/TheMovieDBTests/Fakes/FakeModels.swift new file mode 100644 index 00000000..8be3ee06 --- /dev/null +++ b/TheMovieDB/TheMovieDBTests/Fakes/FakeModels.swift @@ -0,0 +1,21 @@ +// +// FakeModels.swift +// TheMovieDBTests +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation +@testable import TheMovieDB + +final class FakeModels { + + static var FakeMovieDetails: MovieDetails = { + return MovieDetails(id: 1, + genres: [], + overview: nil, + title: "title", + posterPath: nil, + backdropPath: nil) + }() +} diff --git a/TheMovieDB/TheMovieDBTests/Fakes/MovieDetailsAPIServiceFake.swift b/TheMovieDB/TheMovieDBTests/Fakes/MovieDetailsAPIServiceFake.swift new file mode 100644 index 00000000..bba07b25 --- /dev/null +++ b/TheMovieDB/TheMovieDBTests/Fakes/MovieDetailsAPIServiceFake.swift @@ -0,0 +1,15 @@ +// +// MovieDetailsAPIServiceFake.swift +// TheMovieDBTests +// +// Created by Ali Sani on 12/11/21. +// + +import Foundation +@testable import TheMovieDB + +final class MovieDetailsAPIServiceFake: MovieDetailsAPIService { + func getMovieDetails(for movieId: Int, completed: @escaping (Result) -> Void) { + completed(.success(FakeModels.FakeMovieDetails)) + } +} diff --git a/TheMovieDB/TheMovieDBTests/Info.plist b/TheMovieDB/TheMovieDBTests/Info.plist new file mode 100644 index 00000000..64d65ca4 --- /dev/null +++ b/TheMovieDB/TheMovieDBTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/TheMovieDB/TheMovieDBTests/TheMovieDBTests.swift b/TheMovieDB/TheMovieDBTests/TheMovieDBTests.swift new file mode 100644 index 00000000..52b1e7c9 --- /dev/null +++ b/TheMovieDB/TheMovieDBTests/TheMovieDBTests.swift @@ -0,0 +1,57 @@ +// +// TheMovieDBTests.swift +// TheMovieDBTests +// +// Created by Ali Sani on 12/11/21. +// + +import XCTest +@testable import TheMovieDB + +class TheMovieDBTests: XCTestCase { + + var viewModel: MovieDetailsViewModel! + + override func setUp() { + super.setUp() + viewModel = MovieDetailsViewModel(MovieDetailsService: MovieDetailsAPIServiceFake(), movieId: 0) + } + + func testNumberOfRowsReturnsZeroWhenMovieDetailsIsNil() { + viewModel.movieDetails = nil + XCTAssert(viewModel.numberOfRows == 0) + } + + func testNumberOfRowsReturnsOneWhenMovieDetailsIsNotNil() { + viewModel.movieDetails = FakeModels.FakeMovieDetails + XCTAssert(viewModel.numberOfRows == 1) + } + + func testCellDataReturnsMovieDetailsForAnyIndexPath() { + viewModel.movieDetails = FakeModels.FakeMovieDetails + var result = viewModel.getCellData(for: IndexPath(row: 0, section: 0)) + XCTAssertEqual(result, FakeModels.FakeMovieDetails) + + result = viewModel.getCellData(for: IndexPath(row: 1, section: 1)) + XCTAssertEqual(result, FakeModels.FakeMovieDetails) + + result = viewModel.getCellData(for: IndexPath(row: 1, section: 0)) + XCTAssertEqual(result, FakeModels.FakeMovieDetails) + } + + func testAsksForReloadWhenMovieDetailsIsSet() { + let expectation = self.expectation(description: "loadingState") + + viewModel.onShouldReloadTableView = { + expectation.fulfill() + } + + viewModel.movieDetails = FakeModels.FakeMovieDetails + waitForExpectations(timeout: 2, handler: nil) + } + + func testMovieDetailsIsSetWhenAPICallSucceeded() { + viewModel.viewDidLoad() + XCTAssertEqual(viewModel.movieDetails, FakeModels.FakeMovieDetails) + } +} diff --git a/TheMovieDB/TheMovieDBUITests/Info.plist b/TheMovieDB/TheMovieDBUITests/Info.plist new file mode 100644 index 00000000..64d65ca4 --- /dev/null +++ b/TheMovieDB/TheMovieDBUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/TheMovieDB/TheMovieDBUITests/TheMovieDBUITests.swift b/TheMovieDB/TheMovieDBUITests/TheMovieDBUITests.swift new file mode 100644 index 00000000..ce80d41a --- /dev/null +++ b/TheMovieDB/TheMovieDBUITests/TheMovieDBUITests.swift @@ -0,0 +1,41 @@ +// +// TheMovieDBUITests.swift +// TheMovieDBUITests +// +// Created by Ali Sani on 12/11/21. +// + +import XCTest + +class TheMovieDBUITests: XCTestCase { + + override func setUpWithError() throws { + super.setUp() + continueAfterFailure = false + } + + override func tearDownWithError() throws { + try super.tearDownWithError() + } + + func testHomeViewInitialViewsExist() { + let app = XCUIApplication() + app.launch() + + XCTAssert(app.staticTexts["The Movie DB"].waitForExistence(timeout: 1)) + XCTAssert(app.tables.buttons["Top rated"].waitForExistence(timeout: 1)) + XCTAssert(app.tables.buttons["Popular"].waitForExistence(timeout: 1)) + } + + // TODO: We should use mocked data here instead. + func testMovieDetailGenresIsDisplayedCorrectly() { + let app = XCUIApplication() + app.launch() + let tablesQuery = app.tables + tablesQuery.cells.containing(.staticText, identifier:"Sep 30, 2021") + .staticTexts["Venom: Let There Be Carnage"] + .tap() + XCTAssert(tablesQuery/*@START_MENU_TOKEN@*/.cells.staticTexts["Science Fiction, Action, Adventure"]/*[[".cells.staticTexts[\"Science Fiction, Action, Adventure\"]",".staticTexts[\"Science Fiction, Action, Adventure\"]"],[[[-1,1],[-1,0]]],[1]]@END_MENU_TOKEN@*/ + .waitForExistence(timeout: 3)) + } +}