diff --git a/ProjectManager/CoreDataManager.swift b/ProjectManager/CoreDataManager.swift new file mode 100644 index 000000000..6c91d7323 --- /dev/null +++ b/ProjectManager/CoreDataManager.swift @@ -0,0 +1,56 @@ +// +// CoreDataManager.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/27. +// + +import UIKit + +final class CoreDataManager { + + static var shared: CoreDataManager = CoreDataManager() + let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext + var entities: [Entity] = [] + + func saveToContext() { + do { + try context.save() + } catch { + print(error.localizedDescription) + } + } + + func createEntity(title: String, body: String, duration: Date, status: Status) { + let newEntity = Entity(context: context) + newEntity.title = title + newEntity.body = body + newEntity.duration = duration + newEntity.status = status.rawValue + + saveToContext() + getAllEntity() + } + + func getAllEntity() { + do { + entities = try context.fetch(Entity.fetchRequest()) + } catch { + print(error.localizedDescription) + } + } + + func updateEntity(entity: Entity, newTitle: String, newBody: String, newDuration: Date) { + entity.title = newTitle + entity.body = newBody + entity.duration = newDuration + + saveToContext() + } + + func deleteEntity(entity: Entity) { + context.delete(entity) + + saveToContext() + } +} diff --git a/ProjectManager/Entity+CoreDataClass.swift b/ProjectManager/Entity+CoreDataClass.swift new file mode 100644 index 000000000..80a442e8c --- /dev/null +++ b/ProjectManager/Entity+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// Entity+CoreDataClass.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/26. +// +// + +import Foundation +import CoreData + +@objc(Entity) +public class Entity: NSManagedObject { + +} diff --git a/ProjectManager/Entity+CoreDataProperties.swift b/ProjectManager/Entity+CoreDataProperties.swift new file mode 100644 index 000000000..f6d0d92c2 --- /dev/null +++ b/ProjectManager/Entity+CoreDataProperties.swift @@ -0,0 +1,28 @@ +// +// Entity+CoreDataProperties.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/26. +// +// + +import Foundation +import CoreData + + +extension Entity { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "Entity") + } + + @NSManaged public var duration: Date? + @NSManaged public var title: String? + @NSManaged public var body: String? + @NSManaged public var status: String? + +} + +extension Entity : Identifiable { + +} diff --git a/ProjectManager/ProjectManager.xcodeproj/project.pbxproj b/ProjectManager/ProjectManager.xcodeproj/project.pbxproj index 5d3ff1c56..750733095 100644 --- a/ProjectManager/ProjectManager.xcodeproj/project.pbxproj +++ b/ProjectManager/ProjectManager.xcodeproj/project.pbxproj @@ -9,21 +9,43 @@ /* Begin PBXBuildFile section */ C7431F0625F51E1D0094C4CF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7431F0525F51E1D0094C4CF /* AppDelegate.swift */; }; C7431F0825F51E1D0094C4CF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7431F0725F51E1D0094C4CF /* SceneDelegate.swift */; }; - C7431F0A25F51E1D0094C4CF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7431F0925F51E1D0094C4CF /* ViewController.swift */; }; + C7431F0A25F51E1D0094C4CF /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7431F0925F51E1D0094C4CF /* MainViewController.swift */; }; C7431F0D25F51E1D0094C4CF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7431F0B25F51E1D0094C4CF /* Main.storyboard */; }; C7431F0F25F51E1E0094C4CF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7431F0E25F51E1E0094C4CF /* Assets.xcassets */; }; C7431F1225F51E1E0094C4CF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7431F1025F51E1E0094C4CF /* LaunchScreen.storyboard */; }; + D0293F532ACAB3CE00505749 /* DateFormatManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0293F522ACAB3CE00505749 /* DateFormatManager.swift */; }; + D0293F5A2ACBAA2B00505749 /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0293F592ACBAA2B00505749 /* Status.swift */; }; + D06DA8E52AC2BA9F00314499 /* Todo.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = D06DA8E32AC2BA9F00314499 /* Todo.xcdatamodeld */; }; + D06DA8E82AC2BB0D00314499 /* Entity+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06DA8E62AC2BB0D00314499 /* Entity+CoreDataClass.swift */; }; + D06DA8E92AC2BB0D00314499 /* Entity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06DA8E72AC2BB0D00314499 /* Entity+CoreDataProperties.swift */; }; + D06DA8EB2AC3B87200314499 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06DA8EA2AC3B87200314499 /* CoreDataManager.swift */; }; + D09389A92AC20FC5008A8304 /* CollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D09389A72AC20FC5008A8304 /* CollectionReusableView.swift */; }; + D09389AA2AC20FC5008A8304 /* CollectionReusableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D09389A82AC20FC5008A8304 /* CollectionReusableView.xib */; }; + D0CED7782ABEAB570081ABE2 /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CED7762ABEAB570081ABE2 /* CollectionViewCell.swift */; }; + D0CED7792ABEAB570081ABE2 /* CollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D0CED7772ABEAB570081ABE2 /* CollectionViewCell.xib */; }; + D0CED7812ABEB18D0081ABE2 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CED7802ABEB18D0081ABE2 /* SecondViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ C7431F0225F51E1D0094C4CF /* ProjectManager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProjectManager.app; sourceTree = BUILT_PRODUCTS_DIR; }; C7431F0525F51E1D0094C4CF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; C7431F0725F51E1D0094C4CF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - C7431F0925F51E1D0094C4CF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C7431F0925F51E1D0094C4CF /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; C7431F0C25F51E1D0094C4CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; C7431F0E25F51E1E0094C4CF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C7431F1125F51E1E0094C4CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; C7431F1325F51E1E0094C4CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D0293F522ACAB3CE00505749 /* DateFormatManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatManager.swift; sourceTree = ""; }; + D0293F592ACBAA2B00505749 /* Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Status.swift; sourceTree = ""; }; + D06DA8E42AC2BA9F00314499 /* Todo.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Todo.xcdatamodel; sourceTree = ""; }; + D06DA8E62AC2BB0D00314499 /* Entity+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Entity+CoreDataClass.swift"; sourceTree = ""; }; + D06DA8E72AC2BB0D00314499 /* Entity+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Entity+CoreDataProperties.swift"; sourceTree = ""; }; + D06DA8EA2AC3B87200314499 /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = SOURCE_ROOT; }; + D09389A72AC20FC5008A8304 /* CollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionReusableView.swift; sourceTree = ""; }; + D09389A82AC20FC5008A8304 /* CollectionReusableView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CollectionReusableView.xib; sourceTree = ""; }; + D0CED7762ABEAB570081ABE2 /* CollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = ""; }; + D0CED7772ABEAB570081ABE2 /* CollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CollectionViewCell.xib; sourceTree = ""; }; + D0CED7802ABEB18D0081ABE2 /* SecondViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -40,6 +62,8 @@ C7431EF925F51E1D0094C4CF = { isa = PBXGroup; children = ( + D06DA8E62AC2BB0D00314499 /* Entity+CoreDataClass.swift */, + D06DA8E72AC2BB0D00314499 /* Entity+CoreDataProperties.swift */, C7431F0425F51E1D0094C4CF /* ProjectManager */, C7431F0325F51E1D0094C4CF /* Products */, ); @@ -54,17 +78,82 @@ sourceTree = ""; }; C7431F0425F51E1D0094C4CF /* ProjectManager */ = { + isa = PBXGroup; + children = ( + D0293F582ACBAA1D00505749 /* Enum */, + D0CED77F2ABEAEAC0081ABE2 /* Resources */, + D0CED77E2ABEAE800081ABE2 /* Application */, + D0CED77D2ABEAE600081ABE2 /* Controllers */, + D0CED77C2ABEAE520081ABE2 /* ViewModels */, + D0CED77B2ABEAE400081ABE2 /* Views */, + D0CED77A2ABEAE3A0081ABE2 /* Models */, + ); + path = ProjectManager; + sourceTree = ""; + }; + D0293F582ACBAA1D00505749 /* Enum */ = { + isa = PBXGroup; + children = ( + D0293F592ACBAA2B00505749 /* Status.swift */, + ); + path = Enum; + sourceTree = ""; + }; + D0CED77A2ABEAE3A0081ABE2 /* Models */ = { + isa = PBXGroup; + children = ( + D06DA8EA2AC3B87200314499 /* CoreDataManager.swift */, + ); + path = Models; + sourceTree = ""; + }; + D0CED77B2ABEAE400081ABE2 /* Views */ = { + isa = PBXGroup; + children = ( + C7431F0B25F51E1D0094C4CF /* Main.storyboard */, + C7431F1025F51E1E0094C4CF /* LaunchScreen.storyboard */, + D0CED7772ABEAB570081ABE2 /* CollectionViewCell.xib */, + D09389A82AC20FC5008A8304 /* CollectionReusableView.xib */, + ); + path = Views; + sourceTree = ""; + }; + D0CED77C2ABEAE520081ABE2 /* ViewModels */ = { + isa = PBXGroup; + children = ( + D0CED7762ABEAB570081ABE2 /* CollectionViewCell.swift */, + D09389A72AC20FC5008A8304 /* CollectionReusableView.swift */, + D0293F522ACAB3CE00505749 /* DateFormatManager.swift */, + ); + path = ViewModels; + sourceTree = ""; + }; + D0CED77D2ABEAE600081ABE2 /* Controllers */ = { + isa = PBXGroup; + children = ( + C7431F0925F51E1D0094C4CF /* MainViewController.swift */, + D0CED7802ABEB18D0081ABE2 /* SecondViewController.swift */, + ); + path = Controllers; + sourceTree = ""; + }; + D0CED77E2ABEAE800081ABE2 /* Application */ = { isa = PBXGroup; children = ( C7431F0525F51E1D0094C4CF /* AppDelegate.swift */, C7431F0725F51E1D0094C4CF /* SceneDelegate.swift */, - C7431F0925F51E1D0094C4CF /* ViewController.swift */, - C7431F0B25F51E1D0094C4CF /* Main.storyboard */, + ); + path = Application; + sourceTree = ""; + }; + D0CED77F2ABEAEAC0081ABE2 /* Resources */ = { + isa = PBXGroup; + children = ( C7431F0E25F51E1E0094C4CF /* Assets.xcassets */, - C7431F1025F51E1E0094C4CF /* LaunchScreen.storyboard */, C7431F1325F51E1E0094C4CF /* Info.plist */, + D06DA8E32AC2BA9F00314499 /* Todo.xcdatamodeld */, ); - path = ProjectManager; + path = Resources; sourceTree = ""; }; /* End PBXGroup section */ @@ -124,8 +213,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D09389AA2AC20FC5008A8304 /* CollectionReusableView.xib in Resources */, C7431F1225F51E1E0094C4CF /* LaunchScreen.storyboard in Resources */, C7431F0F25F51E1E0094C4CF /* Assets.xcassets in Resources */, + D0CED7792ABEAB570081ABE2 /* CollectionViewCell.xib in Resources */, C7431F0D25F51E1D0094C4CF /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -137,9 +228,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C7431F0A25F51E1D0094C4CF /* ViewController.swift in Sources */, + C7431F0A25F51E1D0094C4CF /* MainViewController.swift in Sources */, + D06DA8E52AC2BA9F00314499 /* Todo.xcdatamodeld in Sources */, C7431F0625F51E1D0094C4CF /* AppDelegate.swift in Sources */, + D06DA8E92AC2BB0D00314499 /* Entity+CoreDataProperties.swift in Sources */, + D0CED7782ABEAB570081ABE2 /* CollectionViewCell.swift in Sources */, + D0293F532ACAB3CE00505749 /* DateFormatManager.swift in Sources */, + D09389A92AC20FC5008A8304 /* CollectionReusableView.swift in Sources */, + D0CED7812ABEB18D0081ABE2 /* SecondViewController.swift in Sources */, + D06DA8E82AC2BB0D00314499 /* Entity+CoreDataClass.swift in Sources */, + D06DA8EB2AC3B87200314499 /* CoreDataManager.swift in Sources */, C7431F0825F51E1D0094C4CF /* SceneDelegate.swift in Sources */, + D0293F5A2ACBAA2B00505749 /* Status.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -287,7 +387,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - INFOPLIST_FILE = ProjectManager/Info.plist; + INFOPLIST_FILE = ProjectManager/Resources/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -306,7 +406,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - INFOPLIST_FILE = ProjectManager/Info.plist; + INFOPLIST_FILE = ProjectManager/Resources/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -341,6 +441,19 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + D06DA8E32AC2BA9F00314499 /* Todo.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + D06DA8E42AC2BA9F00314499 /* Todo.xcdatamodel */, + ); + currentVersion = D06DA8E42AC2BA9F00314499 /* Todo.xcdatamodel */; + path = Todo.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = C7431EFA25F51E1D0094C4CF /* Project object */; } diff --git a/ProjectManager/ProjectManager/AppDelegate.swift b/ProjectManager/ProjectManager/AppDelegate.swift deleted file mode 100644 index 8df091a06..000000000 --- a/ProjectManager/ProjectManager/AppDelegate.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// ProjectManager - AppDelegate.swift -// Created by yagom. -// Copyright © yagom. All rights reserved. -// - -import UIKit - -@main -class AppDelegate: UIResponder, UIApplicationDelegate { - - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. - return true - } - - // MARK: UISceneSession Lifecycle - - func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { - // Called when a new scene session is being created. - // Use this method to select a configuration to create the new scene with. - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) - } - - func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { - // Called when the user discards a scene session. - // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. - // Use this method to release any resources that were specific to the discarded scenes, as they will not return. - } - - -} - diff --git a/ProjectManager/ProjectManager/Application/AppDelegate.swift b/ProjectManager/ProjectManager/Application/AppDelegate.swift new file mode 100644 index 000000000..8a2e99e8b --- /dev/null +++ b/ProjectManager/ProjectManager/Application/AppDelegate.swift @@ -0,0 +1,79 @@ +// +// ProjectManager - AppDelegate.swift +// Created by Jusbug. +// Copyright © yagom. All rights reserved. +// + +import UIKit +import CoreData + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + lazy var persistentContainer: NSPersistentContainer = { + /* + The persistent container for the application. This implementation + creates and returns a container, having loaded the store for the + application to it. This property is optional since there are legitimate + error conditions that could cause the creation of the store to fail. + */ + let container = NSPersistentContainer(name: "Todo") + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + + /* + Typical reasons for an error here include: + * The parent directory does not exist, cannot be created, or disallows writing. + * The persistent store is not accessible, due to permissions or data protection when the device is locked. + * The device is out of space. + * The store could not be migrated to the current model version. + Check the error message to determine what the actual problem was. + */ + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + return container + }() + + // MARK: - Core Data Saving support + + func saveContext () { + let context = persistentContainer.viewContext + if context.hasChanges { + do { + try context.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + let nserror = error as NSError + fatalError("Unresolved error \(nserror), \(nserror.userInfo)") + } + } + } + + +} + diff --git a/ProjectManager/ProjectManager/SceneDelegate.swift b/ProjectManager/ProjectManager/Application/SceneDelegate.swift similarity index 94% rename from ProjectManager/ProjectManager/SceneDelegate.swift rename to ProjectManager/ProjectManager/Application/SceneDelegate.swift index 94f16adcd..263f65686 100644 --- a/ProjectManager/ProjectManager/SceneDelegate.swift +++ b/ProjectManager/ProjectManager/Application/SceneDelegate.swift @@ -1,6 +1,6 @@ // // ProjectManager - SceneDelegate.swift -// Created by yagom. +// Created by Jusbug. // Copyright © yagom. All rights reserved. // @@ -16,6 +16,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let _ = (scene as? UIWindowScene) else { return } + + if #available(iOS 13.0, *) { + window?.overrideUserInterfaceStyle = .light + } } func sceneDidDisconnect(_ scene: UIScene) { diff --git a/ProjectManager/ProjectManager/Base.lproj/Main.storyboard b/ProjectManager/ProjectManager/Base.lproj/Main.storyboard deleted file mode 100644 index 25a763858..000000000 --- a/ProjectManager/ProjectManager/Base.lproj/Main.storyboard +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProjectManager/ProjectManager/Controllers/MainViewController.swift b/ProjectManager/ProjectManager/Controllers/MainViewController.swift new file mode 100644 index 000000000..038ab96a8 --- /dev/null +++ b/ProjectManager/ProjectManager/Controllers/MainViewController.swift @@ -0,0 +1,257 @@ +// +// ProjectManager - ViewController.swift +// Created by Jusbug. +// Copyright © yagom. All rights reserved. +// + +import UIKit + +class MainViewController: UIViewController { + + @IBOutlet weak var todoCollectionView: UICollectionView! + @IBOutlet weak var doingCollectionView: UICollectionView! + @IBOutlet weak var doneCollectionView: UICollectionView! + let coreDataManager = CoreDataManager.shared + var todoItem: [Entity] = [] + var doingItem: [Entity] = [] + var doneItem: [Entity] = [] + + override func viewDidLoad() { + super.viewDidLoad() + configureTitle() + initDelegateAndDataSource() + registerNib() + updateTodoColletionView() + notificationForUpdate() + filterItemsByStatus() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + updateTodoColletionView() + filterItemsByStatus() + } + + private func notificationForUpdate() { + NotificationCenter.default.addObserver(self, selector: #selector(didReceiveNotification), name: NSNotification.Name("createdTodo"), object: nil) + } + + private func registerNib() { + todoCollectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell") + doingCollectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell") + doneCollectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell") + todoCollectionView.register(UINib(nibName: "CollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") + doingCollectionView.register(UINib(nibName: "CollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") + doneCollectionView.register(UINib(nibName: "CollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") + } + + private func initDelegateAndDataSource() { + todoCollectionView.dataSource = self + todoCollectionView.delegate = self + doingCollectionView.dataSource = self + doingCollectionView.delegate = self + doneCollectionView.dataSource = self + doneCollectionView.delegate = self + } + + @objc func didReceiveNotification() { + updateTodoColletionView() + coreDataManager.getAllEntity() + } + + private func updateTodoColletionView() { + coreDataManager.getAllEntity() + DispatchQueue.main.async { + self.todoCollectionView.reloadData() + self.doingCollectionView.reloadData() + self.doneCollectionView.reloadData() + } + } + + private func filterItemsByStatus() { + todoItem = coreDataManager.entities.filter { $0.status == Status.todo.rawValue } + doingItem = coreDataManager.entities.filter { $0.status == Status.doing.rawValue } + doneItem = coreDataManager.entities.filter { $0.status == Status.done.rawValue } + } + + private func configureTitle() { + self.navigationItem.title = "Project Manager" + } + + @IBAction func didTapAddButton(_ sender: Any) { + guard let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "secondViewController") else { return } + + secondVC.modalTransitionStyle = .coverVertical + secondVC.modalPresentationStyle = .popover + + if let popover = secondVC.popoverPresentationController { + popover.sourceView = self.view + popover.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) + popover.permittedArrowDirections = [] + } + + self.present(secondVC, animated: true, completion: nil) + } + + private func alertActionForMove(sheet: UIAlertController, indexPath: IndexPath, to: Status, from: [Entity]) { + let action = UIAlertAction(title: "Move to \(to.rawValue)", style: .default) { [weak self] action in + guard let self = self else { return } + let entity = from[indexPath.row] + guard let title = entity.title, let body = entity.body, let duration = entity.duration else { + return + } + + self.coreDataManager.createEntity(title: title, body: body, duration: duration, status: to) + self.coreDataManager.deleteEntity(entity: entity) + self.updateTodoColletionView() + } + + sheet.addAction(action) + } + + private func alertActionForDelete(sheet: UIAlertController, indexPath: IndexPath, from: [Entity]) { + let delete = UIAlertAction(title: "Delete", style: .destructive) { [weak self] action in + guard let self = self else { return } + let entity = from[indexPath.row] + + self.coreDataManager.deleteEntity(entity: entity) + self.updateTodoColletionView() + } + + sheet.addAction(delete) + } + + @objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if gestureRecognizer.state == .began { + let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) + let collectionView: UICollectionView + let indexPath: IndexPath + + if let indexPathTodo = todoCollectionView.indexPathForItem(at: gestureRecognizer.location(in: todoCollectionView)) { + collectionView = todoCollectionView + indexPath = indexPathTodo + + alertActionForMove(sheet: actionSheet, indexPath: indexPathTodo, to: Status.doing, from: todoItem) + alertActionForMove(sheet: actionSheet, indexPath: indexPathTodo, to: Status.done, from: todoItem) + alertActionForDelete(sheet: actionSheet, indexPath: indexPathTodo, from: todoItem) + } else if let indexPathDoing = doingCollectionView.indexPathForItem(at: gestureRecognizer.location(in: doingCollectionView)) { + collectionView = doingCollectionView + indexPath = indexPathDoing + + alertActionForMove(sheet: actionSheet, indexPath: indexPathDoing, to: Status.todo, from: doingItem) + alertActionForMove(sheet: actionSheet, indexPath: indexPathDoing, to: Status.done, from: doingItem) + alertActionForDelete(sheet: actionSheet, indexPath: indexPathDoing, from: doingItem) + } else if let indexPathDone = doneCollectionView.indexPathForItem(at: gestureRecognizer.location(in: doneCollectionView)) { + collectionView = doneCollectionView + indexPath = indexPathDone + + alertActionForMove(sheet: actionSheet, indexPath: indexPathDone, to: Status.todo, from: doneItem) + alertActionForMove(sheet: actionSheet, indexPath: indexPathDone, to: Status.doing, from: doneItem) + alertActionForDelete(sheet: actionSheet, indexPath: indexPathDone, from: doneItem) + } else { + return + } + + if let cell = collectionView.cellForItem(at: indexPath) { + actionSheet.popoverPresentationController?.sourceView = cell + actionSheet.popoverPresentationController?.sourceRect = CGRect( + x: cell.bounds.midX, + y: cell.bounds.midY, + width: 0, + height: 0 + ) + actionSheet.popoverPresentationController?.permittedArrowDirections = indexPath.row == collectionView.numberOfItems(inSection: indexPath.section) - 1 ? .down : .up + } + + present(actionSheet, animated: true, completion: nil) + } + } +} + +extension MainViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + switch collectionView { + case todoCollectionView: + return todoItem.count + case doingCollectionView: + return doingItem.count + case doneCollectionView: + return doneItem.count + default: + return 0 + } + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? CollectionViewCell else { return UICollectionViewCell() } + + var entity: Entity? + + switch collectionView { + case todoCollectionView: + entity = todoItem[indexPath.row] + case doingCollectionView: + entity = doingItem[indexPath.row] + case doneCollectionView: + entity = doneItem[indexPath.row] + default: + break + } + + guard let entity = entity else { return UICollectionViewCell() } + + cell.configureLabels(entity: entity) + + if collectionView != doneCollectionView { + cell.configureDurationTextColor(entity: entity) + } + + let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:))) + cell.addGestureRecognizer(longPressRecognizer) + + return cell + } +} + +extension MainViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + } +} + +extension MainViewController: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: collectionView.bounds.width - 10, height: 100) + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { + + return 10 + } + + func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { + + if kind == UICollectionView.elementKindSectionHeader { + guard let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as? CollectionReusableView else { return UICollectionReusableView()} + + switch collectionView { + case todoCollectionView: + headerView.configureTitle(title: "TODO", entity: todoItem) + case doingCollectionView: + headerView.configureTitle(title: "DOING", entity: doingItem) + case doneCollectionView: + headerView.configureTitle(title: "DONE", entity: doneItem) + default: + break + } + + return headerView + } else { + return UICollectionReusableView() + } + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { + return CGSize(width: collectionView.frame.width - 10, height: 80) + } +} diff --git a/ProjectManager/ProjectManager/Controllers/SecondViewController.swift b/ProjectManager/ProjectManager/Controllers/SecondViewController.swift new file mode 100644 index 000000000..0682ed2e5 --- /dev/null +++ b/ProjectManager/ProjectManager/Controllers/SecondViewController.swift @@ -0,0 +1,111 @@ +// +// SecondViewController.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/23. +// + +import UIKit + +class SecondViewController: UIViewController { + + @IBOutlet weak var titleTextField: UITextField! + @IBOutlet weak var datePicker: UIDatePicker! + @IBOutlet weak var bodyTextView: UITextView! + private let placeHolderForTextField = "Title" + private let placeHolderForTextView = "This is where you type in what to do.\n1000 characters in the limit." + let coreDataManager = CoreDataManager.shared + private let entity: Entity? = nil + + override func viewDidLoad() { + configureTitle() + initPlaceHolderForText() + configureLayout() + } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + + guard let title = titleTextField.text, !title.isEmpty, title != placeHolderForTextField else { + return + } + + guard let body = bodyTextView.text, !body.isEmpty, body != placeHolderForTextView else { + return + } + + let date = datePicker.date + coreDataManager.createEntity(title: title, body: body, duration: date, status: Status.todo) + } + + override func touchesBegan(_ touches: Set, with event: UIEvent?){ + self.view.endEditing(true) + } + + private func configureTitle() { + self.navigationItem.title = "TODO" + } + + private func initPlaceHolderForText() { + titleTextField.delegate = self + titleTextField.text = placeHolderForTextField + titleTextField.textColor = .gray + bodyTextView.delegate = self + bodyTextView.text = placeHolderForTextView + bodyTextView.textColor = .gray + } + + private func configureLayout() { + titleTextField.layer.shadowColor = UIColor.gray.cgColor + titleTextField.layer.shadowOpacity = 1 + titleTextField.layer.shadowOffset = CGSize(width: 0, height: 5) + titleTextField.layer.shadowRadius = 5 + titleTextField.layer.masksToBounds = false + bodyTextView.layer.shadowColor = UIColor.gray.cgColor + bodyTextView.layer.shadowOpacity = 1 + bodyTextView.layer.shadowOffset = CGSize(width: 0, height: 5) + bodyTextView.layer.shadowRadius = 5 + bodyTextView.layer.masksToBounds = false + } + + @IBAction func didTapEditButton(_ sender: Any) { + + } + + @IBAction func didTapDoneButton(_ sender: Any) { + NotificationCenter.default.post(name: NSNotification.Name("createdTodo"), object: nil) + self.dismiss(animated: true, completion: nil) + } +} + +extension SecondViewController: UITextFieldDelegate { + func textFieldDidBeginEditing(_ textField: UITextField) { + if titleTextField.text == placeHolderForTextField { + titleTextField.text = nil + titleTextField.textColor = .black + } + } + + func textFieldDidEndEditing(_ textField: UITextField) { + if let title = titleTextField.text, title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + titleTextField.text = placeHolderForTextField + titleTextField.textColor = .gray + } + } +} + +extension SecondViewController: UITextViewDelegate { + func textViewDidBeginEditing(_ textView: UITextView) { + if bodyTextView.text == placeHolderForTextView { + bodyTextView.text = nil + bodyTextView.textColor = .black + } + } + + func textViewDidEndEditing(_ textView: UITextView) { + if bodyTextView.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + bodyTextView.text = placeHolderForTextView + bodyTextView.textColor = .gray + } + } +} diff --git a/ProjectManager/ProjectManager/Enum/Status.swift b/ProjectManager/ProjectManager/Enum/Status.swift new file mode 100644 index 000000000..09e63a86c --- /dev/null +++ b/ProjectManager/ProjectManager/Enum/Status.swift @@ -0,0 +1,12 @@ +// +// Status.swift +// ProjectManager +// +// Created by Jusbug on 2023/10/03. +// + +enum Status: String { + case todo = "Todo" + case doing = "Doing" + case done = "Done" +} diff --git a/ProjectManager/ProjectManager/Assets.xcassets/AccentColor.colorset/Contents.json b/ProjectManager/ProjectManager/Resources/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from ProjectManager/ProjectManager/Assets.xcassets/AccentColor.colorset/Contents.json rename to ProjectManager/ProjectManager/Resources/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/ProjectManager/ProjectManager/Assets.xcassets/AppIcon.appiconset/Contents.json b/ProjectManager/ProjectManager/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from ProjectManager/ProjectManager/Assets.xcassets/AppIcon.appiconset/Contents.json rename to ProjectManager/ProjectManager/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/ProjectManager/ProjectManager/Assets.xcassets/Contents.json b/ProjectManager/ProjectManager/Resources/Assets.xcassets/Contents.json similarity index 100% rename from ProjectManager/ProjectManager/Assets.xcassets/Contents.json rename to ProjectManager/ProjectManager/Resources/Assets.xcassets/Contents.json diff --git a/ProjectManager/ProjectManager/Info.plist b/ProjectManager/ProjectManager/Resources/Info.plist similarity index 100% rename from ProjectManager/ProjectManager/Info.plist rename to ProjectManager/ProjectManager/Resources/Info.plist diff --git a/ProjectManager/ProjectManager/Resources/Todo.xcdatamodeld/Todo.xcdatamodel/contents b/ProjectManager/ProjectManager/Resources/Todo.xcdatamodeld/Todo.xcdatamodel/contents new file mode 100644 index 000000000..0fb96f9f1 --- /dev/null +++ b/ProjectManager/ProjectManager/Resources/Todo.xcdatamodeld/Todo.xcdatamodel/contents @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ProjectManager/ProjectManager/ViewController.swift b/ProjectManager/ProjectManager/ViewController.swift deleted file mode 100644 index 3f450cec2..000000000 --- a/ProjectManager/ProjectManager/ViewController.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// ProjectManager - ViewController.swift -// Created by yagom. -// Copyright © yagom. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} - diff --git a/ProjectManager/ProjectManager/ViewModels/CollectionReusableView.swift b/ProjectManager/ProjectManager/ViewModels/CollectionReusableView.swift new file mode 100644 index 000000000..68f91914d --- /dev/null +++ b/ProjectManager/ProjectManager/ViewModels/CollectionReusableView.swift @@ -0,0 +1,23 @@ +// +// CollectionReusableView.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/26. +// + +import UIKit + +class CollectionReusableView: UICollectionReusableView { + + @IBOutlet weak var headerLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + } + + func configureTitle(title: String, entity: [Entity]) { + let count = String(entity.count) + + headerLabel.text = "\(title) \(count)" + } +} diff --git a/ProjectManager/ProjectManager/ViewModels/CollectionViewCell.swift b/ProjectManager/ProjectManager/ViewModels/CollectionViewCell.swift new file mode 100644 index 000000000..40e794cb3 --- /dev/null +++ b/ProjectManager/ProjectManager/ViewModels/CollectionViewCell.swift @@ -0,0 +1,40 @@ +// +// CollectionViewCell.swift +// ProjectManager +// +// Created by Jusbug on 2023/09/23. +// + +import UIKit + +class CollectionViewCell: UICollectionViewCell { + + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var bodyLabel: UILabel! + @IBOutlet weak var durationLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + + } + + func configureLabels(entity: Entity) { + guard let date = entity.duration else { return } + let formattedDate = DateFormatManager.formatDate(date: date) + + titleLabel.text = entity.title + bodyLabel.text = entity.body + durationLabel.text = formattedDate + } + + func configureDurationTextColor(entity: Entity) { + guard let date = entity.duration else { return } + let currentDate = Date() + + if date < currentDate { + durationLabel.textColor = .red + } else { + durationLabel.textColor = .black + } + } +} diff --git a/ProjectManager/ProjectManager/ViewModels/DateFormatManager.swift b/ProjectManager/ProjectManager/ViewModels/DateFormatManager.swift new file mode 100644 index 000000000..6f539798e --- /dev/null +++ b/ProjectManager/ProjectManager/ViewModels/DateFormatManager.swift @@ -0,0 +1,24 @@ +// +// DateFormatter.swift +// ProjectManager +// +// Created by Jusbug on 2023/10/02. +// + +import Foundation + +struct DateFormatManager { + static let customDateFormatter: DateFormatter = { + let dateFormatter = DateFormatter() + dateFormatter.locale = Locale(identifier: "koKR") + dateFormatter.dateFormat = "YYYY. MM. dd." + + return dateFormatter + }() + + static func formatDate(date: Date) -> String { + let formattedDate = customDateFormatter.string(from: date) + + return formattedDate + } +} diff --git a/ProjectManager/ProjectManager/Base.lproj/LaunchScreen.storyboard b/ProjectManager/ProjectManager/Views/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from ProjectManager/ProjectManager/Base.lproj/LaunchScreen.storyboard rename to ProjectManager/ProjectManager/Views/Base.lproj/LaunchScreen.storyboard diff --git a/ProjectManager/ProjectManager/Views/Base.lproj/Main.storyboard b/ProjectManager/ProjectManager/Views/Base.lproj/Main.storyboard new file mode 100644 index 000000000..fec91a151 --- /dev/null +++ b/ProjectManager/ProjectManager/Views/Base.lproj/Main.storyboard @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProjectManager/ProjectManager/Views/CollectionReusableView.xib b/ProjectManager/ProjectManager/Views/CollectionReusableView.xib new file mode 100644 index 000000000..8974d2ace --- /dev/null +++ b/ProjectManager/ProjectManager/Views/CollectionReusableView.xib @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProjectManager/ProjectManager/Views/CollectionViewCell.xib b/ProjectManager/ProjectManager/Views/CollectionViewCell.xib new file mode 100644 index 000000000..ea5c762d0 --- /dev/null +++ b/ProjectManager/ProjectManager/Views/CollectionViewCell.xib @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +