Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/#140
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandrarla committed Sep 9, 2024
2 parents 8e6af69 + ef41b8f commit 39ef32f
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 223 deletions.
10 changes: 6 additions & 4 deletions Common/Sources/Components/MediumButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum MediumState {

public class MediumButton: UIButton {

public var mediumState: MediumState = .inactive {
public var mediumState: MediumState = .active {
didSet {
mediumButtonAppearance()
}
Expand All @@ -33,11 +33,13 @@ public class MediumButton: UIButton {
private func mediumButtonAppearance() {
switch mediumState {
case .active:
backgroundColor = CommonAsset.recordyWhite.color
setTitleColor(CommonAsset.recordyGrey09.color, for: .normal)
case .inactive:
backgroundColor = CommonAsset.recordyGrey08.color
setTitleColor(CommonAsset.recordyGrey01.color, for: .normal)
setTitle("팔로잉", for: .normal)
case .inactive:
backgroundColor = CommonAsset.recordyWhite.color
setTitleColor(CommonAsset.recordyGrey09.color, for: .normal)
setTitle("팔로우", for: .normal)
}
}
}
18 changes: 0 additions & 18 deletions Core/Sources/Model/FollowerModel.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Core/Sources/Network/API/APITarget+Users.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ extension APITarget.Users: TargetType {
case .getfollowList(let getFollowListRequest):
return .requestParameters(
parameters: [
"cursorId": getFollowListRequest.cursorId,
// "cursorId": getFollowListRequest.cursorId,
"size": getFollowListRequest.size
],
encoding: URLEncoding.queryString
)
case .getfollowerList(let getFollowerListRequest):
return .requestParameters(
parameters: [
"cursorId": getFollowerListRequest.cursorId,
// "cursorId": getFollowerListRequest.cursorId,
"size": getFollowerListRequest.size
],
encoding: URLEncoding.queryString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import Foundation
extension DTO {
public struct GetFollowListRequest: BaseRequest {
/// 페이지네이션 커서 ID?
let cursorId: Int
// let cursorId: Int?
/// 가져올 데이터 갯수
let size: Int

public init(
cursorId: Int,
// cursorId: Int?,
size: Int
) {
self.cursorId = cursorId
// self.cursorId = cursorId
self.size = size
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Foundation
extension DTO {
public struct GetFollowerListRequest: BaseRequest {
/// 페이지네이션 커서 ID?
let cursorId: Int
let cursorId: Int?
/// 가져올 데이터 갯수
let size: Int

public init(
cursorId: Int,
cursorId: Int?,
size: Int
) {
self.cursorId = cursorId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import Foundation
extension DTO {
public struct GetFollowListResponse: BaseResponse {
/// 다음 커서
public let nextCursor: Int
public let nextCursor: Int?
/// 다음 페이지 여부
public let hasNext: Bool
/// 다음 커서
public let content: [Content]

public init(
nextCursor: Int,
nextCursor: Int?,
hasNext: Bool,
content: [Content]
) {
Expand Down
175 changes: 61 additions & 114 deletions Presentation/Sources/MyProfile/Controller/FollowViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ import Common
enum FollowType {
case follower
case following

var title: String {
switch self {
case .follower:
return "팔로워"
case .following:
return "팔로우"
}
}
}

public class FollowViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
public class FollowViewController: UIViewController {

let followType: FollowType
private let followType: FollowType
private let viewModel: FollowViewModel
private let tableView = UITableView()
private let tableView = UITableView().then {
$0.backgroundColor = .black
$0.separatorStyle = .none
}
private let emptyView = FollowerEmptyView()
let settingButton = UIButton()


init(followType: FollowType) {
self.followType = followType
self.viewModel = FollowViewModel(followType: followType)
Expand All @@ -33,153 +44,89 @@ public class FollowViewController: UIViewController, UITableViewDataSource, UITa
setStyle()
setUI()
setAutoLayout()
setTableView()
bindViewModel()
viewModel.fetchUsers()
bind()

self.navigationController?.navigationBar.topItem?.title = ""
}

private func setStyle() {
view.backgroundColor = .black
view.do {
$0.backgroundColor = .black
}

tableView.do {
$0.dataSource = self
$0.delegate = self
$0.register(FollowerCell.self, forCellReuseIdentifier: "FollowerCell")
}

self.title = followType.title
}

private func setUI() {
view.addSubview(emptyView)
view.addSubview(tableView)
view.do {
$0.addSubview(tableView)
$0.addSubview(emptyView)
}
}

private func setAutoLayout() {
emptyView.snp.makeConstraints {
$0.edges.equalTo(view.safeAreaLayoutGuide)
}

tableView.snp.makeConstraints {
$0.edges.equalTo(view.safeAreaLayoutGuide)
}
}

private func setTableView() {
tableView.dataSource = self
tableView.delegate = self
tableView.backgroundColor = .black
tableView.register(FollowerCell.self, forCellReuseIdentifier: "FollowerCell")
tableView.separatorStyle = .none
}

public func bindViewModel() {
viewModel.followers.bind { [weak self] _ in
private func bind() {
viewModel.followersDidChange = { [weak self] followers in
guard let self = self else { return }
self.tableView.reloadData()
self.tableView.isHidden = viewModel.followers.value.isEmpty
}

viewModel.isEmptyDidChange = { [weak self] isEmpty in
guard let self = self else { return }
self.tableView.isHidden = isEmpty
self.emptyView.isHidden = !isEmpty
}
}
}

extension FollowViewController: UITableViewDataSource, UITableViewDelegate {

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.followers.value.count
return viewModel.followers.count
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(
withIdentifier: "FollowerCell",
for: indexPath
) as! FollowerCell
let follower = viewModel.followers.value[indexPath.row]

let follower = viewModel.followers[indexPath.row]
cell.configure(with: follower)

cell.followButton.do {
if indexPath.row == 0 && followType == .following {
$0.isHidden = true
} else {
$0.isHidden = false
cell.updateFollowButton(isFollowed: follower.isFollowing)
}
}

cell.followButtonEvent = { [weak self] in
guard let self = self else { return }
postFollowRequest(index: indexPath.row)
cell.updateFollowButton(isFollowed: follower.isFollowing)
self.viewModel.postFollowRequest(at: indexPath.row)
}
return cell
}

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let userVC = OtherUserProfileViewController(id: viewModel.followers.value[indexPath.row].id)
let userVC = OtherUserProfileViewController(id: viewModel.followers[indexPath.row].id)
self.navigationController?.pushViewController(userVC, animated: true)
}

func postFollowRequest(index: Int) {
self.viewModel.followers.value[index].isFollowing.toggle()
let apiProvider = APIProvider<APITarget.Users>()
let request = DTO.FollowRequest(followingId: viewModel.followers.value[index].id)
apiProvider.justRequest(.follow(request)) { result in
switch result {
case .success(let success):
print(success)
case .failure(let failure):
print(failure)
}
}
}
}

public class FollowerCell: UITableViewCell {
let profileImageView = UIImageView()
let usernameLabel = UILabel()
let followButton = MediumButton()

var followButtonEvent: (() -> Void)?

public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

contentView.addSubview(profileImageView)
contentView.addSubview(usernameLabel)
contentView.addSubview(followButton)

setStyle()
setAutoLayout()
followButton.addTarget(self, action: #selector(followButtonTapped), for: .touchUpInside)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setStyle() {
profileImageView.cornerRadius(10)
usernameLabel.font = RecordyFont.body2Bold.font
usernameLabel.textColor = CommonAsset.recordyGrey01.color
contentView.backgroundColor = .black
}

private func setAutoLayout() {
profileImageView.snp.makeConstraints {
$0.top.equalTo(contentView.snp.top).offset(10)
$0.leading.equalTo(contentView.snp.leading).offset(20)
$0.centerY.equalTo(contentView.snp.centerY)
$0.width.equalTo(54)
$0.height.equalTo(54)
}

usernameLabel.snp.makeConstraints {
$0.leading.equalTo(profileImageView.snp.trailing).offset(20)
$0.centerY.equalTo(contentView.snp.centerY)
}

followButton.snp.makeConstraints {
$0.trailing.equalTo(contentView.snp.trailing).offset(-20)
$0.centerY.equalTo(contentView.snp.centerY)
$0.width.equalTo(76.adaptiveWidth)
$0.height.equalTo(36.adaptiveHeight)
}
}

@objc private func followButtonTapped() {
self.followButtonEvent?()
}

public func updateFollowButton(isFollowed: Bool) {
followButton.mediumState = isFollowed ? .active : .inactive
followButton.setTitle(isFollowed ? "팔로우" : "팔로잉", for: .normal)
}

func configure(with follower: Follower) {
let url = URL(string: follower.profileImage)
profileImageView.kf.setImage(with: url)
usernameLabel.text = follower.username
if follower.username == "유영" {
followButton.isHidden = true
} else {
updateFollowButton(isFollowed: follower.isFollowing)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public class MyRecordViewController: UIViewController {
$0.leading.trailing.bottom.equalToSuperview()
}
}
@objc private func didTapRecordButton() {

}

private func bindViewModel() {
viewModel.isEmpty.bind { [weak self] isEmpty in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ProfileViewController: UIViewController {
getMyRecordList()
getUserProfile()
setObserver()
self.title = "프로필"
}

public override func viewWillDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -82,7 +83,6 @@ public class ProfileViewController: UIViewController {
}

func setStyle() {
self.title = "프로필"
let rightButton = UIButton(type: .system)
rightButton.setImage(CommonAsset.settingIcon.image, for: .normal)
rightButton.addTarget(
Expand Down Expand Up @@ -191,7 +191,7 @@ public class ProfileViewController: UIViewController {
let url = URL(string: user.profileImage)!
self.profileInfoView.profileImage.kf.setImage(with: url)
}

func getUserProfile() {
let apiProvider = APIProvider<APITarget.Users>()
let userId = UserDefaults.standard.integer(forKey: "userId")
Expand Down
Loading

0 comments on commit 39ef32f

Please sign in to comment.