Skip to content

Commit

Permalink
Merge pull request #620 from yunyezl/feature/#619
Browse files Browse the repository at this point in the history
[#619] ํ”ผ๋“œ ์ปค๋ฎค๋‹ˆํ‹ฐ ํŽ˜์ด์ง• ๋ฒ„๊ทธ ์ˆ˜์ •
  • Loading branch information
yunyezl authored Dec 9, 2021
2 parents 9b6102d + eba64a7 commit e32da8a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
36 changes: 18 additions & 18 deletions Mohaeng/Mohaeng/Resources/Storyboards/Feed/Feed.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0VN-3I-WEj">
<rect key="frame" x="0.0" y="-6" width="414" height="50"/>
<color key="backgroundColor" red="1" green="0.94901960780000005" blue="0.81568627449999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="B4g-TN-APh"/>
</constraints>
</view>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zJm-TA-3Ki">
<rect key="frame" x="333" y="737" width="65" height="65"/>
<constraints>
<constraint firstAttribute="width" constant="65" id="hJD-24-TBt"/>
<constraint firstAttribute="height" constant="65" id="ws3-PI-9jP"/>
</constraints>
<state key="normal" image="floating"/>
<connections>
<action selector="touchFloatingTopButton:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="GVl-Uf-JAe"/>
</connections>
</button>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="wtu-1M-Hvm">
<rect key="frame" x="0.0" y="44" width="414" height="852"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
Expand All @@ -56,6 +38,24 @@
</collectionViewCell>
</cells>
</collectionView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0VN-3I-WEj">
<rect key="frame" x="0.0" y="-6" width="414" height="50"/>
<color key="backgroundColor" red="1" green="0.94901960780000005" blue="0.81568627449999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="B4g-TN-APh"/>
</constraints>
</view>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zJm-TA-3Ki">
<rect key="frame" x="333" y="737" width="65" height="65"/>
<constraints>
<constraint firstAttribute="width" constant="65" id="hJD-24-TBt"/>
<constraint firstAttribute="height" constant="65" id="ws3-PI-9jP"/>
</constraints>
<state key="normal" image="floating"/>
<connections>
<action selector="touchFloatingTopButton:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="GVl-Uf-JAe"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class FeedDetailCollectionViewCell: UICollectionViewCell {
var hasImage: Bool = false
var viewController: FeedDetail = .myDrawer
weak var delegate: TrashReportButtonProtocol?
var currentIndex: Int = 0

// MARK: - View Life Cycle

Expand Down Expand Up @@ -125,6 +126,10 @@ class FeedDetailCollectionViewCell: UICollectionViewCell {
}
}

func setCurrentIndex(currentIndex: Int) {
self.currentIndex = currentIndex
}

private func setMoodImage(moodStatus: Int) {
switch moodStatus {
case 0:
Expand Down Expand Up @@ -182,17 +187,6 @@ class FeedDetailCollectionViewCell: UICollectionViewCell {
func touchTrashButton() {
delegate?.touchTrashButton(reportTrashButton, postId: currentPostId)
}

func getIndexPath() -> Int {
var indexPath = 0

guard let superView = self.superview as? UICollectionView else {
return -1
}
indexPath = superView.indexPath(for: self)!.row

return indexPath
}
}

// MARK: - UIColelctionViewDataSource
Expand All @@ -211,7 +205,7 @@ extension FeedDetailCollectionViewCell: UICollectionViewDataSource {
}

cell.setPostId(postId: currentPostId)
cell.setCurrentIndex(index: getIndexPath())
cell.setCurrentIndex(index: currentIndex)

return cell
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ extension FeedDetailViewController: UICollectionViewDataSource {
cell.setData(feed: myFeed[indexPath.row], viewController: .myDrawer)
case .community:
cell.setData(feed: allFeed.feeds[indexPath.row], viewController: .community)
cell.setCurrentIndex(currentIndex: indexPath.row)

if indexPath.row == allFeed.feeds.count - 1 && !isLast {
bottomPage += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
//

import UIKit

import SnapKit
import Then
import Lottie

class FeedViewController: UIViewController {

Expand All @@ -18,6 +20,7 @@ class FeedViewController: UIViewController {
private var currentData: FeedResponse = FeedResponse(isNew: false, hasFeed: 0, userCount: 0, feeds: [Feed]())
private var currentPage = 0
private var isLast = false
private var cachedPages: [Int] = []

enum Size {
static let FeedCollectionViewTopConstraint: CGFloat = 167
Expand All @@ -31,6 +34,14 @@ class FeedViewController: UIViewController {
@IBOutlet weak var feedCollectionView: UICollectionView!
@IBOutlet weak var statusBarView: UIView!
@IBOutlet weak var floatingTopButton: UIButton!
private lazy var loadingView = AnimationView(name: "loading").then {
$0.contentMode = .scaleAspectFill
$0.loopMode = .loop
$0.play()
$0.isHidden = true
$0.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
$0.center = CGPoint(x: self.view.center.x, y: self.view.center.y)
}

private var feedUserCountLabel = UILabel().then {
$0.font = UIFont.gmarketFont(weight: .medium, size: 18)
Expand Down Expand Up @@ -64,10 +75,10 @@ class FeedViewController: UIViewController {
initAtrributes()
setupAutoLayout()
addObserver()
getFeeds(page: currentPage)
}

override func viewWillAppear(_ animated: Bool) {
getFeeds(page: currentPage)
self.navigationController?.isNavigationBarHidden = true
}

Expand Down Expand Up @@ -105,6 +116,8 @@ class FeedViewController: UIViewController {
}

private func initAtrributes() {
view.addSubview(loadingView)

feedCollectionView.backgroundView = UIView()
feedCollectionView.backgroundView?.addSubview(headerView)

Expand Down Expand Up @@ -140,8 +153,11 @@ class FeedViewController: UIViewController {
if currentPage == 0 {
allFeeds = feed
} else {
allFeeds.feeds.append(contentsOf: feed.feeds)
if cachedPages.filter({ $0 == currentPage }).count == 0 {
allFeeds.feeds.append(contentsOf: feed.feeds)
}
}

feedCollectionView.reloadData()

if let userCount = feed.userCount {
Expand Down Expand Up @@ -310,13 +326,19 @@ extension FeedViewController: HeaderViewDelegate {

extension FeedViewController {
@objc func getFeeds(page: Int) {
loadingView.isHidden = true
FeedAPI.shared.getFeed(page: currentPage) { response in
switch response {
case .success(let data):
if let data = data as? FeedResponse {
self.updateData(feed: data)
self.feedCollectionView.reloadData()
self.refreshControl.endRefreshing()
self.cachedPages.append(page)

DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.loadingView.isHidden = false
}
}
case .requestErr(let message):
print("requestErr", message)
Expand Down

0 comments on commit e32da8a

Please sign in to comment.