From f7aed7b8de683a8fc2d723cd455d6f15ab736c55 Mon Sep 17 00:00:00 2001 From: Aki Kuratani Date: Mon, 20 Jul 2020 18:43:08 +0900 Subject: [PATCH 01/12] =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=82=92=E3=82=BB?= =?UTF-8?q?=E3=83=BC=E3=83=96=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E3=81=A0=E3=81=91=E6=9B=B8=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/EditProfile/EditProfileModel.swift | 21 +++++++++++++++++++ .../EditProfile/EditProfilePresenter.swift | 6 +++--- .../EditProfileViewController.swift | 16 +++++--------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/chat-iOS/Views/EditProfile/EditProfileModel.swift b/chat-iOS/Views/EditProfile/EditProfileModel.swift index bde0ae2..e082d85 100644 --- a/chat-iOS/Views/EditProfile/EditProfileModel.swift +++ b/chat-iOS/Views/EditProfile/EditProfileModel.swift @@ -4,6 +4,7 @@ // // Created by 倉谷 明希 on 2020/07/03. // +import Firebase protocol EditProfileModelProtocol { var presenter: EditProfileModelOutput! { get set } @@ -18,6 +19,26 @@ final class EditProfileModel: EditProfileModelProtocol { var presenter: EditProfileModelOutput! func saveProfile() { + let storage = Storage.storage().reference(forURL: "gs://mapapp6-bf5a1.appspot.com") + let imageRef = storage.child("profileImage").child("\(user.uid).jpeg") + var ProfileImageData: Data = Data() + if imageView.image != nil { + + //画像を圧縮 + ProfileImageData = (imageView.image?.jpegData(compressionQuality: 0.01))! + + } + imageRef.putData(ProfileImageData, metadata: nil) { (metaData, error) in + + //エラーであれば + if error != nil { + + print(error.debugDescription) + return //これより下にはいかないreturn + } + } + + } } diff --git a/chat-iOS/Views/EditProfile/EditProfilePresenter.swift b/chat-iOS/Views/EditProfile/EditProfilePresenter.swift index b4651d9..6269fd0 100644 --- a/chat-iOS/Views/EditProfile/EditProfilePresenter.swift +++ b/chat-iOS/Views/EditProfile/EditProfilePresenter.swift @@ -30,7 +30,7 @@ final class EditProfileViewPresenter: EditProfileViewPresenterProtocol, EditProf self.model = model } - func didTapStopEditProfileButton(){ + func didTapStopEditProfileButton() { view.dismissEditProfileViewController() } @@ -38,11 +38,11 @@ final class EditProfileViewPresenter: EditProfileViewPresenterProtocol, EditProf self.model.saveProfile() } - func didTapChangePhotoButton(){ + func didTapChangePhotoButton() { view.showActionSheet() } - func didTapPickupPhotoAction(){ + func didTapPickupPhotoAction() { view.showImagePickerControllerAsPhotoLibrary() } diff --git a/chat-iOS/Views/EditProfile/EditProfileViewController.swift b/chat-iOS/Views/EditProfile/EditProfileViewController.swift index da1be61..67c61c7 100644 --- a/chat-iOS/Views/EditProfile/EditProfileViewController.swift +++ b/chat-iOS/Views/EditProfile/EditProfileViewController.swift @@ -6,6 +6,7 @@ // import UIKit +import Firebase final class EditProfileViewController: UIViewController { private var presenter: EditProfileViewPresenterProtocol! @@ -24,11 +25,9 @@ final class EditProfileViewController: UIViewController { } - func inject(with presenter: EditProfileViewPresenterProtocol) { self.presenter = presenter self.presenter.view = self - } func setupNavigationItem() { @@ -54,28 +53,23 @@ final class EditProfileViewController: UIViewController { print("キャンセルボタンタップされた") self.presenter.didTapStopEditProfileButton() - } + //TODO: ここでデータをセーブする処理を行う @objc func tapSaveEditProfileButton() { print("セーブボタンタップされた") - + self.presenter.didTapSaveEditProfileButton() - } @IBAction func tapChangePhotoButton(_ sender: Any) { - self.presenter.didTapChangePhotoButton() } - - } extension EditProfileViewController: EditProfileViewPresenterOutput { func dismissEditProfileViewController() { self.dismiss(animated: true, completion: nil) - } func showActionSheet() { @@ -129,7 +123,6 @@ extension EditProfileViewController: EditProfileViewPresenterOutput { self.present(photoPickerVC, animated: true, completion: nil) } } - } extension EditProfileViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { @@ -145,6 +138,7 @@ extension EditProfileViewController: UIImagePickerControllerDelegate, UINavigati self.imageView.image = pickerImage picker.dismiss(animated: true) } - } + + From 45a3f91b23049662098c9a1930d7b0979d436fa8 Mon Sep 17 00:00:00 2001 From: Aki Kuratani Date: Mon, 20 Jul 2020 19:24:20 +0900 Subject: [PATCH 02/12] =?UTF-8?q?=E5=90=8D=E5=89=8D=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Profile/UserProfileViewController.swift | 5 ++- .../Views/Profile/UserProfileViewModel.swift | 32 +++++++++++++++++-- .../Profile/UserProfileViewPresenter.swift | 6 ++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/chat-iOS/Views/Profile/UserProfileViewController.swift b/chat-iOS/Views/Profile/UserProfileViewController.swift index e97bdf5..458f2d7 100644 --- a/chat-iOS/Views/Profile/UserProfileViewController.swift +++ b/chat-iOS/Views/Profile/UserProfileViewController.swift @@ -37,7 +37,10 @@ extension UserProfileViewController: UserProfileViewPresenterOutput { navigationController.modalPresentationStyle = .fullScreen self.present(navigationController, animated: true, completion: nil) } - func setUser() { + func setUserName(userName: String) { + DispatchQueue.main.async { + self.profileNameLabel.text = userName + } } } diff --git a/chat-iOS/Views/Profile/UserProfileViewModel.swift b/chat-iOS/Views/Profile/UserProfileViewModel.swift index 9f9f2d3..4e1ce3a 100644 --- a/chat-iOS/Views/Profile/UserProfileViewModel.swift +++ b/chat-iOS/Views/Profile/UserProfileViewModel.swift @@ -4,6 +4,7 @@ // // Created by 倉谷 明希 on 2020/06/22. // +import Firebase protocol UserProfileViewModelProtocol { var presenter: UserProfileViewModelOutput! { get set } @@ -11,13 +12,40 @@ protocol UserProfileViewModelProtocol { } protocol UserProfileViewModelOutput { - func successFetchUser() + func successFetchUser(user: User) } final class UserProfileViewModel: UserProfileViewModelProtocol { var presenter: UserProfileViewModelOutput! + var firestore: Firestore! + + init() { + self.firestore = Firestore.firestore() + let setting = FirestoreSettings() + self.firestore.settings = setting + } func fetchUser() { - self.presenter.successFetchUser() + self.firestore.collection("message/v1/users").document("y783WJnXJqDfDED0nBvK").getDocument { (document, error) in + if let error = error { + print("Error: \(error.localizedDescription)") + return + } + + guard let document = document, document.exists else { + print("The document doesn't exist.") + return + } + + do { + let user = try Firestore.Decoder().decode(User.self, from: document.data()!) + self.presenter.successFetchUser(user: user) + } catch { + fatalError() + } + + + } + } } diff --git a/chat-iOS/Views/Profile/UserProfileViewPresenter.swift b/chat-iOS/Views/Profile/UserProfileViewPresenter.swift index b6d4dd1..52a099b 100644 --- a/chat-iOS/Views/Profile/UserProfileViewPresenter.swift +++ b/chat-iOS/Views/Profile/UserProfileViewPresenter.swift @@ -12,7 +12,7 @@ protocol UserProfileViewPresenterProtocol { } protocol UserProfileViewPresenterOutput { - func setUser() + func setUserName(userName: String) func presentEditProfileViewController() } @@ -29,8 +29,8 @@ final class UserProfileViewPresenter: UserProfileViewPresenterProtocol, UserProf func didLoadViewController() { self.model.fetchUser() } - func successFetchUser() { - self.view.setUser() + func successFetchUser(user: User) { + self.view.setUserName(userName: user.displayName) } func didTapEditProfileButton() { self.view.presentEditProfileViewController() From 1930ca176be07d923e8637667c0a5333767ddf16 Mon Sep 17 00:00:00 2001 From: Aki Kuratani Date: Mon, 20 Jul 2020 19:45:18 +0900 Subject: [PATCH 03/12] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E5=87=BA?= =?UTF-8?q?=E3=81=9F=E3=81=8B=E3=82=89=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=A2=E3=82=A6=E3=83=88=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/EditProfile/EditProfileModel.swift | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/chat-iOS/Views/EditProfile/EditProfileModel.swift b/chat-iOS/Views/EditProfile/EditProfileModel.swift index e082d85..387bced 100644 --- a/chat-iOS/Views/EditProfile/EditProfileModel.swift +++ b/chat-iOS/Views/EditProfile/EditProfileModel.swift @@ -19,24 +19,24 @@ final class EditProfileModel: EditProfileModelProtocol { var presenter: EditProfileModelOutput! func saveProfile() { - let storage = Storage.storage().reference(forURL: "gs://mapapp6-bf5a1.appspot.com") - let imageRef = storage.child("profileImage").child("\(user.uid).jpeg") - var ProfileImageData: Data = Data() - if imageView.image != nil { - - //画像を圧縮 - ProfileImageData = (imageView.image?.jpegData(compressionQuality: 0.01))! - - } - imageRef.putData(ProfileImageData, metadata: nil) { (metaData, error) in - - //エラーであれば - if error != nil { - - print(error.debugDescription) - return //これより下にはいかないreturn - } - } +// let storage = Storage.storage().reference(forURL: "gs://mapapp6-bf5a1.appspot.com") +// let imageRef = storage.child("profileImage").child("\(user.uid).jpeg") +// var ProfileImageData: Data = Data() +// if imageView.image != nil { +// +// //画像を圧縮 +// ProfileImageData = (imageView.image?.jpegData(compressionQuality: 0.01))! +// +// } +// imageRef.putData(ProfileImageData, metadata: nil) { (metaData, error) in +// +// //エラーであれば +// if error != nil { +// +// print(error.debugDescription) +// return //これより下にはいかないreturn +// } +// } From 19cc1053f400355daafa82f9968c7b97bbe5aadb Mon Sep 17 00:00:00 2001 From: Aki Kuratani Date: Mon, 20 Jul 2020 20:35:09 +0900 Subject: [PATCH 04/12] =?UTF-8?q?=E7=94=BB=E5=83=8F=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Profile/UserProfileViewController.swift | 11 +++++++++- .../Views/Profile/UserProfileViewModel.swift | 21 +++++++++++++++++++ .../Profile/UserProfileViewPresenter.swift | 5 +++++ .../Views/Storyboards/UserProfile.storyboard | 6 +++--- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/chat-iOS/Views/Profile/UserProfileViewController.swift b/chat-iOS/Views/Profile/UserProfileViewController.swift index 458f2d7..3b6a59a 100644 --- a/chat-iOS/Views/Profile/UserProfileViewController.swift +++ b/chat-iOS/Views/Profile/UserProfileViewController.swift @@ -17,6 +17,7 @@ final class UserProfileViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() editProfileButton.layer.cornerRadius = 10.0 + profileImageView.layer.cornerRadius = profileImageView.frame.height / 2 self.presenter.didLoadViewController() } @@ -42,5 +43,13 @@ extension UserProfileViewController: UserProfileViewPresenterOutput { self.profileNameLabel.text = userName } } - + func setUserProfileImage(imageData: Data) { + DispatchQueue.main.async { + self.profileImageView.image = UIImage(data: imageData)! + self.profileImageView.alpha = 0 + UIView.animate(withDuration: 0.25, animations: { + self.profileImageView.alpha = 1 + }) + } + } } diff --git a/chat-iOS/Views/Profile/UserProfileViewModel.swift b/chat-iOS/Views/Profile/UserProfileViewModel.swift index 4e1ce3a..36b1fc5 100644 --- a/chat-iOS/Views/Profile/UserProfileViewModel.swift +++ b/chat-iOS/Views/Profile/UserProfileViewModel.swift @@ -13,6 +13,7 @@ protocol UserProfileViewModelProtocol { protocol UserProfileViewModelOutput { func successFetchUser(user: User) + func successFetchImageData(imageData: Data) } final class UserProfileViewModel: UserProfileViewModelProtocol { @@ -40,6 +41,7 @@ final class UserProfileViewModel: UserProfileViewModelProtocol { do { let user = try Firestore.Decoder().decode(User.self, from: document.data()!) self.presenter.successFetchUser(user: user) + self.downloadProfile(downLoadURL: user.profileImageURL ?? "") } catch { fatalError() } @@ -48,4 +50,23 @@ final class UserProfileViewModel: UserProfileViewModelProtocol { } } + + private func downloadProfile(downLoadURL: String) { + let httpsReference = Storage.storage().reference(forURL: downLoadURL) + httpsReference.getData(maxSize: 1 * 512 * 512) { data, error in + if let error = error { + print("プロ画取得エラー") + print(error.localizedDescription) + return + } + + guard let data = data else { + print("プロ画取得エラー") + return + } + + print("プロ画取得成功!") + self.presenter.successFetchImageData(imageData: data) + } + } } diff --git a/chat-iOS/Views/Profile/UserProfileViewPresenter.swift b/chat-iOS/Views/Profile/UserProfileViewPresenter.swift index 52a099b..2fc5b54 100644 --- a/chat-iOS/Views/Profile/UserProfileViewPresenter.swift +++ b/chat-iOS/Views/Profile/UserProfileViewPresenter.swift @@ -4,6 +4,7 @@ // // Created by 倉谷 明希 on 2020/06/22. // +import Foundation protocol UserProfileViewPresenterProtocol { var view: UserProfileViewPresenterOutput! { get set } @@ -13,6 +14,7 @@ protocol UserProfileViewPresenterProtocol { protocol UserProfileViewPresenterOutput { func setUserName(userName: String) + func setUserProfileImage(imageData: Data) func presentEditProfileViewController() } @@ -32,6 +34,9 @@ final class UserProfileViewPresenter: UserProfileViewPresenterProtocol, UserProf func successFetchUser(user: User) { self.view.setUserName(userName: user.displayName) } + func successFetchImageData(imageData: Data) { + self.view.setUserProfileImage(imageData: imageData) + } func didTapEditProfileButton() { self.view.presentEditProfileViewController() } diff --git a/chat-iOS/Views/Storyboards/UserProfile.storyboard b/chat-iOS/Views/Storyboards/UserProfile.storyboard index 23db718..9bf8d3e 100644 --- a/chat-iOS/Views/Storyboards/UserProfile.storyboard +++ b/chat-iOS/Views/Storyboards/UserProfile.storyboard @@ -36,13 +36,13 @@ -