Skip to content

Commit

Permalink
Merge pull request #261 from TeamNADA/release1.0/#257
Browse files Browse the repository at this point in the history
[FEAT] #257 - 명함 그룹뷰 인파이나이트스크롤 구현
  • Loading branch information
hyun99999 authored Dec 29, 2021
2 parents ad52a55 + 7965b86 commit ded11cd
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 48 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 @@ -72,11 +72,13 @@ class SelectGroupBottomSheetViewController: CommonBottomSheetViewController {
@objc func presentCardInfoViewController() {
switch status {
case .detail:
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
changeGroupWithAPI(request: ChangeGroupRequest(cardID: cardDataModel?.cardID ?? "",
userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "",
groupID: groupId ?? 0,
newGroupID: selectedGroup))
case .add, .addWithQR:
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
cardAddInGroupWithAPI(cardRequest: CardAddInGroupRequest(cardId: cardDataModel?.cardID ?? "",
userId: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "",
groupId: selectedGroup))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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,22 @@ 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)
groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "")

}

}

extension GroupViewController {
Expand All @@ -107,9 +97,26 @@ 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(scrollToTop), name: .reloadGroupViewController, object: nil)
}

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

@objc
private func scrollToTop() {
offset = 0
frontCards?.removeAll()
groupListFetchWithAPI(userID: UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) ?? "")
// FIXME: - 스크롤 탑
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
}
// cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false)
}
}

// MARK: - Network
Expand All @@ -123,9 +130,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 +148,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 +198,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 +217,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 +240,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 +269,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,12 @@ class QRScanViewController: UIViewController {
super.viewDidLoad()
basicSetting()
}

}

extension QRScanViewController {
@objc func dismissQRScanViewController() {
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
self.dismiss(animated: true, completion: nil)
presentingViewController?.viewWillAppear(true)
}
}

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

self.groupEditTableView.reloadData()

}

// MARK: - @IBAction Properties
@IBAction func dismissToPreviousView(_ sender: UIButton) {
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil)
self.navigationController?.popViewController(animated: true)
}

Expand Down

0 comments on commit ded11cd

Please sign in to comment.