Skip to content

Commit

Permalink
Merge branch 'release1.0/3' into release/TeamNADA#218
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwns33 committed Dec 29, 2021
2 parents bdaa8be + 0c7093d commit 5f0cc83
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
3 changes: 2 additions & 1 deletion NADA-iOS-forRelease/Resouces/Constants/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension Notification.Name {
static let presentCardShare = Notification.Name("presentCardShare")
static let passDataToGroup = Notification.Name("passDataToGroup")
static let passDataToDetail = Notification.Name("passDataToDetail")
static let listReloadMainCardSwiper = Notification.Name("listReloadMainCardSwiper")
static let reloadGroupViewController = Notification.Name("reloadGroupViewController")
static let creationReloadMainCardSwiper = Notification.Name("creationReloadMainCardSwiper")
static let listReloadMainCardSwiper = Notification.Name("listReloadMainCardSwiper")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ class CardInGroupCollectionViewCell: UICollectionViewCell {

override func awakeFromNib() {
super.awakeFromNib()
setUI()
}

override func prepareForReuse() {
super.prepareForReuse()

backgroundImageView.image = UIImage()
titleLabel.text = ""
descriptionLabel.text = ""
userNameLabel.text = ""
birthLabel.text = ""
mbtiLabel.text = ""
instagramIDLabel.text = ""
mbtiLabel.text = ""
instagramIcon.image = UIImage()
urlIcon.image = UIImage()
}

static func nib() -> UINib {
return UINib(nibName: Const.Xib.cardInGroupCollectionViewCell, bundle: Bundle(for: CardInGroupCollectionViewCell.self))
}

}

extension CardInGroupCollectionViewCell {
private func setUI() {

// backgroundImageView.alpha = 0.4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class CardDetailViewController: UIViewController {
case .group:
self.navigationController?.popViewController(animated: true)
case .add:
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
self.dismiss(animated: true, completion: nil)
case .addWithQR:
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)

case .detail:
Expand All @@ -28,7 +30,6 @@ class CardDetailViewController: UIViewController {
@IBAction func presentHarmonyViewController(_ sender: Any) {
cardHarmonyFetchWithAPI(myCard: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.firstCardID) ?? "",
yourCard: cardDataModel?.cardID ?? "")

}

@IBOutlet weak var optionButton: UIButton!
Expand Down Expand Up @@ -132,6 +133,7 @@ extension CardDetailViewController {
self.makeCancelDeleteAlert(title: "명함 삭제",
message: "명함을 정말 삭제하시겠습니까?",
deleteAction: { _ in
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
// 명함 삭제 서버통신
self.cardDeleteInGroupWithAPI(groupID: self.groupId ?? 0, cardID: self.cardDataModel?.cardID ?? "")
}) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,29 @@ class GroupViewController: UIViewController {

// 그룹 이름들을 담을 변수 생성
var serverGroups: Groups?
var serverCards: CardsInGroupResponse?
var frontCards: [FrontCard]? = []
var serverCardsWithBack: Card?
var groupId: Int?

var selectedRow = 0
private var offset = 0
private var isInfiniteScroll = true

override func viewDidLoad() {
super.viewDidLoad()

registerCell()
setNotification()
setUI()

// 그룹 속 명함 조회 테스트
// cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: "nada", groupId: 5, offset: 0))
// 명함 검색 테스트
// cardDetailFetchWithAPI(cardID: "cardA")

}

override func viewWillAppear(_ animated: Bool) {
// 그룹 리스트 조회 서버 테스트
super.viewWillAppear(true)
NotificationCenter.default.addObserver(self, selector: #selector(didRecieveDataNotification(_:)), name: Notification.Name.passDataToGroup, object: nil)
super.viewWillAppear(animated)

offset = 0
frontCards?.removeAll()
groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "")

}

}

extension GroupViewController {
Expand All @@ -107,9 +104,32 @@ extension GroupViewController {
navigationController?.navigationBar.isHidden = true
}

private func setNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(didRecieveDataNotification(_:)), name: Notification.Name.passDataToGroup, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(relaodCardCollection), name: .reloadGroupViewController, object: nil)
}
// FIXME: - 스크롤탑
private func scrollToTop(completion: () -> Void) {
groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "")
completion()
}

@objc func didRecieveDataNotification(_ notification: Notification) {
selectedRow = notification.object as? Int ?? 0
}

@objc
private func relaodCardCollection() {
offset = 0
frontCards?.removeAll()

// FIXME: - 스크롤 탑
// scrollToTop {
// self.cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
// }
groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "")
// cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
}
}

