Skip to content

Commit

Permalink
Merge pull request #361 from DeveloperAcademy-POSTECH/feature/357-pus…
Browse files Browse the repository at this point in the history
…hnotification-viewcontroller

[FEAT] 푸시알림을 눌렀을 때 해당 방의 쪽지뷰로 이동 기능 구현
  • Loading branch information
MMMIIIN authored Jan 16, 2023
2 parents 5faf0e6 + ef5fe6f commit bf479b0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
14 changes: 12 additions & 2 deletions Manito/Manito/Global/Supports/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
completionHandler([.badge, .sound])
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
guard let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate
as? SceneDelegate else { return }
let userInfo = response.notification.request.content.userInfo
if let roomId = userInfo["roomId"] as? String {
guard let roomId = Int(roomId) else { return }
sceneDelegate.changeRootViewWithLetterView(roomId: roomId)
} else {
sceneDelegate.showRoomIdErrorAlert()
}

completionHandler()
}
}
}
12 changes: 12 additions & 0 deletions Manito/Manito/Global/Supports/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ extension SceneDelegate {
func logout() {
window?.rootViewController = LoginViewController()
}

func changeRootViewWithLetterView(roomId: Int) {
let mainViewController = MainViewController()
let rootViewController = UINavigationController(rootViewController: mainViewController)
window?.rootViewController = rootViewController
mainViewController.pushDetailViewController(roomId: roomId)
}

func showRoomIdErrorAlert() {
let mainViewController = MainViewController()
mainViewController.showRoomIdErrorAlert()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ class DetailIngViewController: BaseViewController {
let roomId = self?.roomInformation?.id,
let mission = self?.missionContentsLabel.text
else { return }
let letterViewController = LetterViewController(roomState: roomType.rawValue, roomId: roomId.description, mission: mission)
let letterViewController = LetterViewController(roomState: roomType.rawValue,
roomId: roomId.description,
mission: mission,
letterState: .sent)
self?.navigationController?.pushViewController(letterViewController, animated: true)
}
letterBoxButton.addAction(action, for: .touchUpInside)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ final class DetailingCodebaseViewController: BaseViewController {
private let roomId: String
private var roomType: RoomType = .PROCESSING
private var isTappedManittee: Bool = false
var letterViewController: UIViewController {
guard let mission = missionContentsLabel.text else { return UIViewController() }
let viewController = LetterViewController(roomState: roomType.rawValue,
roomId: roomId,
mission: mission,
letterState: .received)
return viewController
}

// MARK: - property

Expand Down Expand Up @@ -133,7 +141,10 @@ final class DetailingCodebaseViewController: BaseViewController {
let roomId = self?.roomId,
let mission = self?.missionContentsLabel.text
else { return }
let letterViewController = LetterViewController(roomState: roomType.rawValue, roomId: roomId, mission: mission)
let letterViewController = LetterViewController(roomState: roomType.rawValue,
roomId: roomId,
mission: mission,
letterState: .sent)
self?.navigationController?.pushViewController(letterViewController, animated: true)
}
button.addAction(action, for: .touchUpInside)
Expand Down Expand Up @@ -472,6 +483,10 @@ final class DetailingCodebaseViewController: BaseViewController {
exitButton.menu = menu
}
}

func pushLetterViewControllerReceivedType() {
self.navigationController?.pushViewController(letterViewController, animated: true)
}

// MARK: - selector

Expand Down
18 changes: 12 additions & 6 deletions Manito/Manito/Screens/Letter/LetterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SnapKit

final class LetterViewController: BaseViewController {

private enum LetterState: Int {
enum LetterState: Int {
case sent = 0
case received = 1

Expand Down Expand Up @@ -74,11 +74,10 @@ final class LetterViewController: BaseViewController {
}()
private lazy var sendLetterView = SendLetterView()

private var letterState: LetterState = .sent {
private var letterState: LetterState {
didSet {
reloadCollectionView(with: self.letterState)
emptyLabel.text = letterState.labelText
emptyLabel.isHidden = true
setupEmptyLabel()
}
}

Expand Down Expand Up @@ -109,10 +108,11 @@ final class LetterViewController: BaseViewController {

// MARK: - init

init(roomState: String, roomId: String, mission: String) {
init(roomState: String, roomId: String, mission: String, letterState: LetterState) {
self.roomState = roomState
self.roomId = roomId
self.mission = mission
self.letterState = letterState
super.init()
}

Expand Down Expand Up @@ -164,7 +164,8 @@ final class LetterViewController: BaseViewController {

override func configUI() {
super.configUI()
letterState = .sent
reloadCollectionView(with: self.letterState)
setupEmptyLabel()
}

override func setupNavigationBar() {
Expand Down Expand Up @@ -272,6 +273,11 @@ final class LetterViewController: BaseViewController {
view.addGestureRecognizer(viewTap)
}

private func setupEmptyLabel() {
emptyLabel.text = letterState.labelText
emptyLabel.isHidden = true
}

// MARK: - selector

@objc
Expand Down
12 changes: 12 additions & 0 deletions Manito/Manito/Screens/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ final class MainViewController: BaseViewController {
}
}

func pushDetailViewController(roomId: Int) {
let viewController = DetailingCodebaseViewController(roomId: roomId.description)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.pushViewController(viewController, animated: true)
viewController.pushLetterViewControllerReceivedType()
}
}

func showRoomIdErrorAlert() {
makeRequestAlert(title: "해당 마니또 방의 정보를 불러오지 못했습니다.", message: "해당 마니또 방으로 이동할 수 없습니다.", okAction: nil)
}

@objc
override func endEditingView() {
if !guideButton.isTouchInside {
Expand Down

0 comments on commit bf479b0

Please sign in to comment.