Skip to content

Commit

Permalink
Merge pull request #353 from PLUB2022/feat/Mainpage-351/Proof
Browse files Browse the repository at this point in the history
[FEAT] 메인페이지 투두리스트 인증 API 연동
  • Loading branch information
dlrjswns authored May 7, 2023
2 parents 24461ad + fa2f217 commit 575c7cb
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 36 deletions.
4 changes: 4 additions & 0 deletions PLUB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
70C9CC9F2A03FE8200BEB5F2 /* CompleteTodolistResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70C9CC9E2A03FE8200BEB5F2 /* CompleteTodolistResponse.swift */; };
70C9CCA42A03FFC000BEB5F2 /* ProofTodolistRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70C9CCA32A03FFC000BEB5F2 /* ProofTodolistRequest.swift */; };
70C9CCA62A05044400BEB5F2 /* LikeTodolistResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70C9CCA52A05044400BEB5F2 /* LikeTodolistResponse.swift */; };
70C9CCB82A07865700BEB5F2 /* Ex+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70C9CCB72A07865700BEB5F2 /* Ex+String.swift */; };
70CF3330299793220077FF47 /* RegisterInterestRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70CF332F299793220077FF47 /* RegisterInterestRequest.swift */; };
70CF33322998EBC30077FF47 /* RecruitmentFilterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70CF33312998EBC30077FF47 /* RecruitmentFilterViewController.swift */; };
70CF3335299920CD0077FF47 /* RecruitmentFilterCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70CF3334299920CD0077FF47 /* RecruitmentFilterCollectionViewCell.swift */; };
Expand Down Expand Up @@ -516,6 +517,7 @@
70C9CC9E2A03FE8200BEB5F2 /* CompleteTodolistResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompleteTodolistResponse.swift; sourceTree = "<group>"; };
70C9CCA32A03FFC000BEB5F2 /* ProofTodolistRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofTodolistRequest.swift; sourceTree = "<group>"; };
70C9CCA52A05044400BEB5F2 /* LikeTodolistResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LikeTodolistResponse.swift; sourceTree = "<group>"; };
70C9CCB72A07865700BEB5F2 /* Ex+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Ex+String.swift"; sourceTree = "<group>"; };
70CF332F299793220077FF47 /* RegisterInterestRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterInterestRequest.swift; sourceTree = "<group>"; };
70CF33312998EBC30077FF47 /* RecruitmentFilterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitmentFilterViewController.swift; sourceTree = "<group>"; };
70CF3334299920CD0077FF47 /* RecruitmentFilterCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitmentFilterCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1344,6 +1346,7 @@
70727A2029BF8F2A003DE956 /* Ex+Date.swift */,
C307826729CF5D9700E1D44B /* Ex+UIImage.swift */,
C36F31C829E3119200AC2C8A /* Ex+Collection.swift */,
70C9CCB72A07865700BEB5F2 /* Ex+String.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2518,6 +2521,7 @@
C333EEB929F45A7E00B3F84E /* ExportViewController.swift in Sources */,
70F1DFEF297D9E1C00F9BC83 /* DetailRecruitmentViewModel.swift in Sources */,
BA8AA42A29863ABC004E9403 /* Interceptor.swift in Sources */,
70C9CCB82A07865700BEB5F2 /* Ex+String.swift in Sources */,
C307826829CF5D9700E1D44B /* Ex+UIImage.swift in Sources */,
70727A1F29BF7FC6003DE956 /* BoardSystemCollectionViewCell.swift in Sources */,
C333EEC129F48EF400B3F84E /* InquireMeetingMemberUseCase.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 658.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions PLUB/Configuration/Extensions/Ex+String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Ex + String.swift
// PLUB
//
// Created by 이건준 on 2023/05/07.
//

import UIKit

extension String {

/// 라벨 취소선을 설정하는 함수입니다.
func strikeThrough() -> NSAttributedString {
let attributeString = NSMutableAttributedString(string: self)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, attributeString.length))
return attributeString
}
}
2 changes: 1 addition & 1 deletion PLUB/Sources/Views/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ final class HomeViewController: BaseViewController {
.disposed(by: disposeBag)

viewModel.isBookmarked.emit(onNext: { isBookmarked in
print("해당 모집글을 북마크 \(isBookmarked)")
Log.debug("해당 모집글을 북마크 \(isBookmarked)")
})
.disposed(by: disposeBag)

Expand Down
4 changes: 2 additions & 2 deletions PLUB/Sources/Views/Home/MainPage/BoardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ final class BoardViewController: BaseViewController {

viewModel.isPinnedFeed
.drive(onNext: { isPinned in
print("고정 성공 !! \(isPinned)")
Log.debug("고정 성공 !! \(isPinned)")
})
.disposed(by: disposeBag)

viewModel.successDeleteFeed
.drive(onNext: { success in
print("해당 게시글 삭제 성공")
Log.debug("해당 게시글 삭제 성공")
})
.disposed(by: disposeBag)
}
Expand Down
30 changes: 21 additions & 9 deletions PLUB/Sources/Views/Home/MainPage/Cell/TodoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Then
protocol TodoCollectionViewCellDelegate: AnyObject {
func didTappedMoreButton()
func didTappedLikeButton(timelineID: Int)
func didTappedTodo(todoID: Int, isCompleted: Bool)
func didTappedTodo(todoID: Int, isCompleted: Bool, model: TodoAlertModel)
}

struct TodoCollectionViewCellModel {
Expand All @@ -26,6 +26,7 @@ struct TodoCollectionViewCellModel {
let isLike: Bool
let isAuthor: Bool
let checkTodoViewModels: [CheckTodoViewModel]
let nickname: String?

init(response: InquireAllTodoTimelineResponse) {
todoTimelineID = response.todoTimelineID
Expand All @@ -43,14 +44,15 @@ struct TodoCollectionViewCellModel {
isProof: $0.isProof
)
}
nickname = response.accountInfo?.nickname
}
}

final class TodoCollectionViewCell: UICollectionViewCell {

static let identifier = "TodoCollectionViewCell"
private let disposeBag = DisposeBag()
private var timelineID: Int?
private var model: TodoCollectionViewCellModel?
weak var delegate: TodoCollectionViewCellDelegate?

private var likeCount: Int = 0 {
Expand Down Expand Up @@ -145,16 +147,16 @@ final class TodoCollectionViewCell: UICollectionViewCell {

likeButton.buttonTapObservable
.subscribe(with: self) { owner, _ in
guard let timelineID = owner.timelineID else { return }
owner.delegate?.didTappedLikeButton(timelineID: timelineID)
guard let model = owner.model else { return }
owner.delegate?.didTappedLikeButton(timelineID: model.todoTimelineID)
owner.likeCount += 1
}
.disposed(by: disposeBag)

likeButton.buttonUnTapObservable
.subscribe(with: self) { owner, _ in
guard let timelineID = owner.timelineID else { return }
owner.delegate?.didTappedLikeButton(timelineID: timelineID)
guard let model = owner.model else { return }
owner.delegate?.didTappedLikeButton(timelineID: model.todoTimelineID)
owner.likeCount -= 1
}
.disposed(by: disposeBag)
Expand All @@ -163,7 +165,7 @@ final class TodoCollectionViewCell: UICollectionViewCell {
func configureUI(with model: TodoCollectionViewCellModel) {
guard let profileImageString = model.profileImageString,
let url = URL(string: profileImageString) else { return }
timelineID = model.todoTimelineID
self.model = model
profileImageView.kf.setImage(with: url, placeholder: UIImage(named: "userDefaultImage"))
likeCount = model.totalLikes
likeButton.isSelected = model.isLike
Expand All @@ -185,7 +187,17 @@ extension TodoCollectionViewCell {
}

extension TodoCollectionViewCell: CheckTodoViewDelegate {
func didTappedCheckboxButton(todoID: Int, isCompleted: Bool) {
delegate?.didTappedTodo(todoID: todoID, isCompleted: isCompleted)
func didTappedCheckboxButton(todoID: Int, isCompleted: Bool, todo: String) {
guard let model = model,
let name = model.nickname else { return }
delegate?.didTappedTodo(
todoID: todoID,
isCompleted: isCompleted,
model: .init(
profileImage: model.profileImageString ?? "",
date: model.date,
name: name,
content: todo)
)
}
}
20 changes: 16 additions & 4 deletions PLUB/Sources/Views/Home/MainPage/Component/CheckTodoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SnapKit
import Then

protocol CheckTodoViewDelegate: AnyObject {
func didTappedCheckboxButton(todoID: Int, isCompleted: Bool)
func didTappedCheckboxButton(todoID: Int, isCompleted: Bool, todo: String)
}

struct CheckTodoViewModel {
Expand All @@ -27,6 +27,17 @@ final class CheckTodoView: UIView {

weak var delegate: CheckTodoViewDelegate?
private var model: CheckTodoViewModel?
private var isChecked: Bool = false {
didSet {
if isChecked {
todoLabel.attributedText = todoLabel.text?.strikeThrough()
} else {
todoLabel.attributedText = NSAttributedString(string: todoLabel.text ?? "")
}
checkboxButton.isChecked = isChecked
}
}

private let disposeBag = DisposeBag()

private let checkboxButton = CheckBoxButton(type: .none)
Expand All @@ -48,10 +59,11 @@ final class CheckTodoView: UIView {

private func bind() {
checkboxButton.rx.isChecked
.subscribe(with: self) { owner, _ in
.subscribe(with: self) { owner, isChecked in
guard let model = owner.model else { return }
owner.isChecked = isChecked
if model.isAuthor && !model.isProof { // 내가 작성했고 인증되있지않은 투두만 완료/인증 가능
owner.delegate?.didTappedCheckboxButton(todoID: model.todoID, isCompleted: owner.checkboxButton.isChecked)
owner.delegate?.didTappedCheckboxButton(todoID: model.todoID, isCompleted: owner.checkboxButton.isChecked, todo: model.todo)
}
}
.disposed(by: disposeBag)
Expand All @@ -74,7 +86,7 @@ final class CheckTodoView: UIView {
func configureUI(with model: CheckTodoViewModel) {
self.model = model
todoLabel.text = model.todo
checkboxButton.isChecked = model.isChecked
self.isChecked = model.isChecked

// 해당 투두가 인증되었거나 작성자가 아니라면 -> 체크버튼 비활성화
checkboxButton.isEnabled = model.isProof || !model.isAuthor ? false : true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@

import UIKit

import Kingfisher
import RxSwift
import SnapKit
import Then

struct TodoAlertModel {
let profileImage: String
let date: String
let name: String
let content: String
}

protocol TodoAlertDelegate: AnyObject {
func whichProofImage(image: UIImage)
}

final class TodoAlertController: BaseViewController {

weak var delegate: TodoAlertDelegate?

private var proofImage: UIImage?

private let dimmedView = UIView().then {
$0.backgroundColor = .black.withAlphaComponent(0.45)
}
Expand Down Expand Up @@ -66,8 +82,8 @@ final class TodoAlertController: BaseViewController {
}

private let completedButton = UIButton(configuration: .plain()).then {
$0.configurationUpdateHandler = $0.configuration?.detailRecruitment(label: "완료!")
$0.isSelected = true
$0.configurationUpdateHandler = $0.configuration?.plubButton(label: "완료!")
$0.isEnabled = false
}

private let tapGesture = UITapGestureRecognizer(target: TodoAlertController.self, action: nil)
Expand Down Expand Up @@ -192,11 +208,29 @@ final class TodoAlertController: BaseViewController {
owner.present(bottomSheet, animated: false)
}
.disposed(by: disposeBag)

completedButton.rx.tap
.subscribe(with: self) { owner, _ in
guard let image = owner.proofImage else { return }
owner.delegate?.whichProofImage(image: image)
owner.dismiss(animated: false)
}
.disposed(by: disposeBag)
}

func configureUI(with model: TodoAlertModel) {
let url = URL(string: model.profileImage)
profileImageView.kf.setImage(with: url, placeholder: UIImage(named: "userDefaultImage"))
dateLabel.text = model.date
nameLabel.text = model.name
todoInfoView.configureUI(with: model.content)
}
}

extension TodoAlertController: PhotoBottomSheetDelegate {
func selectImage(image: UIImage) {
self.proofImage = image
todoAlertView.image = image
completedButton.isEnabled = true
}
}
14 changes: 8 additions & 6 deletions PLUB/Sources/Views/Home/MainPage/Component/TodoInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ import Then
final class TodoInfoView: UIView {

private let checkImageView = UIImageView().then {
$0.image = UIImage(named: "Check")
$0.backgroundColor = .main
$0.contentMode = .scaleAspectFit
$0.image = UIImage(named: "checkFilledMain")
$0.backgroundColor = .clear
$0.contentMode = .scaleAspectFill
$0.layer.masksToBounds = true
}

private let todoLabel = UILabel().then {
var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 1.25
$0.textColor = .deepGray
$0.font = .systemFont(ofSize: 14)
$0.attributedText = NSMutableAttributedString(string: "독후감 쓴 내용 팀원들이랑 공유하기", attributes: [NSAttributedString.Key.strikethroughStyle: NSUnderlineStyle.single.rawValue, NSAttributedString.Key.kern: -0.21, NSAttributedString.Key.paragraphStyle: paragraphStyle])
}

override init(frame: CGRect) {
Expand All @@ -48,4 +46,8 @@ final class TodoInfoView: UIView {
$0.trailing.lessThanOrEqualToSuperview()
}
}

func configureUI(with model: String) {
todoLabel.attributedText = model.strikeThrough()
}
}
20 changes: 18 additions & 2 deletions PLUB/Sources/Views/Home/MainPage/TodolistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ final class TodolistViewController: BaseViewController {

viewModel.successCompleteTodolist
.emit(onNext: { success in
print("성공했니 \(success)")
Log.debug("투두완료성공 \(success)")
})
.disposed(by: disposeBag)

viewModel.successProofTodolist
.emit(with: self) { owner, success in
Log.debug("투두인증성공 \(success)")
owner.viewModel.selectPlubbingID.onNext(plubbingID)
}
.disposed(by: disposeBag)

}
}
Expand Down Expand Up @@ -157,12 +164,15 @@ extension TodolistViewController: UICollectionViewDelegateFlowLayout {
}

extension TodolistViewController: TodoCollectionViewCellDelegate {
func didTappedTodo(todoID: Int, isCompleted: Bool) {
func didTappedTodo(todoID: Int, isCompleted: Bool, model: TodoAlertModel) {
viewModel.selectTodolistID.onNext(todoID)
viewModel.selectComplete.onNext(isCompleted)

if isCompleted {
let alert = TodoAlertController()
alert.modalPresentationStyle = .overFullScreen
alert.delegate = self
alert.configureUI(with: model)
present(alert, animated: false)
}
}
Expand All @@ -177,3 +187,9 @@ extension TodolistViewController: TodoCollectionViewCellDelegate {
present(bottomSheet, animated: false)
}
}

extension TodolistViewController: TodoAlertDelegate {
func whichProofImage(image: UIImage) {
viewModel.whichProofImage.onNext(image)
}
}
Loading

0 comments on commit 575c7cb

Please sign in to comment.