diff --git a/Flash Chat iOS13.xcodeproj/project.pbxproj b/Flash Chat iOS13.xcodeproj/project.pbxproj index 57604ade7..da7f6f9c5 100644 --- a/Flash Chat iOS13.xcodeproj/project.pbxproj +++ b/Flash Chat iOS13.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -17,9 +17,17 @@ 0B62818F235DF01000E35CAF /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B62818E235DF01000E35CAF /* LoginViewController.swift */; }; 0B628191235DF01B00E35CAF /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B628190235DF01B00E35CAF /* ChatViewController.swift */; }; 0B62819E235F0F4D00E35CAF /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 0B62819D235F0F4D00E35CAF /* README.md */; }; + 8413B360B8BD844636930EB0 /* Pods_Flash_Chat_iOS13.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3742D9F6F4B392FE1A4B9A /* Pods_Flash_Chat_iOS13.framework */; }; + DA07ED5326DC55080085FC08 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DA07ED5226DC55080085FC08 /* GoogleService-Info.plist */; }; + DA8EFAD626DDB80800A2910F /* K.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8EFAD526DDB80800A2910F /* K.swift */; }; + DA8EFAD826DDBEF800A2910F /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8EFAD726DDBEF800A2910F /* Message.swift */; }; + DA92E0FB2719273B00502011 /* IQKeyboardManagerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = DA92E0FA2719273B00502011 /* IQKeyboardManagerSwift */; }; + DAE6215826FFA14400D9A9F8 /* MessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAE6215626FFA14400D9A9F8 /* MessageCell.swift */; }; + DAE6215926FFA14400D9A9F8 /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAE6215726FFA14400D9A9F8 /* MessageCell.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0A3742D9F6F4B392FE1A4B9A /* Pods_Flash_Chat_iOS13.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Flash_Chat_iOS13.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 0B628173235DEE8100E35CAF /* Flash Chat iOS13.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Flash Chat iOS13.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 0B628176235DEE8100E35CAF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 0B628178235DEE8100E35CAF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -32,6 +40,13 @@ 0B62818E235DF01000E35CAF /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = ""; }; 0B628190235DF01B00E35CAF /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = ""; }; 0B62819D235F0F4D00E35CAF /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + 9BF7163564BDD700C31DCB1C /* Pods-Flash Chat iOS13.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Flash Chat iOS13.release.xcconfig"; path = "Target Support Files/Pods-Flash Chat iOS13/Pods-Flash Chat iOS13.release.xcconfig"; sourceTree = ""; }; + ABC6055C3000691FA10B6411 /* Pods-Flash Chat iOS13.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Flash Chat iOS13.debug.xcconfig"; path = "Target Support Files/Pods-Flash Chat iOS13/Pods-Flash Chat iOS13.debug.xcconfig"; sourceTree = ""; }; + DA07ED5226DC55080085FC08 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../../Downloads/GoogleService-Info.plist"; sourceTree = ""; }; + DA8EFAD526DDB80800A2910F /* K.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = K.swift; sourceTree = ""; }; + DA8EFAD726DDBEF800A2910F /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Message.swift; path = "Flash Chat iOS13/Message.swift"; sourceTree = SOURCE_ROOT; }; + DAE6215626FFA14400D9A9F8 /* MessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCell.swift; sourceTree = ""; }; + DAE6215726FFA14400D9A9F8 /* MessageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCell.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -39,6 +54,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8413B360B8BD844636930EB0 /* Pods_Flash_Chat_iOS13.framework in Frameworks */, + DA92E0FB2719273B00502011 /* IQKeyboardManagerSwift in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -51,6 +68,8 @@ 0B62819D235F0F4D00E35CAF /* README.md */, 0B628175235DEE8100E35CAF /* Flash Chat iOS13 */, 0B628174235DEE8100E35CAF /* Products */, + 89391F39BFD979F861D3EE87 /* Pods */, + 8FB07E7ACB983490404595BE /* Frameworks */, ); sourceTree = ""; }; @@ -72,7 +91,9 @@ 0B628192235DF02000E35CAF /* Controllers */, 0B62817F235DEE8400E35CAF /* Assets.xcassets */, 0B628181235DEE8400E35CAF /* LaunchScreen.storyboard */, + DA07ED5226DC55080085FC08 /* GoogleService-Info.plist */, 0B628184235DEE8400E35CAF /* Info.plist */, + DA8EFAD526DDB80800A2910F /* K.swift */, ); path = "Flash Chat iOS13"; sourceTree = ""; @@ -92,6 +113,8 @@ isa = PBXGroup; children = ( 0B62817C235DEE8100E35CAF /* Main.storyboard */, + DAE6215626FFA14400D9A9F8 /* MessageCell.swift */, + DAE6215726FFA14400D9A9F8 /* MessageCell.xib */, ); path = Views; sourceTree = ""; @@ -99,10 +122,28 @@ 0B628194235DF03A00E35CAF /* Models */ = { isa = PBXGroup; children = ( + DA8EFAD726DDBEF800A2910F /* Message.swift */, ); path = Models; sourceTree = ""; }; + 89391F39BFD979F861D3EE87 /* Pods */ = { + isa = PBXGroup; + children = ( + ABC6055C3000691FA10B6411 /* Pods-Flash Chat iOS13.debug.xcconfig */, + 9BF7163564BDD700C31DCB1C /* Pods-Flash Chat iOS13.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + 8FB07E7ACB983490404595BE /* Frameworks */ = { + isa = PBXGroup; + children = ( + 0A3742D9F6F4B392FE1A4B9A /* Pods_Flash_Chat_iOS13.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -110,15 +151,20 @@ isa = PBXNativeTarget; buildConfigurationList = 0B628187235DEE8400E35CAF /* Build configuration list for PBXNativeTarget "Flash Chat iOS13" */; buildPhases = ( + 266047308F91DDE97715D0F7 /* [CP] Check Pods Manifest.lock */, 0B62816F235DEE8100E35CAF /* Sources */, 0B628170235DEE8100E35CAF /* Frameworks */, 0B628171235DEE8100E35CAF /* Resources */, + D40212EC75BAB73E7B058B0F /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); dependencies = ( ); name = "Flash Chat iOS13"; + packageProductDependencies = ( + DA92E0FA2719273B00502011 /* IQKeyboardManagerSwift */, + ); productName = "Flash Chat iOS13"; productReference = 0B628173235DEE8100E35CAF /* Flash Chat iOS13.app */; productType = "com.apple.product-type.application"; @@ -130,7 +176,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1110; - LastUpgradeCheck = 1110; + LastUpgradeCheck = 1250; ORGANIZATIONNAME = "Angela Yu"; TargetAttributes = { 0B628172235DEE8100E35CAF = { @@ -147,6 +193,9 @@ Base, ); mainGroup = 0B62816A235DEE8100E35CAF; + packageReferences = ( + DA92E0F92719273B00502011 /* XCRemoteSwiftPackageReference "IQKeyboardManager" */, + ); productRefGroup = 0B628174235DEE8100E35CAF /* Products */; projectDirPath = ""; projectRoot = ""; @@ -162,7 +211,9 @@ buildActionMask = 2147483647; files = ( 0B628183235DEE8400E35CAF /* LaunchScreen.storyboard in Resources */, + DAE6215926FFA14400D9A9F8 /* MessageCell.xib in Resources */, 0B628180235DEE8400E35CAF /* Assets.xcassets in Resources */, + DA07ED5326DC55080085FC08 /* GoogleService-Info.plist in Resources */, 0B62819E235F0F4D00E35CAF /* README.md in Resources */, 0B62817E235DEE8100E35CAF /* Main.storyboard in Resources */, ); @@ -170,6 +221,48 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 266047308F91DDE97715D0F7 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Flash Chat iOS13-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + D40212EC75BAB73E7B058B0F /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Flash Chat iOS13/Pods-Flash Chat iOS13-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Flash Chat iOS13/Pods-Flash Chat iOS13-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Flash Chat iOS13/Pods-Flash Chat iOS13-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 0B62816F235DEE8100E35CAF /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -179,8 +272,11 @@ 0B628177235DEE8100E35CAF /* AppDelegate.swift in Sources */, 0B628179235DEE8100E35CAF /* SceneDelegate.swift in Sources */, 0B62818F235DF01000E35CAF /* LoginViewController.swift in Sources */, + DA8EFAD626DDB80800A2910F /* K.swift in Sources */, + DA8EFAD826DDBEF800A2910F /* Message.swift in Sources */, 0B628191235DF01B00E35CAF /* ChatViewController.swift in Sources */, 0B62818D235DF00B00E35CAF /* RegisterViewController.swift in Sources */, + DAE6215826FFA14400D9A9F8 /* MessageCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -232,6 +328,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -292,6 +389,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -322,16 +420,17 @@ }; 0B628188235DEE8400E35CAF /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = ABC6055C3000691FA10B6411 /* Pods-Flash Chat iOS13.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 3ECFYJZ64T; + DEVELOPMENT_TEAM = D2P3K93K5L; INFOPLIST_FILE = "Flash Chat iOS13/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "co.appbrewery.Flash-Chat-iOS13"; + PRODUCT_BUNDLE_IDENTIFIER = "co.impomales.Flash-Chat-iOS13"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; @@ -340,16 +439,17 @@ }; 0B628189235DEE8400E35CAF /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 9BF7163564BDD700C31DCB1C /* Pods-Flash Chat iOS13.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 3ECFYJZ64T; + DEVELOPMENT_TEAM = D2P3K93K5L; INFOPLIST_FILE = "Flash Chat iOS13/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "co.appbrewery.Flash-Chat-iOS13"; + PRODUCT_BUNDLE_IDENTIFIER = "co.impomales.Flash-Chat-iOS13"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; @@ -378,6 +478,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + DA92E0F92719273B00502011 /* XCRemoteSwiftPackageReference "IQKeyboardManager" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/hackiftekhar/IQKeyboardManager"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 6.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + DA92E0FA2719273B00502011 /* IQKeyboardManagerSwift */ = { + isa = XCSwiftPackageProductDependency; + package = DA92E0F92719273B00502011 /* XCRemoteSwiftPackageReference "IQKeyboardManager" */; + productName = IQKeyboardManagerSwift; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 0B62816B235DEE8100E35CAF /* Project object */; } diff --git a/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate b/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..4bd51ec80 Binary files /dev/null and b/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Flash Chat iOS13.xcodeproj/xcuserdata/isaiaspomales.xcuserdatad/xcschemes/xcschememanagement.plist b/Flash Chat iOS13.xcodeproj/xcuserdata/isaiaspomales.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..96d10a0f9 --- /dev/null +++ b/Flash Chat iOS13.xcodeproj/xcuserdata/isaiaspomales.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Flash Chat iOS13.xcscheme_^#shared#^_ + + orderHint + 18 + + + + diff --git a/Flash Chat iOS13.xcworkspace/contents.xcworkspacedata b/Flash Chat iOS13.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..0bc3cc88e --- /dev/null +++ b/Flash Chat iOS13.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Flash Chat iOS13.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Flash Chat iOS13.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Flash Chat iOS13.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Flash Chat iOS13.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate b/Flash Chat iOS13.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..c653b8127 Binary files /dev/null and b/Flash Chat iOS13.xcworkspace/xcuserdata/isaiaspomales.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Flash Chat iOS13/AppDelegate.swift b/Flash Chat iOS13/AppDelegate.swift index 620250213..36ef861f2 100644 --- a/Flash Chat iOS13/AppDelegate.swift +++ b/Flash Chat iOS13/AppDelegate.swift @@ -7,6 +7,8 @@ // import UIKit +import Firebase +import IQKeyboardManagerSwift @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -15,6 +17,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. + FirebaseApp.configure() + + let db = Firestore.firestore(); + IQKeyboardManager.shared.enable = true + IQKeyboardManager.shared.enableAutoToolbar = false + IQKeyboardManager.shared.shouldResignOnTouchOutside = true + + print(db); + return true } diff --git a/Flash Chat iOS13/Controllers/ChatViewController.swift b/Flash Chat iOS13/Controllers/ChatViewController.swift index eb06ca23e..d51dd7f57 100644 --- a/Flash Chat iOS13/Controllers/ChatViewController.swift +++ b/Flash Chat iOS13/Controllers/ChatViewController.swift @@ -7,19 +7,95 @@ // import UIKit +import Firebase class ChatViewController: UIViewController { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var messageTextfield: UITextField! + let db = Firestore.firestore() + + var messages: [Message] = [] + override func viewDidLoad() { super.viewDidLoad() - + title = K.appTitle + navigationItem.hidesBackButton = true; + tableView.dataSource = self + + tableView.register(UINib(nibName: K.cellNibName, bundle: nil), forCellReuseIdentifier: K.cellIdentifier) + + loadMessages() + } + + func loadMessages() { + db + .collection(K.FStore.collectionName) + .order(by: K.FStore.dateField) + .addSnapshotListener { querySnapshot, error in + self.messages = []; + + if let e = error { + print("There was an issue retrieving data from Firestore. \(e)") + } else { + if let snapShotDocuments = querySnapshot?.documents { + for doc in snapShotDocuments { + let data = doc.data() + if let sender = data[K.FStore.senderField] as? String, + let messageBody = data[K.FStore.bodyField] as? String { + let newMessage = Message(sender: sender, body: messageBody) + self.messages.append(newMessage) + + DispatchQueue.main.async { + self.tableView.reloadData() + } + } + } + } + } + } } @IBAction func sendPressed(_ sender: UIButton) { + if let messageBody = messageTextfield.text, let messageSender = Auth.auth().currentUser?.email { + db.collection(K.FStore.collectionName).addDocument(data: [ + K.FStore.senderField: messageSender, + K.FStore.bodyField: messageBody, + K.FStore.dateField: Date().timeIntervalSince1970 + ]) { (error) in + if let e = error { + print("There was an issue saving data to firestore, \(e)") + } else { + print("Successfully saved data.") + } + + self.messageTextfield.text = "" + } + } } + @IBAction func logOutPressed(_ sender: UIBarButtonItem) { + do { + try Auth.auth().signOut() + navigationController?.popToRootViewController(animated: true); + } catch let signOutError as NSError { + print("Error signing out: %@", signOutError) + } + } +} + +extension ChatViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return messages.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: K.cellIdentifier, for: indexPath) as! MessageCell + + cell.label?.text = messages[indexPath.row].body + + return cell + } } diff --git a/Flash Chat iOS13/Controllers/LoginViewController.swift b/Flash Chat iOS13/Controllers/LoginViewController.swift index d4efc0598..7e6b074ae 100644 --- a/Flash Chat iOS13/Controllers/LoginViewController.swift +++ b/Flash Chat iOS13/Controllers/LoginViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Firebase class LoginViewController: UIViewController { @@ -15,6 +16,23 @@ class LoginViewController: UIViewController { @IBAction func loginPressed(_ sender: UIButton) { + if let email = emailTextfield.text, let password = passwordTextfield.text { + Auth.auth().signIn(withEmail: email, password: password) { authResult, error in + if let e = error { + print(e.localizedDescription); + } else { + // Navigate to Chat Screen on log in success. + self.performSegue(withIdentifier: K.loginSegue, sender: self) + } + } + } } } + + +/* + DEV LOGIN INFO. + email: i@email.com + pass: password + */ diff --git a/Flash Chat iOS13/Controllers/RegisterViewController.swift b/Flash Chat iOS13/Controllers/RegisterViewController.swift index b3e7f126f..1761055df 100644 --- a/Flash Chat iOS13/Controllers/RegisterViewController.swift +++ b/Flash Chat iOS13/Controllers/RegisterViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Firebase class RegisterViewController: UIViewController { @@ -14,6 +15,16 @@ class RegisterViewController: UIViewController { @IBOutlet weak var passwordTextfield: UITextField! @IBAction func registerPressed(_ sender: UIButton) { + if let email = emailTextfield.text, let password = passwordTextfield.text { + Auth.auth().createUser(withEmail: email, password: password) { authResult, error in + if let e = error { + print(e.localizedDescription) + } else { + // Navigate to the chat view controller. + self.performSegue(withIdentifier: K.registerSegue, sender: self) + } + } + } } } diff --git a/Flash Chat iOS13/Controllers/WelcomeViewController.swift b/Flash Chat iOS13/Controllers/WelcomeViewController.swift index 1f5ed9019..5e4af69d4 100644 --- a/Flash Chat iOS13/Controllers/WelcomeViewController.swift +++ b/Flash Chat iOS13/Controllers/WelcomeViewController.swift @@ -7,16 +7,15 @@ // import UIKit +import CLTypingLabel class WelcomeViewController: UIViewController { - @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var titleLabel: CLTypingLabel! override func viewDidLoad() { super.viewDidLoad() - - + + titleLabel.text = K.appTitle } - - } diff --git a/Flash Chat iOS13/K.swift b/Flash Chat iOS13/K.swift new file mode 100644 index 000000000..db274a67e --- /dev/null +++ b/Flash Chat iOS13/K.swift @@ -0,0 +1,29 @@ +// +// Constants.swift +// Flash Chat iOS13 +// +// Created by Isaias Pomales on 8/30/21. +// Copyright © 2021 Angela Yu. All rights reserved. +// + +struct K { + static let appTitle = "⚡️FlashChat" + static let registerSegue = "RegisterToChat" + static let loginSegue = "LoginToChat" + static let cellIdentifier = "ReusableCell" + static let cellNibName = "MessageCell" + + struct BrandColors { + static let purple = "BrandPurple" + static let lightPurple = "BrandLightPurple" + static let blue = "BrandBlue" + static let lighBlue = "BrandLightBlue" + } + + struct FStore { + static let collectionName = "messages" + static let senderField = "sender" + static let bodyField = "body" + static let dateField = "date" + } +} diff --git a/Flash Chat iOS13/Message.swift b/Flash Chat iOS13/Message.swift new file mode 100644 index 000000000..1e8d69daa --- /dev/null +++ b/Flash Chat iOS13/Message.swift @@ -0,0 +1,14 @@ +// +// Message.swift +// Flash Chat iOS13 +// +// Created by Isaias Pomales on 8/30/21. +// Copyright © 2021 Angela Yu. All rights reserved. +// + +import Foundation + +struct Message { + let sender: String // email of sender. + let body: String // message body. +} diff --git a/Flash Chat iOS13/Views/Base.lproj/Main.storyboard b/Flash Chat iOS13/Views/Base.lproj/Main.storyboard index 84d5aa1fa..f5d9a2c9c 100644 --- a/Flash Chat iOS13/Views/Base.lproj/Main.storyboard +++ b/Flash Chat iOS13/Views/Base.lproj/Main.storyboard @@ -1,10 +1,12 @@ - - + + - + + + @@ -13,12 +15,12 @@ - + - - - + + @@ -57,37 +66,38 @@ + - + - + - + - + - + - + @@ -106,10 +116,10 @@ - + - - + - + @@ -145,6 +155,7 @@ + @@ -154,33 +165,34 @@ - + + - + - + - + - + - + @@ -199,19 +211,19 @@ - + - + - + -