diff --git a/Flash Chat iOS13.xcodeproj/project.pbxproj b/Flash Chat iOS13.xcodeproj/project.pbxproj index 57604ade7..521f41173 100644 --- a/Flash Chat iOS13.xcodeproj/project.pbxproj +++ b/Flash Chat iOS13.xcodeproj/project.pbxproj @@ -3,10 +3,15 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ + 0463FC11285DEC6A00BFB8DA /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 0463FC10285DEC6A00BFB8DA /* GoogleService-Info.plist */; }; + 0463FC13285FC93700BFB8DA /* Constans.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0463FC12285FC93700BFB8DA /* Constans.swift */; }; + 0463FC15286082A000BFB8DA /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0463FC14286082A000BFB8DA /* Message.swift */; }; + 0463FC182863258000BFB8DA /* MessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0463FC162863258000BFB8DA /* MessageCell.swift */; }; + 0463FC192863258000BFB8DA /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0463FC172863258000BFB8DA /* MessageCell.xib */; }; 0B628177235DEE8100E35CAF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B628176235DEE8100E35CAF /* AppDelegate.swift */; }; 0B628179235DEE8100E35CAF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B628178235DEE8100E35CAF /* SceneDelegate.swift */; }; 0B62817E235DEE8100E35CAF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0B62817C235DEE8100E35CAF /* Main.storyboard */; }; @@ -17,9 +22,15 @@ 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 */; }; + D8C5B3403A36A84B76464DAD /* Pods_Flash_Chat_iOS13.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 114C4759A12D177B80CF2088 /* Pods_Flash_Chat_iOS13.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0463FC10285DEC6A00BFB8DA /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 0463FC12285FC93700BFB8DA /* Constans.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constans.swift; sourceTree = ""; }; + 0463FC14286082A000BFB8DA /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Message.swift; path = "Flash Chat iOS13/Message.swift"; sourceTree = SOURCE_ROOT; }; + 0463FC162863258000BFB8DA /* MessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCell.swift; sourceTree = ""; }; + 0463FC172863258000BFB8DA /* MessageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCell.xib; sourceTree = ""; }; 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 +43,9 @@ 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 = ""; }; + 114C4759A12D177B80CF2088 /* Pods_Flash_Chat_iOS13.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Flash_Chat_iOS13.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 41D365E32DD792F011ED41A7 /* 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 = ""; }; + 66994428E1BB42C78EA77343 /* 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -39,6 +53,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D8C5B3403A36A84B76464DAD /* Pods_Flash_Chat_iOS13.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -51,6 +66,8 @@ 0B62819D235F0F4D00E35CAF /* README.md */, 0B628175235DEE8100E35CAF /* Flash Chat iOS13 */, 0B628174235DEE8100E35CAF /* Products */, + 4B2E516EB0C15FE324306018 /* Pods */, + B202153191C46618D83BBA37 /* Frameworks */, ); sourceTree = ""; }; @@ -72,7 +89,9 @@ 0B628192235DF02000E35CAF /* Controllers */, 0B62817F235DEE8400E35CAF /* Assets.xcassets */, 0B628181235DEE8400E35CAF /* LaunchScreen.storyboard */, + 0463FC10285DEC6A00BFB8DA /* GoogleService-Info.plist */, 0B628184235DEE8400E35CAF /* Info.plist */, + 0463FC12285FC93700BFB8DA /* Constans.swift */, ); path = "Flash Chat iOS13"; sourceTree = ""; @@ -92,6 +111,8 @@ isa = PBXGroup; children = ( 0B62817C235DEE8100E35CAF /* Main.storyboard */, + 0463FC162863258000BFB8DA /* MessageCell.swift */, + 0463FC172863258000BFB8DA /* MessageCell.xib */, ); path = Views; sourceTree = ""; @@ -99,10 +120,28 @@ 0B628194235DF03A00E35CAF /* Models */ = { isa = PBXGroup; children = ( + 0463FC14286082A000BFB8DA /* Message.swift */, ); path = Models; sourceTree = ""; }; + 4B2E516EB0C15FE324306018 /* Pods */ = { + isa = PBXGroup; + children = ( + 66994428E1BB42C78EA77343 /* Pods-Flash Chat iOS13.debug.xcconfig */, + 41D365E32DD792F011ED41A7 /* Pods-Flash Chat iOS13.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + B202153191C46618D83BBA37 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 114C4759A12D177B80CF2088 /* Pods_Flash_Chat_iOS13.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -110,9 +149,11 @@ isa = PBXNativeTarget; buildConfigurationList = 0B628187235DEE8400E35CAF /* Build configuration list for PBXNativeTarget "Flash Chat iOS13" */; buildPhases = ( + BAAF841C167AFA25DDBAA684 /* [CP] Check Pods Manifest.lock */, 0B62816F235DEE8100E35CAF /* Sources */, 0B628170235DEE8100E35CAF /* Frameworks */, 0B628171235DEE8100E35CAF /* Resources */, + 73D86851AF88CFECD823892E /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -130,7 +171,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1110; - LastUpgradeCheck = 1110; + LastUpgradeCheck = 1330; ORGANIZATIONNAME = "Angela Yu"; TargetAttributes = { 0B628172235DEE8100E35CAF = { @@ -147,6 +188,8 @@ Base, ); mainGroup = 0B62816A235DEE8100E35CAF; + packageReferences = ( + ); productRefGroup = 0B628174235DEE8100E35CAF /* Products */; projectDirPath = ""; projectRoot = ""; @@ -162,7 +205,9 @@ buildActionMask = 2147483647; files = ( 0B628183235DEE8400E35CAF /* LaunchScreen.storyboard in Resources */, + 0463FC192863258000BFB8DA /* MessageCell.xib in Resources */, 0B628180235DEE8400E35CAF /* Assets.xcassets in Resources */, + 0463FC11285DEC6A00BFB8DA /* GoogleService-Info.plist in Resources */, 0B62819E235F0F4D00E35CAF /* README.md in Resources */, 0B62817E235DEE8100E35CAF /* Main.storyboard in Resources */, ); @@ -170,6 +215,48 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 73D86851AF88CFECD823892E /* [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; + }; + BAAF841C167AFA25DDBAA684 /* [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; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 0B62816F235DEE8100E35CAF /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -180,7 +267,10 @@ 0B628179235DEE8100E35CAF /* SceneDelegate.swift in Sources */, 0B62818F235DF01000E35CAF /* LoginViewController.swift in Sources */, 0B628191235DF01B00E35CAF /* ChatViewController.swift in Sources */, + 0463FC15286082A000BFB8DA /* Message.swift in Sources */, + 0463FC13285FC93700BFB8DA /* Constans.swift in Sources */, 0B62818D235DF00B00E35CAF /* RegisterViewController.swift in Sources */, + 0463FC182863258000BFB8DA /* MessageCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -232,6 +322,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 +383,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 +414,17 @@ }; 0B628188235DEE8400E35CAF /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 66994428E1BB42C78EA77343 /* Pods-Flash Chat iOS13.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 3ECFYJZ64T; + DEVELOPMENT_TEAM = 8U25RXJ494; 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.maonz.Flash-Chat-iOS13"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; @@ -340,16 +433,17 @@ }; 0B628189235DEE8400E35CAF /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 41D365E32DD792F011ED41A7 /* Pods-Flash Chat iOS13.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 3ECFYJZ64T; + DEVELOPMENT_TEAM = 8U25RXJ494; 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.maonz.Flash-Chat-iOS13"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; diff --git a/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate b/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..7676417a0 Binary files /dev/null and b/Flash Chat iOS13.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Flash Chat iOS13.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist b/Flash Chat iOS13.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..ca84307a4 --- /dev/null +++ b/Flash Chat iOS13.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Flash Chat iOS13.xcscheme_^#shared#^_ + + orderHint + 20 + + + + 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/mac.xcuserdatad/UserInterfaceState.xcuserstate b/Flash Chat iOS13.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..b5b4dba5a Binary files /dev/null and b/Flash Chat iOS13.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Flash Chat iOS13/AppDelegate.swift b/Flash Chat iOS13/AppDelegate.swift index 620250213..3039e32ef 100644 --- a/Flash Chat iOS13/AppDelegate.swift +++ b/Flash Chat iOS13/AppDelegate.swift @@ -7,14 +7,27 @@ // import UIKit +import FirebaseCore +import FirebaseAuth +import FirebaseFirestore +import IQKeyboardManagerSwift @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - + var window: UIWindow? + 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/Constans.swift b/Flash Chat iOS13/Constans.swift new file mode 100644 index 000000000..6f3d13451 --- /dev/null +++ b/Flash Chat iOS13/Constans.swift @@ -0,0 +1,29 @@ +// +// Constans.swift +// Flash Chat iOS13 +// +// Created by Mac on 20.06.2022. +// Copyright © 2022 Angela Yu. All rights reserved. +// + +struct K { + static let appName = "⚡️FlashChat" + static let cellIdentifier = "ReusableCell" + static let cellNibName = "MessageCell" + static let registerSegue = "RegisterToChat" + static let loginSegue = "LoginToChat" + + 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/Controllers/ChatViewController.swift b/Flash Chat iOS13/Controllers/ChatViewController.swift index eb06ca23e..1c10044cd 100644 --- a/Flash Chat iOS13/Controllers/ChatViewController.swift +++ b/Flash Chat iOS13/Controllers/ChatViewController.swift @@ -7,19 +7,112 @@ // import UIKit +import FirebaseCore +import FirebaseAuth +import FirebaseFirestore -class ChatViewController: UIViewController { +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() - + tableView.dataSource = self + title = "⚡️FlashChat" + navigationItem.hidesBackButton = true + 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, err in + if let err = err{ + print("smth wrong \(err)") + }else { + + self.messages = [] + //or//self.tableView.clearsContextBeforeDrawing + if let snapshotDocumets = querySnapshot?.documents { + for doc in snapshotDocumets{ + let data = doc.data() + if let messageSender = data[K.FStore.senderField] as? String, let messageBody = data[K.FStore.bodyField] as? String { + let newMessage = Message(sender: messageSender, body: messageBody) + self.messages.append(newMessage) + + DispatchQueue.main.async { + self.tableView.reloadData() + let indexPath = IndexPath(row: self.messages.count - 1,section: 0) + self.tableView.scrollToRow(at: indexPath, at: .top, animated: true) + } + } + } + } + } + } } - @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]) { err in + if let err = err { + print("trouble in data sender \(err)") + }else{ + self.messageTextfield.text = "" + + DispatchQueue.main.async { + self.loadMessages() + } + } + } + } + } + @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 message = messages[indexPath.row] + let cell = tableView.dequeueReusableCell(withIdentifier: K.cellIdentifier, for: indexPath) + as! MessageCell + cell.label.text = message.body + + if message.sender == Auth.auth().currentUser?.email { + cell.leftImageView.isHidden = true + cell.avatarImageView.isHidden = false + + }else { + cell.leftImageView.isHidden = false + cell.avatarImageView.isHidden = true + } + + return cell + } + + + } diff --git a/Flash Chat iOS13/Controllers/LoginViewController.swift b/Flash Chat iOS13/Controllers/LoginViewController.swift index d4efc0598..14febfd5e 100644 --- a/Flash Chat iOS13/Controllers/LoginViewController.swift +++ b/Flash Chat iOS13/Controllers/LoginViewController.swift @@ -7,14 +7,31 @@ // import UIKit +import FirebaseAuth +import FirebaseCore class LoginViewController: UIViewController { - + + @IBAction func accountSwith(_ sender: UISegmentedControl) { + emailTextfield.text = "2@23g.com" + passwordTextfield.text = "werwer123" + print(sender) + } + @IBOutlet weak var emailTextfield: UITextField! @IBOutlet weak var passwordTextfield: UITextField! - + @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) + } else { + self.performSegue(withIdentifier: K.loginSegue, sender: self) + } + + } + } } - } diff --git a/Flash Chat iOS13/Controllers/RegisterViewController.swift b/Flash Chat iOS13/Controllers/RegisterViewController.swift index b3e7f126f..8e93fe4e9 100644 --- a/Flash Chat iOS13/Controllers/RegisterViewController.swift +++ b/Flash Chat iOS13/Controllers/RegisterViewController.swift @@ -7,13 +7,27 @@ // import UIKit +import FirebaseCore +import FirebaseAuth class RegisterViewController: UIViewController { - + @IBOutlet weak var emailTextfield: UITextField! @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) + }else { + 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..0c3a87df8 100644 --- a/Flash Chat iOS13/Controllers/WelcomeViewController.swift +++ b/Flash Chat iOS13/Controllers/WelcomeViewController.swift @@ -7,16 +7,89 @@ // 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.appName } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +//MARK: - Reference: VDL text animation +// var colorNum = 0 +// var charIndex = 0.0 +// let titleText = "⚡️FlashChat" +// //MARK: - simulation of typing && random color of text +// let colorArray = [UIColor.red,UIColor.systemTeal,UIColor.blue,UIColor.purple,UIColor.systemPink,UIColor.gray,UIColor.cyan,UIColor.magenta,UIColor.systemIndigo,UIColor.orange] +// for char in titleText { +// Timer.scheduledTimer(withTimeInterval: 0.15 * charIndex, repeats: false) { (timer) in +// self.titleLabel.text?.append(char) +// self.titleLabel.textColor = colorArray.randomElement() +// //MARK: - lastColor +// colorNum += 1 +// if colorNum == 10{ +// self.titleLabel.textColor = UIColor(red: 157/255, green: 196/255, blue: 234/255, alpha: 1) //which color will be last +// }else{ +// print("...") +// } +// } +// charIndex += 1 +// } + diff --git a/Flash Chat iOS13/GoogleService-Info.plist b/Flash Chat iOS13/GoogleService-Info.plist new file mode 100644 index 000000000..3f781cc11 --- /dev/null +++ b/Flash Chat iOS13/GoogleService-Info.plist @@ -0,0 +1,34 @@ + + + + + CLIENT_ID + 378673531586-qr2h519k0an1bms8tgpqm3peshpsbnpb.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.378673531586-qr2h519k0an1bms8tgpqm3peshpsbnpb + API_KEY + AIzaSyAkFCNnGX5byhhCaX9RbErKD6KiJuDwTbA + GCM_SENDER_ID + 378673531586 + PLIST_VERSION + 1 + BUNDLE_ID + co.maonz.Flash-Chat-iOS13 + PROJECT_ID + flashchat-e6040 + STORAGE_BUCKET + flashchat-e6040.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:378673531586:ios:92cd930a9ddadf8e4f895b + + \ No newline at end of file diff --git a/Flash Chat iOS13/Message.swift b/Flash Chat iOS13/Message.swift new file mode 100644 index 000000000..b2b0069e7 --- /dev/null +++ b/Flash Chat iOS13/Message.swift @@ -0,0 +1,14 @@ +// +// Message.swift +// Flash Chat iOS13 +// +// Created by Mac on 20.06.2022. +// Copyright © 2022 Angela Yu. All rights reserved. +// + +import Foundation + +struct Message { + let sender: String + let body: String +} diff --git a/Flash Chat iOS13/Views/Base.lproj/Main.storyboard b/Flash Chat iOS13/Views/Base.lproj/Main.storyboard index 84d5aa1fa..368d079da 100644 --- a/Flash Chat iOS13/Views/Base.lproj/Main.storyboard +++ b/Flash Chat iOS13/Views/Base.lproj/Main.storyboard @@ -1,10 +1,12 @@ - + - + + + @@ -16,9 +18,9 @@ - - - + + @@ -62,15 +71,15 @@ - + - + @@ -81,7 +90,7 @@ - + @@ -106,9 +115,9 @@ - + -