├── README.md ├── Snakey List.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ ├── ali.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── MylivnTask.xcscheme │ │ └── xcschememanagement.plist │ └── aliadam.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── Snakey List ├── AppDelegate.swift ├── ApplicationViewControllers │ ├── ItemsGridScreen │ │ ├── ItemsGridRouter.swift │ │ ├── ItemsGridViewController.swift │ │ └── ItemsGridViewModel.swift │ └── SplashScreen │ │ ├── SplashRouter.swift │ │ ├── SplashViewController.swift │ │ └── SplashViewModel.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-57x57@1x.png │ │ ├── Icon-App-57x57@2x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-72x72@1x.png │ │ ├── Icon-App-72x72@2x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ ├── Icon-App-83.5x83.5@2x.png │ │ ├── Icon-Small-50x50@1x.png │ │ ├── Icon-Small-50x50@2x.png │ │ └── ItunesArtwork@2x.png │ ├── Contents.json │ ├── SnakeyList.imageset │ │ ├── Contents.json │ │ ├── iTunesArtwork@1x.png │ │ ├── iTunesArtwork@2x.png │ │ └── iTunesArtwork@3x.png │ ├── deleteIMG.imageset │ │ ├── Contents.json │ │ └── deleteIMG.png │ └── placeholder.imageset │ │ ├── Contents.json │ │ └── placeholder.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Helpers │ ├── AlertControllerHelper.swift │ ├── AsyncImageDownloader.swift │ ├── Extension │ │ ├── StringExtension.swift │ │ ├── UIImageViewExtension.swift │ │ └── UIViewExtension.swift │ ├── LocalizableWords.swift │ ├── MockLoader.swift │ └── StoryboardScene.swift ├── Info.plist ├── Layouts │ └── SnakeUICollectionLayout.swift ├── Models │ ├── Item.swift │ └── ItemsList.swift ├── Network │ ├── APPError.swift │ ├── NetworkProvider.swift │ └── NetworkResponse.swift ├── Resources │ └── ItemsList.json └── Views │ ├── DraggingView.swift │ └── ItemCell.swift └── screenshots ├── 1.gif └── 2.gif /README.md: -------------------------------------------------------------------------------- 1 | # Snakey-List 2 | An Instgram like collection Layout support drag and drop 3 | 4 | 5 | ![ScreenShot](https://github.com/AliAdam/Snakey-List/blob/master/Snakey%20List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork%401x.png) 6 | 7 | ![ScreenShot](https://github.com/AliAdam/Snakey-List/blob/master/screenshots/1.gif) 8 | 9 | ![ScreenShot](https://github.com/AliAdam/Snakey-List/blob/master/screenshots/2.gif) 10 | 11 | # features 12 | 1 - suport drag and drop 13 | 14 | 2 - cash the data to a local json file 15 | 16 | 3- add and delete from the list 17 | 18 | 4- load image async 19 | 20 | 5- network call simulation using local json file 21 | 22 | 23 | 24 | ``` 25 | if you want to use this layout in your project just copy this files to your project 26 | SnakeUICollectionLayout.swift 27 | DraggingView.swift 28 | 29 | ``` 30 | 31 | 32 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4132227F201E6B53000BB57C /* DraggingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4132227E201E6B53000BB57C /* DraggingView.swift */; }; 11 | 41614B8D220764C8001961DE /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 41614B8C220764C8001961DE /* README.md */; }; 12 | 41A6540A201CE10C00EEEF91 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A65409201CE10C00EEEF91 /* StringExtension.swift */; }; 13 | 41A6540C201CF92F00EEEF91 /* UIImageViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A6540B201CF92F00EEEF91 /* UIImageViewExtension.swift */; }; 14 | 41A6540E201D1BD500EEEF91 /* SnakeUICollectionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A6540D201D1BD500EEEF91 /* SnakeUICollectionLayout.swift */; }; 15 | 41A65413201D1DCB00EEEF91 /* ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41A65411201D1DCA00EEEF91 /* ItemCell.swift */; }; 16 | 41AD7383201B642400989141 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD7382201B642400989141 /* AppDelegate.swift */; }; 17 | 41AD7388201B642400989141 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 41AD7386201B642400989141 /* Main.storyboard */; }; 18 | 41AD738A201B642400989141 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 41AD7389201B642400989141 /* Assets.xcassets */; }; 19 | 41AD738D201B642400989141 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 41AD738B201B642400989141 /* LaunchScreen.storyboard */; }; 20 | 41AD73BD201B666C00989141 /* ItemsList.json in Resources */ = {isa = PBXBuildFile; fileRef = 41AD73A5201B666C00989141 /* ItemsList.json */; }; 21 | 41AD73C7201B666C00989141 /* NetworkResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73B0201B666C00989141 /* NetworkResponse.swift */; }; 22 | 41AD73C9201B666C00989141 /* NetworkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73B2201B666C00989141 /* NetworkProvider.swift */; }; 23 | 41AD73E5201B6D5300989141 /* ItemsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73E3201B6D5200989141 /* ItemsList.swift */; }; 24 | 41AD73E6201B6D5300989141 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73E4201B6D5200989141 /* Item.swift */; }; 25 | 41AD73E8201B6F8600989141 /* MockLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73E7201B6F8600989141 /* MockLoader.swift */; }; 26 | 41AD73EA201B783200989141 /* APPError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73E9201B783200989141 /* APPError.swift */; }; 27 | 41AD73F1201B994C00989141 /* SplashRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73ED201B994C00989141 /* SplashRouter.swift */; }; 28 | 41AD73F2201B994C00989141 /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73EE201B994C00989141 /* SplashViewController.swift */; }; 29 | 41AD73F4201B994C00989141 /* SplashViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73F0201B994C00989141 /* SplashViewModel.swift */; }; 30 | 41AD73F9201B9B4800989141 /* ItemsGridRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73F5201B9B4800989141 /* ItemsGridRouter.swift */; }; 31 | 41AD73FA201B9B4800989141 /* ItemsGridViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73F6201B9B4800989141 /* ItemsGridViewController.swift */; }; 32 | 41AD73FC201B9B4800989141 /* ItemsGridViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73F8201B9B4800989141 /* ItemsGridViewModel.swift */; }; 33 | 41AD73FE201BA36B00989141 /* StoryboardScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73FD201BA36B00989141 /* StoryboardScene.swift */; }; 34 | 41AD7400201BB47F00989141 /* LocalizableWords.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD73FF201BB47F00989141 /* LocalizableWords.swift */; }; 35 | 41AD7402201BB56400989141 /* AlertControllerHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD7401201BB56400989141 /* AlertControllerHelper.swift */; }; 36 | 41AD7407201BC3CA00989141 /* AsyncImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41AD7406201BC3C900989141 /* AsyncImageDownloader.swift */; }; 37 | 72B894C7201EE68B00A673D2 /* UIViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72B894C6201EE68B00A673D2 /* UIViewExtension.swift */; }; 38 | /* End PBXBuildFile section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 079FF8978BABFA21B6605A25 /* Pods_MylivnTask.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MylivnTask.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 4132227E201E6B53000BB57C /* DraggingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraggingView.swift; sourceTree = ""; }; 43 | 41614B8C220764C8001961DE /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 44 | 41A65409201CE10C00EEEF91 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = ""; }; 45 | 41A6540B201CF92F00EEEF91 /* UIImageViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageViewExtension.swift; sourceTree = ""; }; 46 | 41A6540D201D1BD500EEEF91 /* SnakeUICollectionLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnakeUICollectionLayout.swift; sourceTree = ""; }; 47 | 41A65411201D1DCA00EEEF91 /* ItemCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemCell.swift; sourceTree = ""; }; 48 | 41AD737F201B642400989141 /* Snakey List.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Snakey List.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 41AD7382201B642400989141 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 50 | 41AD7387201B642400989141 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | 41AD7389201B642400989141 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | 41AD738C201B642400989141 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | 41AD738E201B642400989141 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 41AD73A5201B666C00989141 /* ItemsList.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ItemsList.json; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.javascript; }; 55 | 41AD73B0201B666C00989141 /* NetworkResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkResponse.swift; sourceTree = ""; }; 56 | 41AD73B2201B666C00989141 /* NetworkProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkProvider.swift; sourceTree = ""; }; 57 | 41AD73E3201B6D5200989141 /* ItemsList.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemsList.swift; sourceTree = ""; }; 58 | 41AD73E4201B6D5200989141 /* Item.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = ""; }; 59 | 41AD73E7201B6F8600989141 /* MockLoader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockLoader.swift; sourceTree = ""; }; 60 | 41AD73E9201B783200989141 /* APPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APPError.swift; sourceTree = ""; }; 61 | 41AD73ED201B994C00989141 /* SplashRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashRouter.swift; sourceTree = ""; }; 62 | 41AD73EE201B994C00989141 /* SplashViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = ""; }; 63 | 41AD73F0201B994C00989141 /* SplashViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewModel.swift; sourceTree = ""; }; 64 | 41AD73F5201B9B4800989141 /* ItemsGridRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsGridRouter.swift; sourceTree = ""; }; 65 | 41AD73F6201B9B4800989141 /* ItemsGridViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsGridViewController.swift; sourceTree = ""; }; 66 | 41AD73F8201B9B4800989141 /* ItemsGridViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsGridViewModel.swift; sourceTree = ""; }; 67 | 41AD73FD201BA36B00989141 /* StoryboardScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryboardScene.swift; sourceTree = ""; }; 68 | 41AD73FF201BB47F00989141 /* LocalizableWords.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizableWords.swift; sourceTree = ""; }; 69 | 41AD7401201BB56400989141 /* AlertControllerHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertControllerHelper.swift; sourceTree = ""; }; 70 | 41AD7406201BC3C900989141 /* AsyncImageDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsyncImageDownloader.swift; sourceTree = ""; }; 71 | 72B894C6201EE68B00A673D2 /* UIViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtension.swift; sourceTree = ""; }; 72 | /* End PBXFileReference section */ 73 | 74 | /* Begin PBXFrameworksBuildPhase section */ 75 | 41AD737C201B642400989141 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | /* End PBXFrameworksBuildPhase section */ 83 | 84 | /* Begin PBXGroup section */ 85 | 41A65408201CE0D200EEEF91 /* Extension */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 41A65409201CE10C00EEEF91 /* StringExtension.swift */, 89 | 41A6540B201CF92F00EEEF91 /* UIImageViewExtension.swift */, 90 | 72B894C6201EE68B00A673D2 /* UIViewExtension.swift */, 91 | ); 92 | path = Extension; 93 | sourceTree = ""; 94 | }; 95 | 41AD7376201B642400989141 = { 96 | isa = PBXGroup; 97 | children = ( 98 | 41614B8C220764C8001961DE /* README.md */, 99 | 41AD7381201B642400989141 /* Snakey List */, 100 | 41AD7380201B642400989141 /* Products */, 101 | 9E0756FBF86D999D1FC481F3 /* Frameworks */, 102 | ); 103 | sourceTree = ""; 104 | }; 105 | 41AD7380201B642400989141 /* Products */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 41AD737F201B642400989141 /* Snakey List.app */, 109 | ); 110 | name = Products; 111 | sourceTree = ""; 112 | }; 113 | 41AD7381201B642400989141 /* Snakey List */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 41AD7395201B650900989141 /* ApplicationViewControllers */, 117 | 41AD7397201B666B00989141 /* Resources */, 118 | 41AD7394201B643100989141 /* Helpers */, 119 | 41AD73A3201B666C00989141 /* Models */, 120 | 41AD73AE201B666C00989141 /* Network */, 121 | 41AD7413201C814500989141 /* Layouts */, 122 | 41AD7403201BBDB700989141 /* Views */, 123 | 41AD7382201B642400989141 /* AppDelegate.swift */, 124 | 41AD7386201B642400989141 /* Main.storyboard */, 125 | 41AD7389201B642400989141 /* Assets.xcassets */, 126 | 41AD738B201B642400989141 /* LaunchScreen.storyboard */, 127 | 41AD738E201B642400989141 /* Info.plist */, 128 | ); 129 | path = "Snakey List"; 130 | sourceTree = ""; 131 | }; 132 | 41AD7394201B643100989141 /* Helpers */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 41A65408201CE0D200EEEF91 /* Extension */, 136 | 41AD7406201BC3C900989141 /* AsyncImageDownloader.swift */, 137 | 41AD73E7201B6F8600989141 /* MockLoader.swift */, 138 | 41AD73FD201BA36B00989141 /* StoryboardScene.swift */, 139 | 41AD73FF201BB47F00989141 /* LocalizableWords.swift */, 140 | 41AD7401201BB56400989141 /* AlertControllerHelper.swift */, 141 | ); 142 | path = Helpers; 143 | sourceTree = ""; 144 | }; 145 | 41AD7395201B650900989141 /* ApplicationViewControllers */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 41AD73DB201B669B00989141 /* SplashScreen */, 149 | 41AD73CC201B668800989141 /* ItemsGridScreen */, 150 | ); 151 | path = ApplicationViewControllers; 152 | sourceTree = ""; 153 | }; 154 | 41AD7397201B666B00989141 /* Resources */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 41AD73A5201B666C00989141 /* ItemsList.json */, 158 | ); 159 | path = Resources; 160 | sourceTree = ""; 161 | }; 162 | 41AD73A3201B666C00989141 /* Models */ = { 163 | isa = PBXGroup; 164 | children = ( 165 | 41AD73E4201B6D5200989141 /* Item.swift */, 166 | 41AD73E3201B6D5200989141 /* ItemsList.swift */, 167 | ); 168 | path = Models; 169 | sourceTree = ""; 170 | }; 171 | 41AD73AE201B666C00989141 /* Network */ = { 172 | isa = PBXGroup; 173 | children = ( 174 | 41AD73B0201B666C00989141 /* NetworkResponse.swift */, 175 | 41AD73B2201B666C00989141 /* NetworkProvider.swift */, 176 | 41AD73E9201B783200989141 /* APPError.swift */, 177 | ); 178 | path = Network; 179 | sourceTree = ""; 180 | }; 181 | 41AD73CC201B668800989141 /* ItemsGridScreen */ = { 182 | isa = PBXGroup; 183 | children = ( 184 | 41AD73F6201B9B4800989141 /* ItemsGridViewController.swift */, 185 | 41AD73F8201B9B4800989141 /* ItemsGridViewModel.swift */, 186 | 41AD73F5201B9B4800989141 /* ItemsGridRouter.swift */, 187 | ); 188 | path = ItemsGridScreen; 189 | sourceTree = ""; 190 | }; 191 | 41AD73DB201B669B00989141 /* SplashScreen */ = { 192 | isa = PBXGroup; 193 | children = ( 194 | 41AD73EE201B994C00989141 /* SplashViewController.swift */, 195 | 41AD73F0201B994C00989141 /* SplashViewModel.swift */, 196 | 41AD73ED201B994C00989141 /* SplashRouter.swift */, 197 | ); 198 | path = SplashScreen; 199 | sourceTree = ""; 200 | }; 201 | 41AD7403201BBDB700989141 /* Views */ = { 202 | isa = PBXGroup; 203 | children = ( 204 | 41A65411201D1DCA00EEEF91 /* ItemCell.swift */, 205 | 4132227E201E6B53000BB57C /* DraggingView.swift */, 206 | ); 207 | path = Views; 208 | sourceTree = ""; 209 | }; 210 | 41AD7413201C814500989141 /* Layouts */ = { 211 | isa = PBXGroup; 212 | children = ( 213 | 41A6540D201D1BD500EEEF91 /* SnakeUICollectionLayout.swift */, 214 | ); 215 | path = Layouts; 216 | sourceTree = ""; 217 | }; 218 | 9E0756FBF86D999D1FC481F3 /* Frameworks */ = { 219 | isa = PBXGroup; 220 | children = ( 221 | 079FF8978BABFA21B6605A25 /* Pods_MylivnTask.framework */, 222 | ); 223 | name = Frameworks; 224 | sourceTree = ""; 225 | }; 226 | /* End PBXGroup section */ 227 | 228 | /* Begin PBXNativeTarget section */ 229 | 41AD737E201B642400989141 /* Snakey List */ = { 230 | isa = PBXNativeTarget; 231 | buildConfigurationList = 41AD7391201B642400989141 /* Build configuration list for PBXNativeTarget "Snakey List" */; 232 | buildPhases = ( 233 | 41AD737B201B642400989141 /* Sources */, 234 | 41AD737C201B642400989141 /* Frameworks */, 235 | 41AD737D201B642400989141 /* Resources */, 236 | ); 237 | buildRules = ( 238 | ); 239 | dependencies = ( 240 | ); 241 | name = "Snakey List"; 242 | productName = MylivnTask; 243 | productReference = 41AD737F201B642400989141 /* Snakey List.app */; 244 | productType = "com.apple.product-type.application"; 245 | }; 246 | /* End PBXNativeTarget section */ 247 | 248 | /* Begin PBXProject section */ 249 | 41AD7377201B642400989141 /* Project object */ = { 250 | isa = PBXProject; 251 | attributes = { 252 | LastSwiftUpdateCheck = 0920; 253 | LastUpgradeCheck = 0920; 254 | ORGANIZATIONNAME = "Ali Adam"; 255 | TargetAttributes = { 256 | 41AD737E201B642400989141 = { 257 | CreatedOnToolsVersion = 9.2; 258 | ProvisioningStyle = Automatic; 259 | }; 260 | }; 261 | }; 262 | buildConfigurationList = 41AD737A201B642400989141 /* Build configuration list for PBXProject "Snakey List" */; 263 | compatibilityVersion = "Xcode 8.0"; 264 | developmentRegion = en; 265 | hasScannedForEncodings = 0; 266 | knownRegions = ( 267 | en, 268 | Base, 269 | ); 270 | mainGroup = 41AD7376201B642400989141; 271 | productRefGroup = 41AD7380201B642400989141 /* Products */; 272 | projectDirPath = ""; 273 | projectRoot = ""; 274 | targets = ( 275 | 41AD737E201B642400989141 /* Snakey List */, 276 | ); 277 | }; 278 | /* End PBXProject section */ 279 | 280 | /* Begin PBXResourcesBuildPhase section */ 281 | 41AD737D201B642400989141 /* Resources */ = { 282 | isa = PBXResourcesBuildPhase; 283 | buildActionMask = 2147483647; 284 | files = ( 285 | 41AD738D201B642400989141 /* LaunchScreen.storyboard in Resources */, 286 | 41AD738A201B642400989141 /* Assets.xcassets in Resources */, 287 | 41614B8D220764C8001961DE /* README.md in Resources */, 288 | 41AD7388201B642400989141 /* Main.storyboard in Resources */, 289 | 41AD73BD201B666C00989141 /* ItemsList.json in Resources */, 290 | ); 291 | runOnlyForDeploymentPostprocessing = 0; 292 | }; 293 | /* End PBXResourcesBuildPhase section */ 294 | 295 | /* Begin PBXSourcesBuildPhase section */ 296 | 41AD737B201B642400989141 /* Sources */ = { 297 | isa = PBXSourcesBuildPhase; 298 | buildActionMask = 2147483647; 299 | files = ( 300 | 41AD73E6201B6D5300989141 /* Item.swift in Sources */, 301 | 72B894C7201EE68B00A673D2 /* UIViewExtension.swift in Sources */, 302 | 41AD73EA201B783200989141 /* APPError.swift in Sources */, 303 | 41AD7402201BB56400989141 /* AlertControllerHelper.swift in Sources */, 304 | 4132227F201E6B53000BB57C /* DraggingView.swift in Sources */, 305 | 41AD73FC201B9B4800989141 /* ItemsGridViewModel.swift in Sources */, 306 | 41AD73C9201B666C00989141 /* NetworkProvider.swift in Sources */, 307 | 41A6540A201CE10C00EEEF91 /* StringExtension.swift in Sources */, 308 | 41AD73F4201B994C00989141 /* SplashViewModel.swift in Sources */, 309 | 41AD73E5201B6D5300989141 /* ItemsList.swift in Sources */, 310 | 41AD73C7201B666C00989141 /* NetworkResponse.swift in Sources */, 311 | 41AD7383201B642400989141 /* AppDelegate.swift in Sources */, 312 | 41AD73E8201B6F8600989141 /* MockLoader.swift in Sources */, 313 | 41AD73F9201B9B4800989141 /* ItemsGridRouter.swift in Sources */, 314 | 41A6540C201CF92F00EEEF91 /* UIImageViewExtension.swift in Sources */, 315 | 41A65413201D1DCB00EEEF91 /* ItemCell.swift in Sources */, 316 | 41AD73F1201B994C00989141 /* SplashRouter.swift in Sources */, 317 | 41AD7407201BC3CA00989141 /* AsyncImageDownloader.swift in Sources */, 318 | 41AD73F2201B994C00989141 /* SplashViewController.swift in Sources */, 319 | 41A6540E201D1BD500EEEF91 /* SnakeUICollectionLayout.swift in Sources */, 320 | 41AD73FE201BA36B00989141 /* StoryboardScene.swift in Sources */, 321 | 41AD7400201BB47F00989141 /* LocalizableWords.swift in Sources */, 322 | 41AD73FA201B9B4800989141 /* ItemsGridViewController.swift in Sources */, 323 | ); 324 | runOnlyForDeploymentPostprocessing = 0; 325 | }; 326 | /* End PBXSourcesBuildPhase section */ 327 | 328 | /* Begin PBXVariantGroup section */ 329 | 41AD7386201B642400989141 /* Main.storyboard */ = { 330 | isa = PBXVariantGroup; 331 | children = ( 332 | 41AD7387201B642400989141 /* Base */, 333 | ); 334 | name = Main.storyboard; 335 | sourceTree = ""; 336 | }; 337 | 41AD738B201B642400989141 /* LaunchScreen.storyboard */ = { 338 | isa = PBXVariantGroup; 339 | children = ( 340 | 41AD738C201B642400989141 /* Base */, 341 | ); 342 | name = LaunchScreen.storyboard; 343 | sourceTree = ""; 344 | }; 345 | /* End PBXVariantGroup section */ 346 | 347 | /* Begin XCBuildConfiguration section */ 348 | 41AD738F201B642400989141 /* Debug */ = { 349 | isa = XCBuildConfiguration; 350 | buildSettings = { 351 | ALWAYS_SEARCH_USER_PATHS = NO; 352 | CLANG_ANALYZER_NONNULL = YES; 353 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 354 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 355 | CLANG_CXX_LIBRARY = "libc++"; 356 | CLANG_ENABLE_MODULES = YES; 357 | CLANG_ENABLE_OBJC_ARC = YES; 358 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 359 | CLANG_WARN_BOOL_CONVERSION = YES; 360 | CLANG_WARN_COMMA = YES; 361 | CLANG_WARN_CONSTANT_CONVERSION = YES; 362 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 363 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 364 | CLANG_WARN_EMPTY_BODY = YES; 365 | CLANG_WARN_ENUM_CONVERSION = YES; 366 | CLANG_WARN_INFINITE_RECURSION = YES; 367 | CLANG_WARN_INT_CONVERSION = YES; 368 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 369 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 370 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 371 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 372 | CLANG_WARN_STRICT_PROTOTYPES = YES; 373 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 374 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 375 | CLANG_WARN_UNREACHABLE_CODE = YES; 376 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 377 | CODE_SIGN_IDENTITY = "iPhone Developer"; 378 | COPY_PHASE_STRIP = NO; 379 | DEBUG_INFORMATION_FORMAT = dwarf; 380 | ENABLE_STRICT_OBJC_MSGSEND = YES; 381 | ENABLE_TESTABILITY = YES; 382 | GCC_C_LANGUAGE_STANDARD = gnu11; 383 | GCC_DYNAMIC_NO_PIC = NO; 384 | GCC_NO_COMMON_BLOCKS = YES; 385 | GCC_OPTIMIZATION_LEVEL = 0; 386 | GCC_PREPROCESSOR_DEFINITIONS = ( 387 | "DEBUG=1", 388 | "$(inherited)", 389 | ); 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 397 | MTL_ENABLE_DEBUG_INFO = YES; 398 | ONLY_ACTIVE_ARCH = YES; 399 | SDKROOT = iphoneos; 400 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 401 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 402 | }; 403 | name = Debug; 404 | }; 405 | 41AD7390201B642400989141 /* Release */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | ALWAYS_SEARCH_USER_PATHS = NO; 409 | CLANG_ANALYZER_NONNULL = YES; 410 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 411 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 412 | CLANG_CXX_LIBRARY = "libc++"; 413 | CLANG_ENABLE_MODULES = YES; 414 | CLANG_ENABLE_OBJC_ARC = YES; 415 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 416 | CLANG_WARN_BOOL_CONVERSION = YES; 417 | CLANG_WARN_COMMA = YES; 418 | CLANG_WARN_CONSTANT_CONVERSION = YES; 419 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 420 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 421 | CLANG_WARN_EMPTY_BODY = YES; 422 | CLANG_WARN_ENUM_CONVERSION = YES; 423 | CLANG_WARN_INFINITE_RECURSION = YES; 424 | CLANG_WARN_INT_CONVERSION = YES; 425 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 426 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 427 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 428 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 429 | CLANG_WARN_STRICT_PROTOTYPES = YES; 430 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 431 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 432 | CLANG_WARN_UNREACHABLE_CODE = YES; 433 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 434 | CODE_SIGN_IDENTITY = "iPhone Developer"; 435 | COPY_PHASE_STRIP = NO; 436 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 437 | ENABLE_NS_ASSERTIONS = NO; 438 | ENABLE_STRICT_OBJC_MSGSEND = YES; 439 | GCC_C_LANGUAGE_STANDARD = gnu11; 440 | GCC_NO_COMMON_BLOCKS = YES; 441 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 442 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 443 | GCC_WARN_UNDECLARED_SELECTOR = YES; 444 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 445 | GCC_WARN_UNUSED_FUNCTION = YES; 446 | GCC_WARN_UNUSED_VARIABLE = YES; 447 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 448 | MTL_ENABLE_DEBUG_INFO = NO; 449 | SDKROOT = iphoneos; 450 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 451 | VALIDATE_PRODUCT = YES; 452 | }; 453 | name = Release; 454 | }; 455 | 41AD7392201B642400989141 /* Debug */ = { 456 | isa = XCBuildConfiguration; 457 | buildSettings = { 458 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 459 | CODE_SIGN_STYLE = Automatic; 460 | DEVELOPMENT_TEAM = HJ9GBN3WD6; 461 | INFOPLIST_FILE = "$(SRCROOT)/Snakey List/Info.plist"; 462 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 464 | PRODUCT_BUNDLE_IDENTIFIER = AliAdam.MylivnTask; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | SWIFT_VERSION = 4.0; 467 | TARGETED_DEVICE_FAMILY = "1,2"; 468 | }; 469 | name = Debug; 470 | }; 471 | 41AD7393201B642400989141 /* Release */ = { 472 | isa = XCBuildConfiguration; 473 | buildSettings = { 474 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 475 | CODE_SIGN_STYLE = Automatic; 476 | DEVELOPMENT_TEAM = HJ9GBN3WD6; 477 | INFOPLIST_FILE = "$(SRCROOT)/Snakey List/Info.plist"; 478 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 479 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 480 | PRODUCT_BUNDLE_IDENTIFIER = AliAdam.MylivnTask; 481 | PRODUCT_NAME = "$(TARGET_NAME)"; 482 | SWIFT_VERSION = 4.0; 483 | TARGETED_DEVICE_FAMILY = "1,2"; 484 | }; 485 | name = Release; 486 | }; 487 | /* End XCBuildConfiguration section */ 488 | 489 | /* Begin XCConfigurationList section */ 490 | 41AD737A201B642400989141 /* Build configuration list for PBXProject "Snakey List" */ = { 491 | isa = XCConfigurationList; 492 | buildConfigurations = ( 493 | 41AD738F201B642400989141 /* Debug */, 494 | 41AD7390201B642400989141 /* Release */, 495 | ); 496 | defaultConfigurationIsVisible = 0; 497 | defaultConfigurationName = Release; 498 | }; 499 | 41AD7391201B642400989141 /* Build configuration list for PBXNativeTarget "Snakey List" */ = { 500 | isa = XCConfigurationList; 501 | buildConfigurations = ( 502 | 41AD7392201B642400989141 /* Debug */, 503 | 41AD7393201B642400989141 /* Release */, 504 | ); 505 | defaultConfigurationIsVisible = 0; 506 | defaultConfigurationName = Release; 507 | }; 508 | /* End XCConfigurationList section */ 509 | }; 510 | rootObject = 41AD7377201B642400989141 /* Project object */; 511 | } 512 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/xcuserdata/ali.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 72 | 84 | 85 | 86 | 88 | 100 | 101 | 102 | 104 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/xcuserdata/ali.xcuserdatad/xcschemes/MylivnTask.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/xcuserdata/ali.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MylivnTask.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 41AD737E201B642400989141 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/xcuserdata/aliadam.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Snakey List.xcodeproj/xcuserdata/aliadam.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MylivnTask.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Snakey List/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | return true 19 | } 20 | 21 | func applicationWillResignActive(_ application: UIApplication) {} 22 | 23 | func applicationDidEnterBackground(_ application: UIApplication) {} 24 | 25 | func applicationWillEnterForeground(_ application: UIApplication) {} 26 | 27 | func applicationDidBecomeActive(_ application: UIApplication) {} 28 | 29 | func applicationWillTerminate(_ application: UIApplication) {} 30 | 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/ItemsGridScreen/ItemsGridRouter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ItemsGridRouter.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | class ItemsGridRouter :NSObject { 13 | weak var itemsGridViewController: ItemsGridViewController? 14 | 15 | // delete confirmation alert 16 | func showDeleteConfirmationWith(uuid:String, completionHandler: @escaping (ConfirmResponse) -> ()){ 17 | let alertController = UIAlertController(title: LocalizableWords.deleteTitle, message: "\(LocalizableWords.deleteConfrimation)\(uuid)", preferredStyle: .alert) 18 | let okAction = UIAlertAction(title: LocalizableWords.yes, style: .default) { (action) in 19 | completionHandler(.confirm(true)) 20 | } 21 | let cancelAction = UIAlertAction(title: LocalizableWords.cancel, style: .default) { (action) in 22 | completionHandler(.notConfirm(true)) 23 | } 24 | alertController.addAction(okAction) 25 | alertController.addAction(cancelAction) 26 | 27 | itemsGridViewController?.present(alertController, animated: true, completion: nil) 28 | 29 | 30 | } 31 | 32 | // Delete Error Alert 33 | func showDeleteErrorAlert() { 34 | AlertControllerHelper.showAlert(withTitle: LocalizableWords.errorMessageTile, message: LocalizableWords.deleteErrorMessage, on: itemsGridViewController!) 35 | } 36 | 37 | // Update Error Alert 38 | func showUpdateErrorAlert() { 39 | AlertControllerHelper.showAlert(withTitle: LocalizableWords.errorMessageTile, message: LocalizableWords.updateErrorMessage, on: itemsGridViewController!) 40 | } 41 | // reorder Error Alert 42 | func showReorderErrorAlert() { 43 | AlertControllerHelper.showAlert(withTitle: LocalizableWords.errorMessageTile, message: LocalizableWords.reorderErrorMessage, on: itemsGridViewController!) 44 | } 45 | 46 | // add new item Alert 47 | func showAddNewItemAlert(completionHandler: @escaping (ConfirmResponse) -> ()) { 48 | let alertController = UIAlertController(title: LocalizableWords.addNewItemTile, message: LocalizableWords.addNewItemMessage, preferredStyle: .alert) 49 | let okAction = UIAlertAction(title: LocalizableWords.yes, style: .default) { (action) in 50 | let textField = alertController.textFields![0] as UITextField 51 | completionHandler(.confirm(textField.text!)) 52 | } 53 | let cancelAction = UIAlertAction(title: LocalizableWords.cancel, style: .default) { (action) in 54 | completionHandler(.notConfirm("")) 55 | } 56 | okAction.isEnabled = false 57 | alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in 58 | textField.placeholder = LocalizableWords.addNewItemMessage 59 | NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextFieldTextDidChange, object: textField, queue: OperationQueue.main) { (notification) in 60 | okAction.isEnabled = textField.text!.isValidURL() 61 | } 62 | }) 63 | alertController.addAction(okAction) 64 | alertController.addAction(cancelAction) 65 | itemsGridViewController?.present(alertController, animated: true, completion: nil) 66 | } 67 | 68 | 69 | // change UUID Alert 70 | 71 | func showChangeUUIDAlert(uuid:String,completionHandler: @escaping (ConfirmResponse) -> ()) { 72 | 73 | let message = LocalizableWords.changeUUIDMessage.replacingOccurrences(of: LocalizableWords.placeHolderUUID, with: uuid) 74 | let alertController = UIAlertController(title: LocalizableWords.changeUUIDTile, message: message, preferredStyle: .alert) 75 | 76 | let okAction = UIAlertAction(title: LocalizableWords.change, style: .default) { (action) in 77 | let textField = alertController.textFields![0] as UITextField 78 | completionHandler(.confirm(textField.text!)) 79 | } 80 | let cancelAction = UIAlertAction(title: LocalizableWords.cancel, style: .default) { (action) in 81 | completionHandler(.notConfirm("")) 82 | } 83 | okAction.isEnabled = false 84 | alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in 85 | textField.placeholder = LocalizableWords.placeHolderUUID 86 | NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextFieldTextDidChange, object: textField, queue: OperationQueue.main) { (notification) in 87 | okAction.isEnabled = textField.text!.isValidUUID() 88 | } 89 | 90 | }) 91 | alertController.addAction(okAction) 92 | alertController.addAction(cancelAction) 93 | itemsGridViewController?.present(alertController, animated: true, completion: nil) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/ItemsGridScreen/ItemsGridViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ItemsGridViewController.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ItemsGridViewController: UIViewController { 12 | 13 | @IBOutlet weak var collectionView: UICollectionView! 14 | // controller view model 15 | @IBOutlet var viewModel: ItemsGridViewModel! 16 | 17 | // contrroler router to navigate to other controller or show messages 18 | @IBOutlet var router: ItemsGridRouter! 19 | 20 | 21 | // set the viewmodel 22 | func setViewModel(viewModel:ItemsGridViewModel) { 23 | self.viewModel = viewModel 24 | } 25 | 26 | 27 | 28 | override func viewDidLoad(){ 29 | super.viewDidLoad() 30 | router.itemsGridViewController = self 31 | 32 | // config the collectionView Lay out 33 | configCollectionView() 34 | 35 | 36 | } 37 | 38 | 39 | func configCollectionView() { 40 | 41 | // set the SnakeUICollectionLayout completion handler to call it when 42 | // move cell 43 | let layout = collectionView.collectionViewLayout as! SnakeUICollectionLayout 44 | layout.didReorderHandler = { [weak self] fromIndexPath, toIndexPath in 45 | self?.moveItem(fromIndex: fromIndexPath.item, toIndex: toIndexPath.item) 46 | } 47 | collectionView.reloadData() 48 | } 49 | 50 | } 51 | 52 | //MARK:- UICollectionViewDelegate 53 | extension ItemsGridViewController : UICollectionViewDelegate ,UICollectionViewDataSource{ 54 | 55 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 56 | return viewModel.itemsCount! + 1 57 | } 58 | 59 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 60 | let cell : ItemCell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath) as! ItemCell 61 | configCellForItem(item: indexPath.item, andCell: cell) 62 | return cell 63 | } 64 | 65 | // config each cell by the item from list 66 | func configCellForItem(item:Int,andCell cell:ItemCell?) { 67 | if let itemCell = cell { 68 | var isAdd = false 69 | if item == viewModel.itemsCount! { 70 | isAdd = true 71 | itemCell.addBTNHandler = { [weak self] index ,cell in 72 | self?.addItemAction(index: index) 73 | } 74 | itemCell.Config(imageUrlString: "" ,index: item ,isAdd:isAdd ) 75 | } 76 | else { 77 | let url = viewModel.imageURLForItemAt(index: item) 78 | itemCell.Config(imageUrlString: url ,index: item ,isAdd:isAdd ) 79 | itemCell.addBTNHandler = { [weak self] index,cell in 80 | let indexpath = self?.collectionView.indexPath(for: cell) 81 | self?.changeItemIDAction(index: (indexpath?.item)!) 82 | } 83 | itemCell.deleteBTNHandler = { [weak self] index,cell in 84 | let indexpath = self?.collectionView.indexPath(for: cell) 85 | self?.deleteItemAction(index: (indexpath?.item)!) 86 | } 87 | } 88 | 89 | } 90 | } 91 | } 92 | //MARK:- Delete,Add,Move,Change Actions 93 | 94 | extension ItemsGridViewController { 95 | 96 | 97 | // MARK: - delete action 98 | 99 | // confirm action from user then delete item from the list by view model 100 | // then update the collection view on success 101 | func deleteItemAction(index :Int) { 102 | let uuid = viewModel.uuidForItemAt(index: index) 103 | router.showDeleteConfirmationWith(uuid:uuid, completionHandler: { [weak self] response in 104 | switch response { 105 | case .confirm(_): 106 | self?.deleteItemAt(index: index) 107 | case .notConfirm(_): 108 | print("not confirm ") 109 | } 110 | }) 111 | } 112 | func deleteItemAt(index :Int) { 113 | self.viewModel.deleteItem(atIndex: index) { [weak self] response in 114 | switch response { 115 | case .success(_): 116 | print("") 117 | self?.removeItemFromCollection(index: index) 118 | case .error(_): 119 | self?.router.showDeleteErrorAlert() 120 | 121 | } 122 | } 123 | } 124 | func removeItemFromCollection(index: Int) { 125 | let indexPath = IndexPath(row: index, section: 0) 126 | collectionView.performBatchUpdates({ 127 | self.collectionView.deleteItems(at: [indexPath]) 128 | }, completion: { 129 | (finished: Bool) in 130 | }) 131 | } 132 | 133 | 134 | //MARK:- add item Action 135 | 136 | // confirm action from user then add item to the list by view model 137 | // then update the collection view on success 138 | 139 | func addItemAction(index :Int) { 140 | self.router.showAddNewItemAlert { [weak self] response in 141 | switch response { 142 | case let .confirm(url): 143 | self?.addItemWith(url: url) 144 | print("\(url)") 145 | case .notConfirm(_): 146 | print("not Confirm") 147 | } 148 | 149 | } 150 | } 151 | func addItemWith(url :String) { 152 | self.viewModel.addNewItem(url: url){ [weak self] response in 153 | switch response { 154 | case .success(_): 155 | self?.insertItemToCollection(index:((self?.viewModel.itemsCount!)! - 1)) 156 | case .error(_): 157 | self?.router.showDeleteErrorAlert() 158 | 159 | } 160 | } 161 | } 162 | func insertItemToCollection(index: Int) { 163 | let indexPath = IndexPath(row: index, section: 0) 164 | collectionView.performBatchUpdates({ 165 | self.collectionView.insertItems(at: [indexPath]) 166 | }, completion: { 167 | (finished: Bool) in 168 | }) 169 | } 170 | 171 | //MARK:- change UUID Action 172 | 173 | // confirm action from user then chnge uuid on the list by view model 174 | // then update the collection view on success 175 | func changeItemIDAction(index :Int) { 176 | print("\(index)") 177 | let itemUUId = self.viewModel.uuidForItemAt(index: index) 178 | self.router.showChangeUUIDAlert(uuid:itemUUId){ [weak self] response in 179 | switch response { 180 | case let .confirm(uuid): 181 | self?.changeUUIdForItem(atIndex: index, newUUID: uuid) 182 | print("\(uuid)") 183 | case .notConfirm(_): 184 | print("not Confirm") 185 | } 186 | 187 | } 188 | } 189 | 190 | func changeUUIdForItem (atIndex index:Int,newUUID uuid:String) { 191 | self.viewModel.changeUUIdForItem(atIndex:index,newUUID:uuid){ [weak self] response in 192 | switch response { 193 | case .success(_): 194 | let selectedIndexPath = IndexPath(item: index, section: 0) 195 | self?.collectionView.reloadItems(at: [selectedIndexPath]) 196 | case .error(_): 197 | self?.router.showDeleteErrorAlert() 198 | 199 | } 200 | } 201 | } 202 | 203 | 204 | //MARK:- move item from index to index 205 | 206 | // move item to the new index on the list by view model 207 | // then update the collection view on success 208 | func moveItem( fromIndex: Int, toIndex: Int) { 209 | self.viewModel.moveItem(fromIndex:fromIndex,toIndex:toIndex){ [weak self] response in 210 | switch response { 211 | case .success(_): 212 | self?.moveItemInCollection(fromIndex:fromIndex, toIndex: toIndex) 213 | case .error(_): 214 | self?.router.showReorderErrorAlert() 215 | } 216 | } 217 | } 218 | func moveItemInCollection( fromIndex: Int, toIndex: Int) { 219 | let fromIndexPath = IndexPath(item: fromIndex, section: 0) 220 | let toIndexPath = IndexPath(item: toIndex, section: 0) 221 | 222 | collectionView?.performBatchUpdates({ 223 | self.collectionView?.moveItem(at: fromIndexPath, to: toIndexPath) 224 | }, completion: nil 225 | ) 226 | } 227 | } 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/ItemsGridScreen/ItemsGridViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ItemsGridViewModel.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class ItemsGridViewModel:NSObject { 12 | 13 | fileprivate var itemsList : ItemsList? 14 | 15 | override init() { 16 | super.init() 17 | } 18 | // init the view model with list of item 19 | init(itemList:ItemsList) { 20 | super.init() 21 | self.itemsList = itemList 22 | } 23 | 24 | // return item count 25 | var itemsCount: Int? { 26 | return itemsList?.items?.count 27 | } 28 | 29 | // // items array 30 | // var items: [Item]? { 31 | // return itemsList?.items 32 | // } 33 | 34 | // image url for item at index 35 | func imageURLForItemAt(index:Int) -> String { 36 | return (self.itemsList?.items![index].imageUrlString)! 37 | } 38 | 39 | // UUID for item at index 40 | func uuidForItemAt(index:Int) -> String { 41 | return (self.itemsList?.items![index].uuid)! 42 | } 43 | 44 | // return item at index 45 | func itemAt(index:Int) -> Item { 46 | return (self.itemsList?.items![index] )! 47 | } 48 | 49 | 50 | /// add new item with with url and generate uuid for it then update the saved data ince sucess call the complation handler 51 | func addNewItem(url:String,completionHandler:@escaping (NetworkResponse)->()){ 52 | let tempItemList = self.itemsList 53 | let randomUUID = String.randomUUID() 54 | self.itemsList?.addItemWith(uuid: randomUUID, imageurl: url) 55 | let lastIndex = self.itemsCount! - 1 56 | let item = self.itemAt(index: lastIndex) 57 | NetworkProvider.shared.updateItemList(with: self.itemsList!) { [weak self] response in 58 | switch response { 59 | case .success(_): 60 | completionHandler(.success(item)) 61 | case let .error(error): 62 | self?.itemsList = tempItemList 63 | completionHandler(.error(error)) 64 | 65 | } 66 | 67 | } 68 | } 69 | 70 | /// delet itemthen update the saved data ince sucess call the complation handler 71 | func deleteItem (atIndex index:Int,completionHandler:@escaping (NetworkResponse)->()){ 72 | let tempItemList = self.itemsList 73 | self.itemsList?.deleteItem(atIndex: index) 74 | NetworkProvider.shared.updateItemList(with: self.itemsList!) { [weak self] response in 75 | switch response { 76 | case let .success(res): 77 | completionHandler(.success(res)) 78 | case let .error(error): 79 | self?.itemsList = tempItemList 80 | completionHandler(.error(error)) 81 | } 82 | 83 | } 84 | } 85 | 86 | /// change uuid for item then update the saved data ince sucess call the complation handler 87 | 88 | func changeUUIdForItem (atIndex index:Int,newUUID uuid:String,completionHandler:@escaping (NetworkResponse)->()){ 89 | let tempItemList = self.itemsList 90 | self.itemsList?.changeUUIdForItem(atIndex: index, newUUID: uuid) 91 | NetworkProvider.shared.updateItemList(with: self.itemsList!) { [weak self] response in 92 | switch response { 93 | case let .success(res): 94 | completionHandler(.success(res)) 95 | case let .error(error): 96 | self?.itemsList = tempItemList 97 | completionHandler(.error(error)) 98 | } 99 | 100 | } 101 | } 102 | 103 | /// move item from index to index then update the saved data ince sucess call the complation handler 104 | func moveItem( fromIndex: Int, toIndex: Int,completionHandler:@escaping (NetworkResponse)->()){ 105 | let tempItemList = self.itemsList 106 | self.itemsList?.moveItem(fromIndex: fromIndex, toIndex: toIndex) 107 | NetworkProvider.shared.updateItemList(with: self.itemsList!) { [weak self] response in 108 | switch response { 109 | case let .success(res): 110 | completionHandler(.success(res)) 111 | case let .error(error): 112 | self?.itemsList = tempItemList 113 | completionHandler(.error(error)) 114 | } 115 | 116 | } 117 | } 118 | 119 | 120 | } 121 | 122 | 123 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/SplashScreen/SplashRouter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SplashRouter.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | class SplashRouter:NSObject { 12 | 13 | weak var splashViewController: SplashViewController? 14 | 15 | override init() { 16 | super.init() 17 | } 18 | // navigate to next screen collection screen 19 | func navigateToItemsGridList() { 20 | let viewModel = ItemsGridViewModel(itemList: splashViewController!.getItemList()) 21 | let viewController = StoryboardScene.ItemsGridViewController.initialViewController() as! ItemsGridViewController 22 | viewController.setViewModel(viewModel: viewModel) 23 | UIApplication.shared.keyWindow?.rootViewController = viewController 24 | } 25 | // show alert controller 26 | func showParsingErrorAlert() { 27 | AlertControllerHelper.showAlert(withTitle: LocalizableWords.errorMessageTile, message: LocalizableWords.parseErrorMessage, on: splashViewController!) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/SplashScreen/SplashViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SplashViewController.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SplashViewController: UIViewController { 12 | // controller view model 13 | @IBOutlet var viewModel: SplashViewModel! 14 | 15 | // contrroler router to navigate to other controller or show messages 16 | @IBOutlet var router: SplashRouter! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | // set the router controller 21 | router.splashViewController = self 22 | } 23 | override func viewDidAppear(_ animated: Bool) { 24 | super.viewDidAppear(animated) 25 | loadData() 26 | } 27 | /// load item list and navigate to collection view on sucess 28 | // show error on fail 29 | func loadData() { 30 | viewModel.loadItemsList { [weak self] response in 31 | switch response { 32 | case .success(_): 33 | self?.router.navigateToItemsGridList() 34 | 35 | case .error( _): 36 | self?.router.showParsingErrorAlert() 37 | } 38 | } 39 | } 40 | 41 | /// get item list to pass it to the new viewmodel of next screen 42 | func getItemList() -> ItemsList { 43 | return viewModel.getItemList() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Snakey List/ApplicationViewControllers/SplashScreen/SplashViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SplashViewModel.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright (c) 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | class SplashViewModel :NSObject{ 11 | 12 | fileprivate var itemsList : ItemsList? 13 | override init() { 14 | super.init() 15 | } 16 | // load item list 17 | func loadItemsList(completionHandler: @escaping (NetworkResponse) -> ()){ 18 | NetworkProvider.shared.itemList { [weak self] response in 19 | switch response { 20 | case let .success(itemList): 21 | self?.itemsList = itemList 22 | completionHandler(.success(true)) 23 | print("items count = \(String(describing: itemList.items?.count))") 24 | case let .error(error): 25 | completionHandler(.error(error)) 26 | print("\(error.localizedDescription)") 27 | } 28 | } 29 | 30 | } 31 | 32 | /// get item list 33 | func getItemList() -> ItemsList { 34 | return itemsList! 35 | } 36 | 37 | 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "57x57", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-57x57@1x.png", 49 | "scale" : "1x" 50 | }, 51 | { 52 | "size" : "57x57", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-57x57@2x.png", 55 | "scale" : "2x" 56 | }, 57 | { 58 | "size" : "60x60", 59 | "idiom" : "iphone", 60 | "filename" : "Icon-App-60x60@2x.png", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "size" : "60x60", 65 | "idiom" : "iphone", 66 | "filename" : "Icon-App-60x60@3x.png", 67 | "scale" : "3x" 68 | }, 69 | { 70 | "size" : "20x20", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-20x20@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "20x20", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-20x20@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "29x29", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-29x29@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "29x29", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-29x29@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "40x40", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-40x40@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "40x40", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-40x40@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "50x50", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-Small-50x50@1x.png", 109 | "scale" : "1x" 110 | }, 111 | { 112 | "size" : "50x50", 113 | "idiom" : "ipad", 114 | "filename" : "Icon-Small-50x50@2x.png", 115 | "scale" : "2x" 116 | }, 117 | { 118 | "size" : "72x72", 119 | "idiom" : "ipad", 120 | "filename" : "Icon-App-72x72@1x.png", 121 | "scale" : "1x" 122 | }, 123 | { 124 | "size" : "72x72", 125 | "idiom" : "ipad", 126 | "filename" : "Icon-App-72x72@2x.png", 127 | "scale" : "2x" 128 | }, 129 | { 130 | "size" : "76x76", 131 | "idiom" : "ipad", 132 | "filename" : "Icon-App-76x76@1x.png", 133 | "scale" : "1x" 134 | }, 135 | { 136 | "size" : "76x76", 137 | "idiom" : "ipad", 138 | "filename" : "Icon-App-76x76@2x.png", 139 | "scale" : "2x" 140 | }, 141 | { 142 | "size" : "83.5x83.5", 143 | "idiom" : "ipad", 144 | "filename" : "Icon-App-83.5x83.5@2x.png", 145 | "scale" : "2x" 146 | }, 147 | { 148 | "size" : "1024x1024", 149 | "idiom" : "ios-marketing", 150 | "filename" : "ItunesArtwork@2x.png", 151 | "scale" : "1x" 152 | } 153 | ], 154 | "info" : { 155 | "version" : 1, 156 | "author" : "xcode" 157 | } 158 | } -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/SnakeyList.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iTunesArtwork@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iTunesArtwork@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iTunesArtwork@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@1x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@2x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/SnakeyList.imageset/iTunesArtwork@3x.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/deleteIMG.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "deleteIMG.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/deleteIMG.imageset/deleteIMG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/deleteIMG.imageset/deleteIMG.png -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/placeholder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "placeholder.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakey List/Assets.xcassets/placeholder.imageset/placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/Snakey List/Assets.xcassets/placeholder.imageset/placeholder.png -------------------------------------------------------------------------------- /Snakey List/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | SnellRoundhand 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Snakey List/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 80 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Snakey List/Helpers/AlertControllerHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlertControllerHelper.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class AlertControllerHelper { 12 | 13 | private init() {} 14 | // show quick alert with title and message and okay button 15 | static func showAlert(withTitle title: String, message: String?, on viewController: UIViewController) { 16 | let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 17 | alertController.addAction(UIAlertAction(title: LocalizableWords.ok, style: .default)) 18 | viewController.present(alertController, animated: true) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Snakey List/Helpers/AsyncImageDownloader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncImageDownloader.swift 3 | // AsyncImageDownloader 4 | // 5 | // Created by Ali Adam on 7/12/17. 6 | // Copyright © 2017 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import ObjectiveC 12 | 13 | /// this class to load and cash images 14 | class AsyncImageDownloader: NSObject { 15 | static let `default` = AsyncImageDownloader() 16 | 17 | private let cache = NSCache() 18 | 19 | /// CashImage init method 20 | /// 21 | override init() { 22 | cache.name = "AsyncImageDownloader" 23 | cache.countLimit = 20 24 | cache.totalCostLimit = 15 25 | } 26 | /// load image from cach 27 | /// 28 | /// - Parameter key: key 29 | /// - Returns: image 30 | private func getImageFor(key :String) -> UIImage? { 31 | let image = cache.object(forKey:key as AnyObject) as? UIImage 32 | return image 33 | } 34 | 35 | /// save image to cach 36 | /// 37 | /// - Parameters: 38 | /// - image: image to be save 39 | /// - key: key 40 | private func saveImage(image : UIImage ,key :String) { 41 | cache.setObject(image, forKey:key as AnyObject) 42 | } 43 | 44 | /// load the image and save it to the cash or load it from the cash 45 | /// 46 | /// - Parameters: 47 | /// - imageView: imageView to add the image on it 48 | /// - url: image url 49 | func load(imageView : UIImageView ,url :String) { 50 | 51 | /// showActivityIndicator method you can find it on UIImageView+Extension.swift 52 | /// i add this method to UIImageView class you can show and hide 53 | /// ActivityIndicator on any imageview with easy way 54 | 55 | /// check if image cached or not if exist load it from the cach if not load it 56 | if AsyncImageDownloader.default.getImageFor(key: url) != nil{ 57 | if let image = AsyncImageDownloader.default.getImageFor(key: url){ 58 | imageView.image = image 59 | imageView.hideActivityIndicator() 60 | } 61 | } 62 | else{ 63 | AsyncImageDownloader.default.loadImageFor(imageView:imageView,url: url) 64 | } 65 | } 66 | 67 | 68 | /// load image from server 69 | /// 70 | /// - Parameters: 71 | /// - imageView: imageView to add the image on it 72 | /// - url: image url 73 | func loadImageFor(imageView : UIImageView ,url :String){ 74 | let imageURL = URL(string: url) 75 | if let imgurl = imageURL { 76 | DispatchQueue.global(qos: .userInitiated).async { 77 | let imageData = NSData(contentsOf: imgurl) 78 | DispatchQueue.main.async { 79 | if imageData != nil { 80 | if let image = UIImage(data: imageData! as Data) { 81 | imageView.image = image 82 | AsyncImageDownloader.default.saveImage(image: image ,key: url) 83 | imageView.hideActivityIndicator() 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | } 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Snakey List/Helpers/Extension/StringExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StringExtension.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/27/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | 10 | import UIKit 11 | 12 | extension String { 13 | /// match this string with regex pattern 14 | /// 15 | /// - Parameter regex: regex pattern 16 | /// - Returns: bool value indicate if it match or not 17 | func matchRegex(regex : String ) -> Bool { 18 | let predicate = NSPredicate(format: "SELF MATCHES %@", regex) 19 | return predicate.evaluate(with: self) 20 | } 21 | 22 | /// cheack if this string is availd url or not 23 | /// 24 | /// - Returns: Returns: bool value indicate if it url or not 25 | func isValidURL() -> Bool { 26 | let regex : String = "^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$" 27 | return self.matchRegex(regex: regex) 28 | } 29 | 30 | /// cheack if this string is availd UUID or not 31 | /// 32 | /// - Returns: Returns: bool value indicate if it UUID or not 33 | 34 | func isValidUUID() -> Bool { 35 | let regex : String = "[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}" 36 | return self.matchRegex(regex: regex) 37 | } 38 | // 39 | static func randomUUID() -> String { 40 | return UUID().uuidString 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Snakey List/Helpers/Extension/UIImageViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageViewExtension.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/27/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | // MARK: - Add UIActivityIndicatorView to UIImageView 13 | /// i add this method to UIImageView class you can show and hide 14 | /// ActivityIndicator on any imageview with easy way 15 | fileprivate var activityIndicatorAssociationKey: UInt8 = 0 16 | 17 | extension UIImageView { 18 | 19 | var activityIndicator: UIActivityIndicatorView! { 20 | get { 21 | return objc_getAssociatedObject(self, &activityIndicatorAssociationKey) as? UIActivityIndicatorView 22 | } 23 | set(newValue) { 24 | objc_setAssociatedObject(self, &activityIndicatorAssociationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) 25 | } 26 | } 27 | // load image with and add place holder during loading 28 | func loadImageFromUrl(_ url: String, andPlaceHolder placeHolder:UIImage, andCach cache:Bool){ 29 | self.image = placeHolder 30 | if cache { 31 | AsyncImageDownloader.default.load(imageView: self,url: url) 32 | } 33 | else 34 | { 35 | AsyncImageDownloader.default.loadImageFor(imageView: self,url: url) 36 | } 37 | } 38 | 39 | // load image with and add activity indicator during loading 40 | func loadImageFromUrl(_ url: String, withActivityIndicator style:UIActivityIndicatorViewStyle, andCach cache:Bool){ 41 | self.showActivityIndicatorWith(style: style) 42 | if cache { 43 | AsyncImageDownloader.default.load(imageView: self,url: url) 44 | } 45 | else 46 | { 47 | AsyncImageDownloader.default.loadImageFor(imageView: self,url: url) 48 | } 49 | } 50 | 51 | 52 | 53 | /// add activityIndicator to the center of image view 54 | func showActivityIndicatorWith(style:UIActivityIndicatorViewStyle) { 55 | if (self.activityIndicator == nil) { 56 | self.activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: style) 57 | self.activityIndicator.hidesWhenStopped = true 58 | self.activityIndicator.frame = CGRect(x: 0, y: 0, width: 30, height: 30); 59 | self.activityIndicator.center = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2); 60 | self.activityIndicator.autoresizingMask = [.flexibleLeftMargin , .flexibleRightMargin , .flexibleTopMargin , .flexibleBottomMargin] 61 | self.activityIndicator.translatesAutoresizingMaskIntoConstraints = false 62 | self.activityIndicator.isUserInteractionEnabled = false 63 | OperationQueue.main.addOperation({ () -> Void in 64 | self.addSubview(self.activityIndicator) 65 | self.activityIndicator.centerXAnchor.constraint(equalTo: self.centerXAnchor) 66 | self.activityIndicator.centerYAnchor.constraint(equalTo: self.centerYAnchor) 67 | self.addConstraint(NSLayoutConstraint(item: self.activityIndicator, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0.0)) 68 | self.addConstraint(NSLayoutConstraint(item: self.activityIndicator, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0.0)) 69 | self.activityIndicator.startAnimating() 70 | }) 71 | } 72 | } 73 | 74 | 75 | /// stop activityIndicator 76 | func hideActivityIndicator() { 77 | guard self.activityIndicator != nil else { 78 | return 79 | } 80 | OperationQueue.main.addOperation({ () -> Void in 81 | self.activityIndicator.stopAnimating() 82 | }) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Snakey List/Helpers/Extension/UIViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewExtension.swift 3 | // Snakey List 4 | // 5 | // Created by ali adam on 1/29/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIView { 12 | 13 | /// Add constraints to this view instances superview object to make sure this always has the same size as the superview. 14 | func bindFrameToSuperviewBounds() { 15 | guard let superview = self.superview else { 16 | print("Error! `superview` was nil – call `addSubview(view: UIView)` before calling `bindFrameToSuperviewBounds()` to fix this.") 17 | return 18 | } 19 | self.translatesAutoresizingMaskIntoConstraints = false 20 | superview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[subview]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["subview": self])) 21 | superview.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[subview]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["subview": self])) 22 | } 23 | /// take screen shot from this view 24 | func takeSnapshot() -> UIImage { 25 | UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale) 26 | drawHierarchy(in: self.bounds, afterScreenUpdates: true) 27 | let image = UIGraphicsGetImageFromCurrentImageContext() 28 | UIGraphicsEndImageContext() 29 | return image! 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Snakey List/Helpers/LocalizableWords.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LocalizableWords.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | // here you can find constant messages and any other constant words on the App 11 | struct LocalizableWords { 12 | 13 | // alert button title 14 | static let tryAgain = "Try Again" 15 | static let ok = "Okay" 16 | static let yes = "Yes" 17 | static let cancel = "Cancel" 18 | static let change = "Change" 19 | /// error messages and titles 20 | static let errorMessageTile = "Error Occured" 21 | static let parseErrorMessage = "Can Not Load And parse Please Try Again later" 22 | static let deleteTitle = "Delete Confirm" 23 | static let deleteConfrimation = "Do you really want to delete the item with identifier: " 24 | static let deleteErrorMessage = "Can Not delete Item Please Try Again later" 25 | static let updateErrorMessage = "Can Not Update UUID Please Try Again later" 26 | static let reorderErrorMessage = "Can Not reorder Items Please Try Again later" 27 | static let addNewItemTile = "Add Item" 28 | static let addNewItemMessage = "Please Enter Image URL" 29 | static let changeUUIDTile = "Change UUID" 30 | static let changeUUIDMessage = "You have selected the item with identifier:\nxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\nAgain, replace the “UUID” with the real identifier of the item." 31 | static let placeHolderUUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /Snakey List/Helpers/MockLoader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MockLoader.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// constant file name to easly change them at any time 12 | private enum Constants { 13 | static let itemListFileName = "ItemsList" 14 | static let FileExtension = "json" 15 | static let FileAndExt = "\(itemListFileName).\(FileExtension)" 16 | static let backUpFileAndExt = "backUP.\(FileExtension)" 17 | } 18 | /// this struct to load the items list file form bundel and add it to the doc diractory 19 | struct MockLoader { 20 | 21 | /// load file from doc if exist or from bundel if not and add it to the diractroy 22 | /// 23 | /// - Parameter fileName: file name to load 24 | /// - Returns: data represnt the file 25 | static fileprivate func loadMock(forFile fileName: String) -> Data? { 26 | 27 | if fileExists(Constants.FileAndExt) { 28 | guard let url = getFileURL(Constants.FileAndExt), let data = FileManager.default.contents(atPath: url.path) else { 29 | return nil 30 | } 31 | return data 32 | } 33 | guard let file = Bundle.main.url(forResource: fileName, withExtension: Constants.FileExtension), 34 | let data = try? Data(contentsOf: file) else { return nil } 35 | try? FileManager.default.copyItem(at: file, to: getFileURL(Constants.FileAndExt)!) 36 | return data 37 | 38 | } 39 | 40 | /// varible represnt the data on file this what others can access 41 | static var itemsListMock: Data? { 42 | guard let result: Data = loadMock(forFile: Constants.itemListFileName) else { return nil } 43 | return result 44 | } 45 | 46 | /// cheack if file exist on doc dir or not 47 | static fileprivate func fileExists(_ fileName: String) -> Bool { 48 | guard let url = getFileURL(fileName) else { 49 | return false 50 | } 51 | return FileManager.default.fileExists(atPath: url.path) 52 | } 53 | 54 | /// get file url by adding its name to the doc diractory 55 | static fileprivate func getFileURL(_ fileName: String) -> URL? { 56 | guard let cachurl = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else { 57 | return nil 58 | } 59 | let url = cachurl.appendingPathComponent(fileName, isDirectory: false) 60 | return url 61 | 62 | } 63 | 64 | /// update date on current file 65 | static func updateitems(_ data: Data) -> Bool { 66 | let url = getFileURL(Constants.FileAndExt)! 67 | do { 68 | if FileManager.default.fileExists(atPath: url.path) { 69 | createBackUpFileBeforeUpdate() 70 | //url.setTemporaryResourceValue(Constants.backUpFileAndExt, forKey: .nameKey) 71 | 72 | } 73 | if FileManager.default.createFile(atPath: url.path, contents: data, attributes: nil) { 74 | try FileManager.default.removeItem(at: getFileURL(Constants.backUpFileAndExt)!) 75 | return true 76 | } 77 | else 78 | { 79 | return false 80 | } 81 | } catch { 82 | return false 83 | } 84 | } 85 | 86 | /// create back file from current file to backup data in case any error happen 87 | @discardableResult static fileprivate func createBackUpFileBeforeUpdate() -> Bool { 88 | do { 89 | let originPath = getFileURL(Constants.FileAndExt)! 90 | let destinationPath = getFileURL(Constants.backUpFileAndExt)! 91 | try FileManager.default.moveItem(at: originPath, to: destinationPath) 92 | return true 93 | } catch { 94 | print(error) 95 | return false 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Snakey List/Helpers/StoryboardScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StoryboardScene.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | // this to mange all screen it helpful when you have more than one storyboard 13 | // 14 | protocol StoryboardSceneType { 15 | static var storyboardName: String { get } 16 | } 17 | 18 | extension StoryboardSceneType { 19 | /// load storyboard by it's name 20 | /// 21 | /// - Returns: storyboarf loaded 22 | static func storyboard() -> UIStoryboard { 23 | return UIStoryboard(name: self.storyboardName, bundle: nil) 24 | } 25 | 26 | 27 | /// load storyboard first Controller 28 | static func initialViewController() -> UIViewController { 29 | guard let vc = storyboard().instantiateInitialViewController() else { 30 | fatalError("Failed to instantiate initialViewController for \(self.storyboardName)") 31 | } 32 | return vc 33 | } 34 | /// load view Controller with idebtifier 35 | /// 36 | /// - Parameter withIdentifier: Controller identifier 37 | /// - Returns: Controller 38 | static func viewController(withIdentifier:String) -> UIViewController { 39 | return Self.storyboard().instantiateViewController(withIdentifier:withIdentifier) 40 | } 41 | } 42 | 43 | /// enum contain refrence of all screens on the app 44 | enum StoryboardScene { 45 | enum SplashViewController: StoryboardSceneType { 46 | static let storyboardName = "Main" 47 | static let viewController = "SplashViewController" 48 | static func initialViewController() -> UIViewController { 49 | return viewController(withIdentifier: viewController) 50 | } 51 | } 52 | enum ItemsGridViewController: StoryboardSceneType { 53 | static let storyboardName = "Main" 54 | static let viewController = "ItemsGridViewController" 55 | static func initialViewController() -> UIViewController { 56 | return viewController(withIdentifier: viewController) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Snakey List/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundleDisplayName 16 | Snakey List 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Snakey List/Layouts/SnakeUICollectionLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnakeUICollectionLayout.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/27/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// SnakeUICollectionLayout this is how i draw the layout of collection view and handle drag and drop 12 | class SnakeUICollectionLayout: UICollectionViewLayout { 13 | 14 | typealias IndexAndItems = (index:Int, item:Int) // reprsnt item and it's index on the row 15 | typealias RowIndexAndItems = (row:Int, rowItem:IndexAndItems) // repesnt the index of the row and item on it 16 | 17 | // compilation handler called after drag end 18 | var didReorderHandler: (_ fromIndexPath: IndexPath, _ toIndexPath: IndexPath) -> Void = { _, _ in } 19 | 20 | fileprivate var longPressGestureRecognizer = UILongPressGestureRecognizer() 21 | fileprivate var panGestureRecognizer = UIPanGestureRecognizer() 22 | // view that contain snapshot of the cell 23 | fileprivate var dragView: DraggingView? 24 | // array contain index of pathes to animate delete or insert 25 | private var indexPathsToAnimate = [IndexPath]() 26 | 27 | // index for paths to move 28 | private var indexPathsToMove = [IndexPath]() 29 | 30 | fileprivate var numberOfColumns = 3 31 | fileprivate var cellPadding: CGFloat = 0 32 | 33 | // Array to keep a cache of attributes. 34 | fileprivate var cache = [UICollectionViewLayoutAttributes]() 35 | 36 | //Content height and size 37 | fileprivate var contentHeight: CGFloat = 0 38 | 39 | var rows : [RowIndexAndItems] = [] 40 | 41 | fileprivate var contentWidth: CGFloat { 42 | guard let collectionView = collectionView else { 43 | return 0 44 | } 45 | 46 | let insets = collectionView.contentInset 47 | return collectionView.bounds.width - (insets.left + insets.right) 48 | } 49 | 50 | override var collectionViewContentSize: CGSize { 51 | return CGSize(width: contentWidth, height: contentHeight) 52 | } 53 | 54 | 55 | 56 | override init() { 57 | super.init() 58 | addObserver(self, forKeyPath: "collectionView", options: [], context: nil) 59 | } 60 | 61 | required init?(coder aDecoder: NSCoder) { 62 | super.init(coder: aDecoder) 63 | addObserver(self, forKeyPath: "collectionView", options: [], context: nil) 64 | } 65 | 66 | deinit { 67 | self.removeObserver(self, forKeyPath: "collectionView", context: nil) 68 | } 69 | 70 | override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { 71 | if keyPath == "collectionView" { 72 | // add gest to the collection view 73 | setupGestureRecognizers() 74 | } else { 75 | super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) 76 | } 77 | } 78 | 79 | override func prepare() { 80 | cache.removeAll() 81 | guard cache.isEmpty == true, let collectionView = collectionView else { 82 | return 83 | } 84 | 85 | // Pre-Calculates the X Offset for every column and adds an array to increment the currently max Y Offset for each column 86 | let columnWidth = contentWidth / CGFloat(numberOfColumns) 87 | var xOffset = [CGFloat](repeating: 0, count: numberOfColumns) 88 | contentHeight = 0 89 | var column = 0 90 | var yOffset = [CGFloat](repeating: 0, count: numberOfColumns) 91 | // Iterates through the list of items in the first section 92 | var index = 0 93 | for item in 0 ..< collectionView.numberOfItems(inSection: 0) { 94 | 95 | // Pre-Calculates the position of each item in column and row 96 | if item % 3 == 0 || item == 0 97 | { 98 | let i = item 99 | index = index + 1 100 | if index % 2 != 0 { 101 | 102 | rows.append(RowIndexAndItems(index,IndexAndItems(0,i))) 103 | rows.append(RowIndexAndItems(index,IndexAndItems(1,i+1))) 104 | rows.append(RowIndexAndItems(index,IndexAndItems(2,i+2))) 105 | } 106 | else 107 | { 108 | rows.append(RowIndexAndItems(index,IndexAndItems(0,i+2))) 109 | rows.append(RowIndexAndItems(index,IndexAndItems(1,i+1))) 110 | rows.append(RowIndexAndItems(index,IndexAndItems(2,i))) 111 | 112 | } 113 | } 114 | let indexPath = IndexPath(item: item, section: 0) 115 | let height = cellPadding * 2 + columnWidth 116 | let rowIndexAndItems = rows.filter({$0.rowItem.item == item}) 117 | var frame = CGRect(x: xOffset[column], y: yOffset[column], width: columnWidth, height: height) 118 | 119 | if item == 0 { 120 | xOffset[column] = 0 121 | yOffset[column] = 0 122 | frame = CGRect(x: 0, y:0, 123 | width: columnWidth * 2 , height: columnWidth * 2) 124 | 125 | } 126 | else if item == 1 { 127 | xOffset[column] = columnWidth * 2 128 | yOffset[column] = 0 129 | 130 | frame = CGRect(x: columnWidth * 2, y:0, 131 | width: columnWidth , height: columnWidth ) 132 | 133 | } 134 | else if item == 2 { 135 | xOffset[column] = columnWidth * 2 136 | yOffset[column] = columnWidth 137 | 138 | frame = CGRect(x: columnWidth * 2, y:columnWidth, 139 | width: columnWidth , height: columnWidth ) 140 | 141 | } 142 | else if let item = rowIndexAndItems.first { 143 | let x = CGFloat(item.rowItem.index) * columnWidth 144 | let y = CGFloat ((rowIndexAndItems.first?.row)!) * columnWidth 145 | 146 | xOffset[column] = x 147 | yOffset[column] = y 148 | 149 | frame = CGRect(x: x, y: y, width: columnWidth , height: columnWidth ) 150 | } 151 | 152 | let insetFrame = frame.insetBy(dx: cellPadding, dy: cellPadding) 153 | // Creates an UICollectionViewLayoutItem with the frame and add it to the cache 154 | let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath) 155 | attributes.frame = insetFrame 156 | cache.append(attributes) 157 | 158 | // Updates the collection view content height 159 | contentHeight = max(contentHeight, frame.maxY) 160 | yOffset[column] = yOffset[column] + height 161 | column = column < (numberOfColumns - 1) ? (column + 1) : 0 162 | } 163 | } 164 | 165 | override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 166 | 167 | var visibleLayoutAttributes = [UICollectionViewLayoutAttributes]() 168 | 169 | // Loop through the cache and look for items in the rect 170 | for attributes in cache { 171 | if attributes.frame.intersects(rect) { 172 | visibleLayoutAttributes.append(attributes) 173 | } 174 | } 175 | return visibleLayoutAttributes 176 | } 177 | 178 | override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 179 | return cache[indexPath.item] 180 | } 181 | 182 | open override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 183 | guard let attributes = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath) else { 184 | return nil 185 | } 186 | 187 | guard indexPathsToAnimate.contains(itemIndexPath) else { 188 | if let index = indexPathsToMove.index(of: itemIndexPath) { 189 | indexPathsToMove.remove(at: index) 190 | attributes.alpha = 1.0 191 | return attributes 192 | } 193 | return nil 194 | } 195 | 196 | if let index = indexPathsToAnimate.index(of: itemIndexPath) { 197 | indexPathsToAnimate.remove(at: index) 198 | } 199 | 200 | // insert animation 201 | attributes.alpha = 1.0 202 | attributes.center = CGPoint(x: collectionView!.frame.width - 23.5, y: -24.5) 203 | attributes.transform = CGAffineTransform(scaleX: 0.15, y: 0.15) 204 | attributes.zIndex = 99 205 | 206 | 207 | return attributes 208 | } 209 | 210 | open override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 211 | guard let attributes = super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath) else { 212 | return nil 213 | } 214 | 215 | // in case if move animation 216 | guard indexPathsToAnimate.contains(itemIndexPath) else { 217 | if let index = indexPathsToMove.index(of: itemIndexPath) { 218 | indexPathsToMove.remove(at: index) 219 | attributes.alpha = 1.0 220 | attributes.transform = CGAffineTransform(scaleX: 0.1,y: 0.1) 221 | attributes.zIndex = -1 222 | return attributes 223 | } 224 | return nil 225 | } 226 | 227 | if let index = indexPathsToAnimate.index(of: itemIndexPath) { 228 | indexPathsToAnimate.remove(at: index) 229 | } 230 | // delete animation 231 | attributes.alpha = 1.0 232 | attributes.transform = CGAffineTransform(scaleX: 0.1,y: 0.1) 233 | attributes.zIndex = -1 234 | 235 | return attributes 236 | } 237 | 238 | open override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) { 239 | super.prepare(forCollectionViewUpdates: updateItems) 240 | 241 | var currentIndexPath: IndexPath? 242 | for updateItem in updateItems { 243 | switch updateItem.updateAction { 244 | case .insert: 245 | currentIndexPath = updateItem.indexPathAfterUpdate 246 | case .delete: 247 | currentIndexPath = updateItem.indexPathBeforeUpdate 248 | case .move: 249 | currentIndexPath = nil 250 | indexPathsToMove.append(updateItem.indexPathBeforeUpdate!) 251 | indexPathsToMove.append(updateItem.indexPathAfterUpdate!) 252 | default: 253 | currentIndexPath = nil 254 | } 255 | 256 | if let indexPath = currentIndexPath { 257 | indexPathsToAnimate.append(indexPath) 258 | } 259 | } 260 | } 261 | } 262 | 263 | 264 | // MARK: - UIGestureRecognizerDelegate 265 | extension SnakeUICollectionLayout : UIGestureRecognizerDelegate { 266 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 267 | if gestureRecognizer == longPressGestureRecognizer && otherGestureRecognizer == panGestureRecognizer { 268 | return true 269 | } else if gestureRecognizer == panGestureRecognizer { 270 | return otherGestureRecognizer == longPressGestureRecognizer 271 | } 272 | 273 | return true 274 | } 275 | 276 | // check f item can moved or not this to prevnt move of add cell 277 | func canMoveItemAtIndexPath(_ indexPath: IndexPath) -> Bool { 278 | if indexPath.item == (collectionView?.numberOfItems(inSection: 0))! - 1{ 279 | return false 280 | } 281 | return true 282 | } 283 | 284 | func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 285 | 286 | if gestureRecognizer == longPressGestureRecognizer { 287 | let location = gestureRecognizer.location(in: collectionView) 288 | if let indexPath = collectionView?.indexPathForItem(at: location), !canMoveItemAtIndexPath(indexPath) { 289 | return false 290 | } 291 | } 292 | 293 | let states: [UIGestureRecognizerState] = [.possible, .failed] 294 | if gestureRecognizer == longPressGestureRecognizer && !states.contains(collectionView!.panGestureRecognizer.state) { 295 | return false 296 | } else if gestureRecognizer == panGestureRecognizer && states.contains(longPressGestureRecognizer.state) { 297 | return false 298 | } 299 | 300 | return true 301 | } 302 | 303 | // MARK: - handleLongPressGestureRecognized methods get acopy of the draged cell and move it at end call the handler 304 | @objc func handleLongPressGestureRecognized(_ recognizer: UILongPressGestureRecognizer) { 305 | switch recognizer.state { 306 | case .began: 307 | let location = recognizer.location(in: collectionView) 308 | if let indexPath = collectionView!.indexPathForItem(at: location), let cell = collectionView!.cellForItem(at: indexPath) { 309 | dragView?.removeFromSuperview() 310 | let newDragView = DraggingView(cell: cell as! ItemCell) 311 | newDragView.dragIndexPath = indexPath 312 | newDragView.initialCenter = cell.center 313 | newDragView.dragCenter = cell.center 314 | newDragView.center = newDragView.dragCenter 315 | newDragView.fromIndexPath = indexPath 316 | dragView = newDragView 317 | collectionView?.addSubview(dragView!) 318 | invalidateLayout() 319 | UIView.animate(withDuration: 0.16, animations: { 320 | self.dragView?.transform = CGAffineTransform(scaleX: 1.1, y: 1.1) 321 | }) 322 | } 323 | case .ended: 324 | if let finalDragView = self.dragView { 325 | UIView.animate(withDuration: 0.2, delay: 0.0, options: [.beginFromCurrentState, .curveEaseIn], animations: { 326 | finalDragView.center = finalDragView.dragCenter 327 | finalDragView.transform = CGAffineTransform.identity 328 | }, completion: { _ in 329 | finalDragView.removeFromSuperview() 330 | if let fromIndexPath = finalDragView.fromIndexPath, let toIndexPath = finalDragView.toIndexPath { 331 | if toIndexPath.item != (self.collectionView?.numberOfItems(inSection: 0))! - 1{ 332 | self.didReorderHandler(fromIndexPath, toIndexPath) 333 | } 334 | } 335 | self.dragView = nil 336 | self.invalidateLayout() 337 | }) 338 | } 339 | default: 340 | break 341 | } 342 | } 343 | 344 | @objc func handlePanGestureRecognized(_ recognizer: UIPanGestureRecognizer) { 345 | let translation = recognizer.translation(in: collectionView!) 346 | switch recognizer.state { 347 | case .changed: 348 | if let newDragView = dragView { 349 | newDragView.center.x = newDragView.initialCenter.x + translation.x 350 | newDragView.center.y = newDragView.initialCenter.y + translation.y 351 | if let _ = newDragView.dragIndexPath, 352 | let toIndexPath = collectionView!.indexPathForItem(at: newDragView.center), 353 | let targetLayoutAttributes = layoutAttributesForItem(at: toIndexPath) { 354 | 355 | newDragView.dragIndexPath = toIndexPath 356 | newDragView.dragCenter = targetLayoutAttributes.center 357 | newDragView.bounds = targetLayoutAttributes.bounds 358 | newDragView.toIndexPath = toIndexPath 359 | } 360 | } 361 | default: 362 | break 363 | } 364 | } 365 | 366 | /// add gest to collection 367 | fileprivate func setupGestureRecognizers() { 368 | if let _ = self.collectionView { 369 | collectionView!.removeGestureRecognizer(longPressGestureRecognizer) 370 | collectionView!.removeGestureRecognizer(panGestureRecognizer) 371 | 372 | longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGestureRecognized(_:))) 373 | longPressGestureRecognizer.delegate = self 374 | collectionView!.addGestureRecognizer(longPressGestureRecognizer) 375 | 376 | panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGestureRecognized(_:))) 377 | panGestureRecognizer.delegate = self 378 | panGestureRecognizer.maximumNumberOfTouches = 1 379 | collectionView!.addGestureRecognizer(panGestureRecognizer) 380 | } 381 | } 382 | 383 | } 384 | 385 | 386 | -------------------------------------------------------------------------------- /Snakey List/Models/Item.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Item.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | /// item model 11 | struct Item : Codable { 12 | let uuid : String? 13 | let imageUrlString : String? 14 | 15 | enum CodingKeys: String, CodingKey { 16 | 17 | case uuid = "uuid" 18 | case imageUrlString = "imageUrlString" 19 | } 20 | 21 | init(from decoder: Decoder) throws { 22 | let values = try decoder.container(keyedBy: CodingKeys.self) 23 | uuid = try values.decodeIfPresent(String.self, forKey: .uuid) 24 | imageUrlString = try values.decodeIfPresent(String.self, forKey: .imageUrlString) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Snakey List/Models/ItemsList.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // ItemsList.swift 4 | // Snakey List 5 | // 6 | // Created by Ali Adam on 1/26/18. 7 | // Copyright © 2018 Ali Adam. All rights reserved. 8 | // 9 | 10 | 11 | import Foundation 12 | /// item list model contain list of items 13 | struct ItemsList : Codable { 14 | var items : [Item]? 15 | 16 | enum CodingKeys: String, CodingKey { 17 | case items = "items" 18 | } 19 | 20 | init(from decoder: Decoder) throws { 21 | let values = try decoder.container(keyedBy: CodingKeys.self) 22 | items = try values.decodeIfPresent([Item].self, forKey: .items) 23 | } 24 | 25 | mutating func deleteItem (atIndex index:Int){ 26 | var it = items 27 | it?.remove(at: index) 28 | items = it 29 | } 30 | mutating func changeUUIdForItem (atIndex index:Int,newUUID uuid:String){ 31 | var it = items 32 | let oldItem = it![index] 33 | let json = """ 34 | { 35 | "uuid": "\(uuid)", 36 | "imageUrlString": "\(oldItem.imageUrlString ?? "")" 37 | } 38 | """.data(using: .utf8)! 39 | let item = try! JSONDecoder().decode(Item.self, from: json) 40 | it?.remove(at: index) 41 | it?.insert(item, at: index) 42 | items = it 43 | } 44 | mutating func addItemWith(uuid:String, imageurl url:String){ 45 | var it = items 46 | 47 | let json = """ 48 | { 49 | "uuid": "\(uuid)", 50 | "imageUrlString": "\(url)" 51 | } 52 | """.data(using: .utf8)! 53 | let item = try! JSONDecoder().decode(Item.self, from: json) 54 | it?.append(item) 55 | items = it 56 | } 57 | 58 | mutating func moveItem( fromIndex: Int, toIndex: Int) 59 | { 60 | var it = items 61 | let oldItem = it![fromIndex] 62 | it?.remove(at: fromIndex) 63 | it?.insert(oldItem, at: toIndex) 64 | items = it 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Snakey List/Network/APPError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APPError.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | 10 | /// error enum 11 | /// 12 | enum APPError: Error { 13 | case couldNotLoadMock 14 | case couldNotParseJson 15 | case couldNotUpdate 16 | } 17 | -------------------------------------------------------------------------------- /Snakey List/Network/NetworkProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkProvider.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | 10 | import UIKit 11 | 12 | /// shard singlton act like a network layer get and update the data 13 | struct NetworkProvider { 14 | static let shared = NetworkProvider() 15 | 16 | private init() { 17 | } 18 | /// get list of items 19 | /// 20 | func itemList(completionHandler: @escaping (NetworkResponse) -> ()){ 21 | guard let data = MockLoader.itemsListMock else { 22 | completionHandler(.error(APPError.couldNotLoadMock)) 23 | return 24 | } 25 | do{ 26 | let decoder = JSONDecoder() 27 | let itemsList = try decoder.decode(ItemsList.self, from: data) 28 | completionHandler(.success(itemsList)) 29 | } catch { 30 | completionHandler(.error(APPError.couldNotParseJson)) 31 | } 32 | 33 | 34 | 35 | } 36 | /// update items list with new values 37 | func updateItemList(with itemsList: ItemsList,completionHandler: @escaping (NetworkResponse) -> ()){ 38 | do{ 39 | let encoder = JSONEncoder() 40 | let data = try encoder.encode(itemsList) 41 | let saved = MockLoader.updateitems(data) 42 | completionHandler(.success(saved)) 43 | } catch { 44 | completionHandler(.error(APPError.couldNotUpdate)) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Snakey List/Network/NetworkResponse.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkResponse.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | 10 | /// respnse enumration 11 | /// 12 | /// - error: in case error occure pass the error 13 | /// - success: in success case pass the object to it 14 | enum NetworkResponse { 15 | case error(Error) 16 | case success(Element) 17 | 18 | } 19 | /// enum repsent user response if he confirm to do some thing or not 20 | /// 21 | enum ConfirmResponse { 22 | case notConfirm(Element) 23 | case confirm(Element) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Snakey List/Resources/ItemsList.json: -------------------------------------------------------------------------------- 1 | { 2 | "items": [ 3 | { 4 | "uuid": "c35a6eb4-7178-45cc-bf1b-393922407621", 5 | "imageUrlString": "http://dummyimage.com/250x250.png/1fa2dd/ffffff" 6 | }, 7 | { 8 | "uuid": "489523f2-f7b8-4b9d-b7bd-a4828f0d49a2", 9 | "imageUrlString": "http://dummyimage.com/250x250.png/1f4444/ffffff" 10 | }, 11 | { 12 | "uuid": "ac37c63a-b1bf-4e6d-a0c2-2607260b35a3", 13 | "imageUrlString": "http://dummyimage.com/250x250.png/1ddddd/000000" 14 | }, 15 | { 16 | "uuid": "49d7f92e-76b0-4a20-8a55-5b7d0c96707e", 17 | "imageUrlString": "http://dummyimage.com/250x250.png/2fff44/ffffff" 18 | }, 19 | { 20 | "uuid": "85800a08-5f21-47e3-b887-34427fc605e4", 21 | "imageUrlString": "http://dummyimage.com/250x250.png/cc0000/ffffff" 22 | }, 23 | { 24 | "uuid": "e5eb4240-3c7c-4dc6-a473-f7236b72cdc7", 25 | "imageUrlString": "http://dummyimage.com/250x250.png/d1dd11/000000" 26 | }, 27 | { 28 | "uuid": "dd3c6af0-d1db-49b6-9559-56afdef883c4", 29 | "imageUrlString": "http://dummyimage.com/250x250.png/1d1dd1/000000" 30 | }, 31 | { 32 | "uuid": "6b07bf03-7b36-4350-8b30-9f4ba92c2915", 33 | "imageUrlString": "http://dummyimage.com/250x250.png/11dddd/000000" 34 | }, 35 | { 36 | "uuid": "e684a7d7-aee6-44ea-88c2-7cae63eeccc7", 37 | "imageUrlString": "http://dummyimage.com/250x250.png/5fa2dd/ffffff" 38 | }, 39 | { 40 | "uuid": "14598dbf-8803-4fe4-b66c-d00675044020", 41 | "imageUrlString": "http://dummyimage.com/250x250.png/ccffff/ffffff" 42 | }, 43 | { 44 | "uuid": "5198fa13-4a68-4efd-b15e-f1ee26f2c83f", 45 | "imageUrlString": "http://dummyimage.com/250x250.png/ccff00/ffffff" 46 | } 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /Snakey List/Views/DraggingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DraggingView.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/28/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | /// view used for dragging contain snapshot of the item 13 | class DraggingView: UIView { 14 | var dragIndexPath: IndexPath? // Current indexPath 15 | var dragCenter = CGPoint.zero // point being dragged from 16 | var fromIndexPath: IndexPath? // Original index path 17 | var toIndexPath: IndexPath? // index path the dragView was dragged to 18 | var initialCenter = CGPoint.zero 19 | 20 | init(cell: ItemCell) { 21 | super.init(frame: CGRect.zero) 22 | backgroundColor = UIColor.clear 23 | autoresizingMask = cell.autoresizingMask 24 | clipsToBounds = true 25 | frame = CGRect(x: 0, y: 0, width: cell.bounds.width, height: cell.bounds.height) 26 | let dragView = cell.dragView() 27 | addSubview(dragView) 28 | dragView.bindFrameToSuperviewBounds() 29 | } 30 | 31 | required init?(coder _: NSCoder) { 32 | fatalError("init(coder:) has not been implemented") 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Snakey List/Views/ItemCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ItemCell.swift 3 | // Snakey List 4 | // 5 | // Created by Ali Adam on 1/26/18. 6 | // Copyright © 2018 Ali Adam. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ItemCell: UICollectionViewCell { 12 | 13 | @IBOutlet weak var deleteBTN: UIButton! 14 | @IBOutlet weak var imageView: UIImageView! 15 | var isAddView = false 16 | // add btn complation handler 17 | var addBTNHandler: (_ index :Int , _ cell:ItemCell) -> Void = { _,_ in } 18 | 19 | // delete btn complation handler 20 | var deleteBTNHandler: (_ index :Int , _ cell:ItemCell) -> Void = { _,_ in } 21 | 22 | @IBOutlet weak var addBTN: UIButton! 23 | 24 | override init(frame: CGRect) { 25 | super.init(frame: frame) 26 | } 27 | required init?(coder aDecoder: NSCoder) { 28 | super.init(coder: aDecoder) 29 | } 30 | 31 | override func awakeFromNib() { 32 | super.awakeFromNib() 33 | addBTN.titleLabel?.lineBreakMode = .byWordWrapping 34 | addBTN.titleLabel?.numberOfLines = 2 35 | addBTN.titleLabel?.textAlignment = .center; 36 | addBTN.setTitle(" + \nAdd ", for: .normal) 37 | addBTN.backgroundColor = .blue 38 | 39 | } 40 | 41 | /// config the cell and load the image 42 | /// 43 | /// - Parameters: 44 | /// - imageUrlString: image url 45 | /// - index: index of cell 46 | /// - isAdd: is it the add cell or not 47 | func Config(imageUrlString: String ,index: Int ,isAdd:Bool) { 48 | self.imageView.tag = index 49 | self.imageView.image = #imageLiteral(resourceName: "placeholder") 50 | if (isAdd) { 51 | deleteBTN.isHidden = true 52 | imageView.isHidden = true 53 | addBTN.setTitle(" + \nAdd ", for: .normal) 54 | addBTN.backgroundColor = .gray 55 | } 56 | else { 57 | deleteBTN.isHidden = false 58 | imageView.isHidden = false 59 | addBTN.setTitle("", for: .normal) 60 | addBTN.backgroundColor = .clear 61 | imageView.loadImageFromUrl(imageUrlString, withActivityIndicator: .whiteLarge, andCach: true) 62 | } 63 | } 64 | 65 | @IBAction func deleteBTNAction(_ sender: Any) { 66 | self.deleteBTNHandler(self.imageView.tag,self) 67 | } 68 | @IBAction func addBTNAction(_ sender: Any) { 69 | 70 | self.addBTNHandler(self.imageView.tag,self) 71 | } 72 | 73 | // return drag view contain snap shot of the cell 74 | func dragView() -> UIView { 75 | var dragViewFrame = self.imageView.bounds 76 | dragViewFrame.origin.x = (bounds.size.width - dragViewFrame.size.width) / 2 77 | dragViewFrame.origin.y = (bounds.size.height - dragViewFrame.size.height) / 2 78 | let dragView = UIView(frame: dragViewFrame) 79 | dragView.clipsToBounds = true 80 | let imageRect = CGRect(x: 0, y: 0, width: self.imageView.frame.size.width, height: self.imageView.frame.size.width) 81 | let imageView = UIImageView(frame: imageRect) 82 | imageView.image = self.contentView.takeSnapshot() 83 | imageView.contentMode = self.imageView.contentMode 84 | imageView.clipsToBounds = true 85 | dragView.addSubview(imageView) 86 | imageView.bindFrameToSuperviewBounds() 87 | dragView.transform = contentView.transform 88 | return dragView 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /screenshots/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/screenshots/1.gif -------------------------------------------------------------------------------- /screenshots/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliAdam/Snakey-List/be6fecb6efe0ab2b938a2d64aaf740ec4bf17e61/screenshots/2.gif --------------------------------------------------------------------------------