-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] #257 - 명함 그룹뷰 인파이나이트스크롤 구현 #261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,32 +63,22 @@ class GroupViewController: UIViewController { | |
|
||
// 그룹 이름들을 담을 변수 생성 | ||
var serverGroups: Groups? | ||
var serverCards: CardsInGroupResponse? | ||
var frontCards: [FrontCard]? = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다.. |
||
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 { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 reloadGRoupViewController은 Notification.Name안해두 먹히나요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
@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 | ||
|
@@ -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)") | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
} | ||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,12 @@ class QRScanViewController: UIViewController { | |
super.viewDidLoad() | ||
basicSetting() | ||
} | ||
|
||
} | ||
|
||
extension QRScanViewController { | ||
@objc func dismissQRScanViewController() { | ||
NotificationCenter.default.post(name: .reloadGroupViewController, object: nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요것도 감사합니다.. |
||
self.dismiss(animated: true, completion: nil) | ||
presentingViewController?.viewWillAppear(true) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 세심하네요 좋아좋아