Skip to content

Commit

Permalink
feat: 폴더 생성 후 화면 이동 Notigication 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
heejinnn committed Feb 20, 2024
1 parent 609a330 commit ad1c350
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 26 deletions.
6 changes: 5 additions & 1 deletion fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
4A2974A62B7FCD7E00587AF8 /* CustomCategoryStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2974A52B7FCD7E00587AF8 /* CustomCategoryStackView.swift */; };
4A2974A82B7FD5D100587AF8 /* CustomPanModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2974A72B7FD5D100587AF8 /* CustomPanModalView.swift */; };
4A2974AA2B7FD70700587AF8 /* TotalFolderPanModalVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2974A92B7FD70700587AF8 /* TotalFolderPanModalVC.swift */; };
4A2D55D52B84C87F0079FDC7 /* NoRecordDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2D55D42B84C87F0079FDC7 /* NoRecordDataView.swift */; };
4A3D7BFA2B4F120900E3BBF8 /* CareDateCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A3D7BF92B4F120900E3BBF8 /* CareDateCollectionViewCell.swift */; };
4A3D7BFD2B4F1F4500E3BBF8 /* CategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A3D7BFC2B4F1F4500E3BBF8 /* CategoryView.swift */; };
4A3D7BFF2B4F231500E3BBF8 /* ScheduleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A3D7BFE2B4F231500E3BBF8 /* ScheduleView.swift */; };
Expand Down Expand Up @@ -166,6 +167,7 @@
4A2974A52B7FCD7E00587AF8 /* CustomCategoryStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCategoryStackView.swift; sourceTree = "<group>"; };
4A2974A72B7FD5D100587AF8 /* CustomPanModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPanModalView.swift; sourceTree = "<group>"; };
4A2974A92B7FD70700587AF8 /* TotalFolderPanModalVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TotalFolderPanModalVC.swift; sourceTree = "<group>"; };
4A2D55D42B84C87F0079FDC7 /* NoRecordDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoRecordDataView.swift; sourceTree = "<group>"; };
4A3D7BF92B4F120900E3BBF8 /* CareDateCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CareDateCollectionViewCell.swift; sourceTree = "<group>"; };
4A3D7BFC2B4F1F4500E3BBF8 /* CategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryView.swift; sourceTree = "<group>"; };
4A3D7BFE2B4F231500E3BBF8 /* ScheduleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -288,7 +290,7 @@
4A0150382B76919B0069AF20 /* FolderTableViewCell.swift */,
4A4B08572B77AE3200959683 /* RecordListView.swift */,
4A4B08592B77B15400959683 /* RecordListTableViewCell.swift */,
4A1B5E482B79476A00A076A7 /* PetImageCollectionViewCell.swift */,
4A2D55D42B84C87F0079FDC7 /* NoRecordDataView.swift */,
);
path = RecordView;
sourceTree = "<group>";
Expand Down Expand Up @@ -444,6 +446,7 @@
4ABB933C2B7BDBC200E1EA73 /* CreateRecordView */ = {
isa = PBXGroup;
children = (
4A1B5E482B79476A00A076A7 /* PetImageCollectionViewCell.swift */,
4ABB933F2B7BDCB900E1EA73 /* ButtonStackView.swift */,
);
path = CreateRecordView;
Expand Down Expand Up @@ -874,6 +877,7 @@
4ABE53002B5AD92F000EA41D /* PetDataManager.swift in Sources */,
4A88D6172B53ABD2003A2D0F /* PetCareRegistrationManager.swift in Sources */,
4A4B085C2B77D2DF00959683 /* RecordVCMethod.swift in Sources */,
4A2D55D52B84C87F0079FDC7 /* NoRecordDataView.swift in Sources */,
4A9936542B64231B00B7B21A /* CalendarView.swift in Sources */,
4ACDD4A92ADAFFD100CD8F1A /* InputPetBirthVC.swift in Sources */,
4ABB933B2B7BD60F00E1EA73 /* RecordCreateManager.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PetCareCollectionViewMethod: NSObject, UICollectionViewDataSource, UIColle
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "PetCareHeaderView", for: indexPath) as! PetCareHeaderView
if let careCategory = petCareData[3]?[indexPath.section] {
if let careCategory = petCareData[selectedPet]?[indexPath.section] {
headerView.titleLabel.text = careCategory.categoryName
}
return headerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ extension Notification.Name {
static let cellSelectedNotification = Notification.Name("CellSelectedNotification")
static let cellSelectedNotificationFromPanModal = Notification.Name("CellSelectedNotificationFromPanModal")
static let cellSelectedNotificationFromRootPanModal = Notification.Name("CellSelectedNotificationFromRootPanModal")

static let FolderCreatedNotification = Notification.Name("FolderCreatedNotification")
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RecordFolderTableViewMethod: NSObject, UITableViewDataSource, UITableViewD

for pet in petData{
if pet.id == memoCategory.petId{
let userInfo: [AnyHashable: Any] = ["memoCategoryId": memoCategory.memoCategoryId, "memoCategoryName": memoCategory.memoCategoryName, "petId": pet.id]
let userInfo: [AnyHashable: Any] = ["memoCategoryId": memoCategory.memoCategoryId, "memoCategoryName": memoCategory.memoCategoryName, "petId": pet.id, "petName": pet.petName]
NotificationCenter.default.post(name: .cellSelectedNotification, object: nil, userInfo: userInfo)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import UIKit
import SnapKit

class NoRecordDataView: UIView{

let textLabel = UILabel()

override init(frame: CGRect) {
super.init(frame: frame)

setupView()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}

func setupView() {

addSubview(textLabel)

let attributedString = NSMutableAttributedString(string: "새로운 기록을\n남겨주세요")
let range = NSRange(location: 8, length: 1)
let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): UIFont.systemFont(ofSize: 14, weight: .medium)]
attributedString.addAttributes(attributes, range: range)

textLabel.attributedText = attributedString
textLabel.numberOfLines = 2
textLabel.textColor = UIColor(named: "Gray3")
textLabel.font = .systemFont(ofSize: 14, weight: .medium)
textLabel.textAlignment = .center

textLabel.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import SnapKit
class CreateFolderVC: CustomNavigationBar{

private let parentFolderLabel = UILabel()
let selecteFolderView = CustomCategoryStackView(label: "전체보기")
let selectFolderView = CustomCategoryStackView(label: "전체보기")
private let folderNameInputView = CustomVerticalView(labelText: "폴더 이름", placeholder: "이름")

private let createButton = CustomNextBtn(title: "폴더 만들기")
private var inputCategoryName = ""
private var categoryId = 0
private var categoryPetId = 0
private var seletedPetName = ""

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -21,7 +22,7 @@ class CreateFolderVC: CustomNavigationBar{
NotificationCenter.default.addObserver(self, selector: #selector(handleCellSelectedNotificationFromRootPanModal(_:)), name: .cellSelectedNotificationFromRootPanModal, object: nil)

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(folderViewTapped))
selecteFolderView.addGestureRecognizer(tapGestureRecognizer)
selectFolderView.addGestureRecognizer(tapGestureRecognizer)

createButton.addTarget(self, action: #selector(createFolderAPI), for: .touchUpInside)
folderNameInputView.textInputField.delegate = self
Expand All @@ -35,7 +36,7 @@ class CreateFolderVC: CustomNavigationBar{
parentFolderLabel.font = .boldSystemFont(ofSize: 18)

view.addSubview(parentFolderLabel)
view.addSubview(selecteFolderView)
view.addSubview(selectFolderView)
view.addSubview(folderNameInputView)
view.addSubview(createButton)

Expand All @@ -45,13 +46,13 @@ class CreateFolderVC: CustomNavigationBar{
make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(32)
}

selecteFolderView.snp.makeConstraints{make in
selectFolderView.snp.makeConstraints{make in
make.top.equalTo(parentFolderLabel.snp.bottom).offset(8)
make.leading.trailing.equalTo(view).inset(16)
}

folderNameInputView.snp.makeConstraints{make in
make.top.equalTo(selecteFolderView.snp.bottom).offset(24)
make.top.equalTo(selectFolderView.snp.bottom).offset(24)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(88)
}
Expand All @@ -71,27 +72,31 @@ class CreateFolderVC: CustomNavigationBar{
guard let userInfo = notification.userInfo as? [String: Any],
let memoCategoryId = userInfo["memoCategoryId"] as? Int,
let memoCategoryName = userInfo["memoCategoryName"] as? String,
let petId = userInfo["petId"] as? Int
let petId = userInfo["petId"] as? Int,
let petName = userInfo["petName"] as? String
else {
return
}
print("Selected memoCategoryId: \(memoCategoryId), memoCategoryName: \(memoCategoryName), petId: \(petId)")
print("Selected memoCategoryId: \(memoCategoryId), memoCategoryName: \(memoCategoryName), petId: \(petId), petName: \(petName)")

categoryId = memoCategoryId
selecteFolderView.selectedText = memoCategoryName
selectFolderView.selectedText = memoCategoryName
categoryPetId = petId
seletedPetName = petName
}

@objc func createFolderAPI(){
AuthorizationAlamofire.shared.createFolder(categoryPetId, categoryId, inputCategoryName) { result in
AuthorizationAlamofire.shared.createFolder(categoryPetId, categoryId, inputCategoryName) { [self] result in
switch result {
case .success(let data):
if let responseData = data,
let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
print("response jsonData: \(jsonObject)")

NotificationCenter.default.post(name: Notification.Name("FolderCreatedNotification"), object: nil, userInfo: ["categoryId": categoryId, "categoryPetId": categoryPetId, "inputCategoryName": inputCategoryName, "petName": seletedPetName])
self.navigationController?.popToRootViewController(animated: true)
}

case .failure(let error):
print("Error: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ class RootFolderPanModalVC: UIViewController {
guard let userInfo = notification.userInfo as? [String: Any],
let memoCategoryId = userInfo["memoCategoryId"] as? Int,
let memoCategoryName = userInfo["memoCategoryName"] as? String,
let petId = userInfo["petId"] as? Int
let petId = userInfo["petId"] as? Int,
let petName = userInfo["petName"] as? String
else {
return
}
print("Selected memoCategoryId: \(memoCategoryId), memoCategoryName: \(memoCategoryName), petId: \(petId)")
print("Selected memoCategoryId: \(memoCategoryId), memoCategoryName: \(memoCategoryName), petId: \(petId), petName: \(petName)")

NotificationCenter.default.removeObserver(self, name: .cellSelectedNotification, object: nil)
NotificationCenter.default.post(name: .cellSelectedNotificationFromRootPanModal, object: nil, userInfo: userInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RecordVC: UIViewController{
private let folderView = CustomCategoryStackView(label: "전체보기")
private let listView = RecordListView()
private let listTableViewMethod = RecordListTableViewMethod()
private let noListDataView = NoRecordDataView()
private var selectedMemoCategoryId = 0
private var selectedPetId = 0

Expand All @@ -18,6 +19,7 @@ class RecordVC: UIViewController{

userTotalFolderListAPI()
NotificationCenter.default.addObserver(self, selector: #selector(handleCellSelectionNotificationFromPanModal(_:)), name: .cellSelectedNotificationFromPanModal, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleFolderCreatedNotification(_:)), name: Notification.Name("FolderCreatedNotification"), object: nil)

initView()
setupNavigationBar()
Expand Down Expand Up @@ -50,6 +52,9 @@ class RecordVC: UIViewController{
view.addSubview(dataScrollView)
view.addSubview(folderView)
dataScrollView.addSubview(listView)
dataScrollView.addSubview(noListDataView)

noListDataView.isHidden = true

let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
imageView.image = UIImage(named: "search")
Expand Down Expand Up @@ -82,7 +87,8 @@ class RecordVC: UIViewController{

dataScrollView.snp.makeConstraints { make in
make.top.equalTo(folderView.snp.bottom).offset(8)
make.leading.trailing.bottom.equalToSuperview()
make.leading.trailing.equalToSuperview()
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
}

folderView.snp.makeConstraints{make in
Expand All @@ -96,6 +102,10 @@ class RecordVC: UIViewController{
make.height.equalTo(0)
make.bottom.equalTo(dataScrollView.snp.bottom)
}
noListDataView.snp.makeConstraints{make in
make.centerX.centerY.equalTo(dataScrollView)
make.height.equalTo(50)
}

}

Expand All @@ -114,6 +124,17 @@ class RecordVC: UIViewController{
recordButton.tintColor = .black
navigationItem.rightBarButtonItems = [recordButton, folderButton]
}

func updatelistViewHeight() {

let heightForRow:CGFloat = 88
let totalCellHeight = CGFloat(listView.recordListTableView.numberOfRows(inSection: 0)) * heightForRow

listView.snp.updateConstraints { make in
make.height.equalTo(totalCellHeight + 200)
}
}

@objc func didTapfolederAddButton(){
let nextVC = CreateFolderVC(title: "폴더 만들기")
nextVC.hidesBottomBarWhenPushed = true
Expand All @@ -131,6 +152,7 @@ class RecordVC: UIViewController{
let nextVC = TotalFolderPanModalVC()
self.presentPanModal(nextVC)
}

@objc func handleCellSelectionNotificationFromPanModal(_ notification: Notification) {
guard let userInfo = notification.userInfo as? [String: Any],
let memoCategoryId = userInfo["memoCategoryId"] as? Int,
Expand All @@ -152,16 +174,23 @@ class RecordVC: UIViewController{

recordDataListAPI()
}

func updatelistViewHeight() {

let heightForRow:CGFloat = 88
let totalCellHeight = CGFloat(listView.recordListTableView.numberOfRows(inSection: 0)) * heightForRow

listView.snp.updateConstraints { make in
make.height.equalTo(totalCellHeight + 200)

@objc func handleFolderCreatedNotification(_ notification: Notification) {
guard let userInfo = notification.userInfo as? [String: Any],
let categoryId = userInfo["categoryId"] as? Int,
let categoryPetId = userInfo["categoryPetId"] as? Int,
let inputCategoryName = userInfo["inputCategoryName"] as? String,
let petName = userInfo["petName"] as? String
else {
return
}

self.folderView.selectedText = "\(petName)/\(inputCategoryName)"
selectedMemoCategoryId = categoryId
selectedPetId = categoryPetId
recordDataListAPI()
}

func userTotalFolderListAPI(){
AuthorizationAlamofire.shared.recordTotalFolderList { result in
switch result {
Expand Down Expand Up @@ -248,11 +277,18 @@ class RecordVC: UIViewController{
memoList.append(memo)
}
}

if memoList.count == 0{
self.noListDataView.isHidden = false
self.listView.isHidden = true
}else{
self.noListDataView.isHidden = true
self.listView.isHidden = false
}
RecordDataListManager.shared.updateRecordData(newData: memoList)
print( RecordDataListManager.shared.recordData)

self.listView.recordListTableView.reloadData()
self.updatelistViewHeight()

} catch {
print("Error parsing JSON: \(error)")
Expand Down

0 comments on commit ad1c350

Please sign in to comment.