// MARK: - Network
Expand All @@ -123,9 +143,7 @@ extension GroupViewController {
self.serverGroups = group
self.groupCollectionView.reloadData()
self.groupId = group.groups[self.selectedRow].groupID
if !group.groups.isEmpty {
self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "", groupId: group.groups[self.selectedRow].groupID, offset: 0))
}
self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "", groupId: group.groups[self.selectedRow].groupID, offset: 0))
}
case .requestErr(let message):
print("groupListFetchWithAPI - requestErr: \(message)")
Expand All @@ -143,9 +161,11 @@ extension GroupViewController {
GroupAPI.shared.cardListFetchInGroup(cardListInGroupRequest: cardListInGroupRequest) { response in
switch response {
case .success(let data):
self.isInfiniteScroll = true

if let cards = data as? CardsInGroupResponse {
self.serverCards = cards
if cards.cards.count == 0 {
self.frontCards?.append(contentsOf: cards.cards)
if self.frontCards?.count == 0 {
self.emptyView.isHidden = false
} else {
self.emptyView.isHidden = true
Expand Down Expand Up @@ -191,7 +211,16 @@ extension GroupViewController {

// MARK: - UICollectionViewDelegate
extension GroupViewController: UICollectionViewDelegate {

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if cardsCollectionView.contentOffset.y > cardsCollectionView.contentSize.height - cardsCollectionView.bounds.height {
if isInfiniteScroll {
isInfiniteScroll = false
offset += 1

cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "", groupId: serverGroups?.groups[self.selectedRow].groupID ?? -1, offset: offset))
}
}
}
}

// MARK: - UICollectionViewDataSource
Expand All @@ -201,7 +230,7 @@ extension GroupViewController: UICollectionViewDataSource {
case groupCollectionView:
return serverGroups?.groups.count ?? 0
case cardsCollectionView:
return serverCards?.cards.count ?? 0
return frontCards?.count ?? 0
default:
return 0
}
Expand All @@ -224,21 +253,21 @@ extension GroupViewController: UICollectionViewDataSource {
guard let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: Const.Xib.cardInGroupCollectionViewCell, for: indexPath) as? CardInGroupCollectionViewCell else {
return UICollectionViewCell()
}
guard let frontCards = frontCards else { return UICollectionViewCell() }
cardCell.backgroundImageView.updateServerImage(frontCards[indexPath.row].background)
cardCell.cardId = frontCards[indexPath.row].cardID
cardCell.titleLabel.text = frontCards[indexPath.row].title
cardCell.descriptionLabel.text = frontCards[indexPath.row].cardDescription
cardCell.userNameLabel.text = frontCards[indexPath.row].name
cardCell.birthLabel.text = frontCards[indexPath.row].birthDate
cardCell.mbtiLabel.text = frontCards[indexPath.row].mbti
cardCell.instagramIDLabel.text = frontCards[indexPath.row].instagram
cardCell.lineURLLabel.text = frontCards[indexPath.row].link

cardCell.backgroundImageView.updateServerImage(serverCards?.cards[indexPath.row].background ?? "")
cardCell.cardId = serverCards?.cards[indexPath.row].cardID
cardCell.titleLabel.text = serverCards?.cards[indexPath.row].title
cardCell.descriptionLabel.text = serverCards?.cards[indexPath.row].cardDescription
cardCell.userNameLabel.text = serverCards?.cards[indexPath.row].name
cardCell.birthLabel.text = serverCards?.cards[indexPath.row].birthDate
cardCell.mbtiLabel.text = serverCards?.cards[indexPath.row].mbti
cardCell.instagramIDLabel.text = serverCards?.cards[indexPath.row].instagram
cardCell.lineURLLabel.text = serverCards?.cards[indexPath.row].link

if serverCards?.cards[indexPath.row].instagram == "" {
if frontCards[indexPath.row].instagram == "" {
cardCell.instagramIcon.isHidden = true
}
if serverCards?.cards[indexPath.row].link == "" {
if frontCards[indexPath.row].link == "" {
cardCell.urlIcon.isHidden = true
}

Expand All @@ -253,14 +282,16 @@ extension GroupViewController: UICollectionViewDataSource {
case groupCollectionView:
selectedRow = indexPath.row
groupId = serverGroups?.groups[indexPath.row].groupID
offset = 0
frontCards?.removeAll()
cardListInGroupWithAPI(cardListInGroupRequest:
CardListInGroupRequest(userId: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "",
groupId: serverGroups?.groups[indexPath.row].groupID ?? 0,
offset: 0))
case cardsCollectionView:
cardDetailFetchWithAPI(cardID: serverCards?.cards[indexPath.row].cardID ?? "")
cardDetailFetchWithAPI(cardID: frontCards?[indexPath.row].cardID ?? "")
default:
print(indexPath.row)
return
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ class QRScanViewController: UIViewController {
super.viewDidLoad()
basicSetting()
}

}

extension QRScanViewController {
@objc func dismissQRScanViewController() {
self.dismiss(animated: true, completion: nil)
presentingViewController?.viewWillAppear(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class GroupEditViewController: UIViewController {
super.viewWillAppear(animated)

self.groupEditTableView.reloadData()

}

// MARK: - @IBAction Properties
Expand Down

0 comments on commit 5f0cc83

Please sign in to comment.