Skip to content

Commit

Permalink
Merge pull request #164 from lee-yeonwoo/#163-보관함편집취소에러해결
Browse files Browse the repository at this point in the history
[Fix] #163 -  editmode 종료시 reload() 할 수 있도록 수정
  • Loading branch information
lee-yeonwoo authored Jun 2, 2023
2 parents 3d28027 + 6199309 commit 3452f4e
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 67 deletions.
4 changes: 3 additions & 1 deletion Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ enum ImageLiterals {
static var icLogoCircle: UIImage { .load(named: "ic_logo_circle") }
static var icMore: UIImage { .load(named: "ic_more") }
static var icPlus: UIImage { .load(named: "ic_plus") }

static var icCheck: UIImage { .load(named: "ic_check") }
static var icCheckFill: UIImage { .load(named: "ic_check_fill") }

// img
static var imgBackground: UIImage { .load(named: "img_background") }
static var imgLogo: UIImage { .load(named: "img_logo") }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 9499.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group 9499@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group 9499@3x.png",
"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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Group 9515.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group 9515@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group 9515@3x.png",
"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.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ extension CourseStorageVC {
private func bindUI() {
viewPager.$selectedTabIndex.sink { [weak self] selectedTabIndex in
guard let self = self else { return }
print(selectedTabIndex)
self.deleteCourseButton.isHidden = (selectedTabIndex != 0)
}.store(in: cancelBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ final class CourseListCVC: UICollectionViewCell {
$0.backgroundColor = .w1
}

private let selectIndicatorButton = UIButton(type: .custom).then {
$0.setImage(ImageLiterals.icCheckFill, for: .selected)
$0.setImage(ImageLiterals.icCheck, for: .normal)
$0.isSelected = false
$0.isHidden = true
}

// MARK: - initialization

override init(frame: CGRect) {
super.init(frame: frame)
self.setUI()
self.setLayout()
self.setAddTarget()

}

required init?(coder: NSCoder) {
Expand All @@ -97,28 +105,30 @@ extension CourseListCVC {
likeButton.addTarget(self, action: #selector(likeButtonDidTap), for: .touchUpInside)
}

func setData(imageURL: String, title: String, location: String?, didLike: Bool?, indexPath: Int? = nil) {
func setData(imageURL: String, title: String, location: String?, didLike: Bool?, indexPath: Int? = nil, isEditMode: Bool = false) {
self.courseImageView.setImage(with: imageURL)
self.titleLabel.text = title
self.indexPath = indexPath

if let location = location {
self.locationLabel.text = location
}

if let didLike = didLike {
self.likeButton.isSelected = didLike
}
self.selectIndicatorButton.isHidden = !isEditMode
}

func selectCell(didSelect: Bool) {
if didSelect {
courseImageView.layer.borderColor = UIColor.m1.cgColor
courseImageView.layer.borderWidth = 2
imageCoverView.isHidden = false
selectIndicatorButton.isSelected = true
} else {
courseImageView.layer.borderColor = UIColor.clear.cgColor
imageCoverView.isHidden = true
selectIndicatorButton.isSelected = false

}
}
}
Expand All @@ -143,7 +153,7 @@ extension CourseListCVC {
}

private func setLayout() {
self.contentView.addSubviews(courseImageView, imageCoverView, labelStackView, likeButton)
self.contentView.addSubviews(courseImageView, imageCoverView, labelStackView, likeButton, selectIndicatorButton)

courseImageView.snp.makeConstraints { make in
make.leading.top.trailing.equalToSuperview()
Expand All @@ -162,6 +172,13 @@ extension CourseListCVC {
make.height.equalTo(20)
}

selectIndicatorButton.snp.makeConstraints { make in
make.top.leading.equalToSuperview().inset(8)
make.leading.equalToSuperview().offset(8)
make.width.equalTo(20)
make.height.equalTo(20)
}

labelStackView.snp.makeConstraints { make in
make.top.equalTo(courseImageView.snp.bottom).offset(4)
make.leading.equalToSuperview()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class PrivateCourseListView: UIView {
isEditMode ? startEditMode() : finishEditMode()
}
}

final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16)
final let itemSpacing: CGFloat = 10
final let lineSpacing: CGFloat = 20
Expand Down Expand Up @@ -119,8 +119,8 @@ extension PrivateCourseListView {
extension PrivateCourseListView {
@objc func editButtonDidTap() {
isEditMode.toggle()

self.delegate?.courseListEditButtonTapped()
self.courseListCollectionView.reloadData()
}

private func startEditMode() {
Expand Down Expand Up @@ -203,7 +203,7 @@ extension PrivateCourseListView: UICollectionViewDelegate, UICollectionViewDataS

let model = courseList[indexPath.item]
let cellTitle = "\(model.departure.region) \(model.departure.city)"
cell.setData(imageURL: model.image, title: cellTitle, location: nil, didLike: nil)
cell.setData(imageURL: model.image, title: cellTitle, location: nil, didLike: nil, isEditMode: isEditMode)
return cell
}

Expand All @@ -219,16 +219,11 @@ extension PrivateCourseListView: UICollectionViewDelegate, UICollectionViewDataS
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
guard let selectedCells = collectionView.indexPathsForSelectedItems else {
return
}

guard let cell = collectionView.cellForItem(at: indexPath) as? CourseListCVC else { return }

if isEditMode {
cell.selectCell(didSelect: false)
}

delegate?.selectCellDidTapped()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ final class UploadedCourseInfoVC: UIViewController {

private var uploadedCourseList = [PublicCourse]()

var isEditMode: Bool = false
var isEditMode: Bool = false {
didSet {
isEditMode ? startEditMode() : finishEditMode()
}
}

private var deleteToCourseId = [Int]()

Expand Down Expand Up @@ -104,7 +108,7 @@ final class UploadedCourseInfoVC: UIViewController {
extension UploadedCourseInfoVC {
private func setData(courseList: [PublicCourse]) {
self.uploadedCourseList = courseList
UploadedCourseInfoCollectionView.reloadData()
self.UploadedCourseInfoCollectionView.reloadData()
self.emptyView.isHidden = !courseList.isEmpty
self.deleteCourseButton.isHidden = true
self.beforeEditTopView.isHidden = courseList.isEmpty
Expand All @@ -127,10 +131,30 @@ extension UploadedCourseInfoVC {
self.editButton.addTarget(self, action: #selector(editButtonDidTap), for: .touchUpInside)

}
private func startEditMode() {
self.totalNumOfRecordlabel.text = "코스 선택"
self.editButton.setTitle("취소", for: .normal)
self.deleteCourseButton.isHidden = false
}

private func finishEditMode() {
self.totalNumOfRecordlabel.text = "총 코스 \(self.uploadedCourseList.count)"
self.editButton.setTitle("편집", for: .normal)
self.deleteCourseButton.isEnabled = false
self.deleteCourseButton.setTitle(title: "삭제하기")
self.deleteCourseButton.isHidden = true
self.deselectAllItems()
}

private func deselectAllItems() {
guard let selectedItems = UploadedCourseInfoCollectionView.indexPathsForSelectedItems else { return }
for indexPath in selectedItems { UploadedCourseInfoCollectionView.deselectItem(at: indexPath, animated: false) }
}

private func setDeleteButton() {
deleteCourseButton.addTarget(self, action: #selector(deleteCourseButtonDidTap), for: .touchUpInside)
}

}

// MARK: - @objc Function
Expand All @@ -155,22 +179,8 @@ extension UploadedCourseInfoVC {
}

@objc func editButtonDidTap() {
if isEditMode {
self.totalNumOfRecordlabel.text = "총 코스 \(self.uploadedCourseList.count)"
self.editButton.setTitle("편집", for: .normal)
self.deleteCourseButton.isEnabled = false
self.deleteCourseButton.setTitle(title: "삭제하기")
self.courseListCollectionView.reloadData()
isEditMode = false
self.deleteCourseButton.isHidden = true
} else {
self.totalNumOfRecordlabel.text = "기록 선택"
self.editButton.setTitle("취소", for: .normal)

self.deleteCourseButton.isHidden = false
self.courseListCollectionView.reloadData()
isEditMode = true
}
isEditMode.toggle()
self.UploadedCourseInfoCollectionView.reloadData()
}
}

Expand Down Expand Up @@ -257,7 +267,7 @@ extension UploadedCourseInfoVC: UICollectionViewDelegateFlowLayout {

// MARK: - UICollectionViewDataSource

extension UploadedCourseInfoVC: UICollectionViewDataSource {
extension UploadedCourseInfoVC: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return uploadedCourseList.count
}
Expand All @@ -266,65 +276,53 @@ extension UploadedCourseInfoVC: UICollectionViewDataSource {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseListCVC.className, for: indexPath)
as? CourseListCVC else { return UICollectionViewCell() }
cell.setCellType(type: .title)
let model = uploadedCourseList[indexPath.item]
let cellTitle = "\(model.departure.region) \(model.departure.city)"
cell.setData(imageURL: model.image, title: cellTitle, location: nil, didLike: nil)

if isEditMode {
// selectCell 표시
if let selectedCells = collectionView.indexPathsForSelectedItems, selectedCells.contains(indexPath) {
cell.selectCell(didSelect: false)
} else { cell.selectCell(didSelect: true)
}
if let selectedCells = collectionView.indexPathsForSelectedItems, selectedCells.contains(indexPath) {
cell.selectCell(didSelect: true)
} else {
cell.setCellType(type: .title)
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CourseListCVC.className,
for: indexPath)
as? CourseListCVC else { return UICollectionViewCell() }
cell.setCellType(type: .title)
cell.selectCell(didSelect: false)
}

let model = uploadedCourseList[indexPath.item]
let cellTitle = "\(model.departure.region) \(model.departure.city)"
cell.setData(imageURL: model.image, title: cellTitle, location: nil, didLike: nil, isEditMode: isEditMode)
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard collectionView.cellForItem(at: indexPath) is CourseListCVC else { return }
guard let selectedCells = collectionView.indexPathsForSelectedItems else { return }
guard let cell = collectionView.cellForItem(at: indexPath) as? CourseListCVC else { return }
let publicCourseModel = uploadedCourseList[indexPath.item]
if isEditMode {
self.deleteCourseButton.isEnabled = true
let countSelectCells = selectedCells.count
self.deleteCourseButton.setTitle(title: "삭제하기(\(countSelectCells))")
cell.selectCell(didSelect: true)
guard let selectedCells = collectionView.indexPathsForSelectedItems else { return }

let countSelectCells = selectedCells.count

if isEditMode {
self.deleteCourseButton.setTitle(title: "삭제하기(\(countSelectCells))")
}
self.deleteCourseButton.setEnabled(countSelectCells != 0)
} else {
collectionView.deselectItem(at: indexPath, animated: true)
self.deleteCourseButton.setTitle(title: "삭제하기")
self.deleteCourseButton.setEnabled(true)
let courseDetailVC = CourseDetailVC()
courseDetailVC.setCourseId(courseId: publicCourseModel.courseId, publicCourseId: publicCourseModel.id)
courseDetailVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(courseDetailVC, animated: true)
cell.selectCell(didSelect: false)
}
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
guard collectionView.cellForItem(at: indexPath) is CourseListCVC else { return }
guard let selectedCells = collectionView.indexPathsForSelectedItems else {
self.deleteCourseButton.isEnabled = false
self.deleteCourseButton.setTitle(title: "삭제하기")
return }
guard let selectedCells = collectionView.indexPathsForSelectedItems else { return }
guard let cell = collectionView.cellForItem(at: indexPath) as? CourseListCVC else { return }
cell.selectCell(didSelect: false)
if isEditMode {
self.deleteCourseButton.isEnabled = true
let countSelectCells = selectedCells.count
self.deleteCourseButton.setTitle(title: "삭제하기(\(countSelectCells))")
cell.selectCell(didSelect: false)
} else {
collectionView.deselectItem(at: indexPath, animated: true)
self.deleteCourseButton.setTitle(title: "삭제하기")
cell.selectCell(didSelect: false)
}

let countSelectCells = selectedCells.count
if isEditMode {
self.deleteCourseButton.setTitle(title: "삭제하기(\(countSelectCells))")
}
self.deleteCourseButton.setEnabled(countSelectCells != 0)
}
}

Expand Down Expand Up @@ -369,6 +367,7 @@ extension UploadedCourseInfoVC {
let status = result.statusCode
if 200..<300 ~= status {
print("삭제 성공")
self.isEditMode.toggle()
self.getUploadedCourseInfo()
}
if status >= 400 {
Expand Down

0 comments on commit 3452f4e

Please sign in to comment.