Skip to content

Commit

Permalink
Merge pull request #145 from TeamBeMe/feature/#140
Browse files Browse the repository at this point in the history
Feature/#140
  • Loading branch information
sery270 authored Jan 15, 2021
2 parents 2cf9327 + a2f8e61 commit b578179
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 101 deletions.
4 changes: 2 additions & 2 deletions BeMe/BeMe/APIService/MyPage/MyPageAnswerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct MyPageAnswerService {
// getMyAnswer - overLoading Method : 쿼리 개수에 따라서 매개변수 개수가 바뀜
func getMyAnswer(availability: String?, category: Int?, page: Int, query: String?, completion : @escaping (NetworkResult<Any>) -> (Void) ){

_ = category == nil ? "" : String(category!)
let category = category == nil ? "" : String(category!)
let availability = availability == nil ? "" : String(availability!)
let query = query == nil ? "" : String(query!)

Expand All @@ -23,7 +23,7 @@ struct MyPageAnswerService {

let params: Parameters = [
"public": "\(availability)",
"availability": "\(availability)",
"category": "\(category)",
"page": "\(page)",
"query": "\(query)"
]
Expand Down
4 changes: 2 additions & 2 deletions BeMe/BeMe/APIService/MyPage/MyPageScrapService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct MyPageScrapService {
// getMyAnswer - overLoading Method : 쿼리 개수에 따라서 매개변수 개수가 바뀜
func getMyScrap(availability: String?, category: Int?, query: String?, page: Int, completion : @escaping (NetworkResult<Any>) -> (Void)){

_ = category == nil ? "" : String(category!)
let category = category == nil ? "" : String(category!)
let availability = availability == nil ? "" : String(availability!)
let query = query == nil ? "" : String(query!)

Expand All @@ -23,7 +23,7 @@ struct MyPageScrapService {

let params: Parameters = [
"public": "\(availability)",
"availability": "\(availability)",
"category": "\(category)",
"page": "\(page)",
"query": "\(query)"
]
Expand Down
26 changes: 21 additions & 5 deletions BeMe/BeMe/CustomActionSheet/Cell/FilterCVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class FilterCVC: UICollectionViewCell {
@IBOutlet weak var categoryButton: UIButton!
@IBAction func categoryButtonTapped(_ sender: UIButton) {
print(category)
filterCVCDelegate?.setSelectedCategory(index: indexPath)
// filterCVCDelegate?.setSelectedCategory(index: indexPath)
}

static let identifier: String = "FilterCVC"
var category: ExploreCategory?
var indexPath = -1
var filterCVCDelegate: FilterCVCDelegate?
// var filterCVCDelegate: FilterCVCDelegate?


override var isSelected: Bool {
Expand Down Expand Up @@ -57,6 +57,22 @@ class FilterCVC: UICollectionViewCell {
}

}

func setButton(selected: Bool) {
if !selected {
print(category)

categoryButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)
categoryButton.backgroundColor = UIColor.white
categoryButton.setTitleColor(.slateGrey, for: .normal)
} else {
categoryButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)
categoryButton.backgroundColor = UIColor.black
categoryButton.setTitleColor(.white, for: .normal)
}

}

func setButton(text: String) {
categoryButton.setTitle(text, for: .normal)
categoryButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)
Expand All @@ -65,6 +81,6 @@ class FilterCVC: UICollectionViewCell {
}
}

protocol FilterCVCDelegate {
func setSelectedCategory(index: Int)
}
//protocol FilterCVCDelegate {
// func setSelectedCategory(index: Int)
//}
190 changes: 114 additions & 76 deletions BeMe/BeMe/CustomActionSheet/VC/CustomActionSheetFilterVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,108 +18,133 @@ class CustomActionSheetFilterVC: UIViewController {
@IBOutlet weak var categoryLabel: UILabel!
// 서버통신을 통해 받아오는 값
var categoryArray: [ExploreCategory] = []
// all, public, unpublic
var availablityArray: [Bool] = [false, false, false]
private var filterCVCDelegate: FilterCVCDelegate?
// private var filterCVCDelegate: FilterCVCDelegate?
var fromServer = true
var categorySelected: Int = 0
private var selectedAvailablity: String = "all"

private var selectedCategory: Int?
= nil

private var selectedAvailablity: String? = nil

override func viewDidLoad() {
super.viewDidLoad()
setLabel()
setButton(view: allButton, isSelected: false)
setButton(view: publicButton, isSelected: false)
setButton(view: unpublicButton, isSelected: false)


categoryCollectionView.showsHorizontalScrollIndicator = false
categoryCollectionView.delegate = self
categoryCollectionView.dataSource = self

selectedAvailablity = "all"
allButton.backgroundColor = .black
allButton.setTitleColor(.white, for: .normal)
allButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)


// Do any additional setup after loading the view.

availablityButtonSet(availablity: selectedAvailablity)
}

override func viewWillAppear(_ animated: Bool) {

// getSelectedFilterInfo()
setCategoryData()
selectedAvailablity = MypageVC.selectedAvailablity
selectedCategory = MypageVC.selectedCategory
availablityButtonSet(availablity: selectedAvailablity)
}


@IBAction func dismissButtonTapped(_ sender: UIButton) {
NotificationCenter.default.post(name: .init("categoryClose"), object: nil)
self.dismiss(animated: true, completion: nil)
}

@IBAction func allButtonTapped(_ sender: UIButton) {
selectedAvailablity = "all"
allButton.backgroundColor = .black
allButton.setTitleColor(.white, for: .normal)
allButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)
availablityButtonSet(availablity: selectedAvailablity)
}

@IBAction func publicButtonTapped(_ sender: UIButton) {
selectedAvailablity = "public"
allButton.backgroundColor = .white
allButton.setTitleColor(.slateGrey, for: .normal)
allButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .black
publicButton.setTitleColor(.white, for: .normal)
publicButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)



unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

availablityButtonSet(availablity: selectedAvailablity)
}
@IBAction func unpublicButtonTapped(_ sender: UIButton) {

selectedAvailablity = "unpublic"
allButton.backgroundColor = .white
allButton.setTitleColor(.slateGrey, for: .normal)
allButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)


unpublicButton.backgroundColor = .black
unpublicButton.setTitleColor(.white, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

availablityButtonSet(availablity: selectedAvailablity)
}

private func selectPrivate(_ sender: UIButton) {


}

@IBAction func applyButtonTapped(_ sender: Any) {

NotificationCenter.default.post(name: .init("categoryClose"), object: nil, userInfo: ["categoryId": categorySelected+1, "selectedAv": selectedAvailablity])
NotificationCenter.default.post(name: .init("categoryClose"), object: nil, userInfo: ["categoryId": selectedCategory , "selectedAv": selectedAvailablity ?? "all"])
self.dismiss(animated: true, completion: nil)

}

// @objc func getSelectedFilterInfo(_ notification: Notification) {
// guard let userInfo = notification.userInfo as? [String: Any] else { return }
// guard let categoryId = userInfo["categoryId"] as? Int else { return }
// guard let selectedAv = userInfo["selectedAv"] as? String else { return }
//
// self.selectedAvailablity = selectedAv
// self.selectedCategory = categoryId
//
// }
// func categoryButtonSet(category: Int){
// <#function body#>
// }
func availablityButtonSet(availablity: String?){
switch availablity {
case "all":
allButton.backgroundColor = .black
allButton.setTitleColor(.white, for: .normal)
allButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

case "public":
allButton.backgroundColor = .white
allButton.setTitleColor(.slateGrey, for: .normal)
allButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .black
publicButton.setTitleColor(.white, for: .normal)
publicButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)



unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)
case "unpublic":
allButton.backgroundColor = .white
allButton.setTitleColor(.slateGrey, for: .normal)
allButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)


unpublicButton.backgroundColor = .black
unpublicButton.setTitleColor(.white, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

default:
allButton.backgroundColor = .black
allButton.setTitleColor(.white, for: .normal)
allButton.setBorderWithRadius(borderColor: .black, borderWidth: 1, cornerRadius: 4)

publicButton.backgroundColor = .white
publicButton.setTitleColor(.slateGrey, for: .normal)
publicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)

unpublicButton.backgroundColor = .white
unpublicButton.setTitleColor(.slateGrey, for: .normal)
unpublicButton.setBorderWithRadius(borderColor: .veryLightPink, borderWidth: 1, cornerRadius: 4)
}
}

func setLabel() {
Expand All @@ -146,7 +171,7 @@ class CustomActionSheetFilterVC: UIViewController {

extension CustomActionSheetFilterVC: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
categorySelected = indexPath.item
selectedCategory = indexPath.item

}
}
Expand All @@ -163,9 +188,22 @@ extension CustomActionSheetFilterVC: UICollectionViewDataSource {
for: indexPath) as? FilterCVC else {
return UICollectionViewCell()}
cell.indexPath = indexPath.row

cell.category = self.categoryArray[indexPath.item]
cell.filterCVCDelegate = self

cell.setButton(text: categoryArray[indexPath.item].name)

// if selectedCategory != nil {
// if self.categoryArray[indexPath.item].id == selectedCategory!+1 {
// cell.setButton(selected: true)
// }
// } else {
//
// }


// cell.filterCVCDelegate = self


return cell

Expand All @@ -181,7 +219,7 @@ extension CustomActionSheetFilterVC: UICollectionViewDataSource {
}

if cell.isSelected {
categorySelected = 0
selectedCategory = 0
collectionView.deselectItem(at: indexPath, animated: false)
return false
} else {
Expand Down Expand Up @@ -233,10 +271,10 @@ extension CustomActionSheetFilterVC {
}
}
}

extension CustomActionSheetFilterVC: FilterCVCDelegate {
func setSelectedCategory(index: Int) {

}

}
//
//extension CustomActionSheetFilterVC: FilterCVCDelegate {
// func setSelectedCategory(index: Int) {
//
// }
//
//}
6 changes: 5 additions & 1 deletion BeMe/BeMe/Mypage/Cells/MypageCRV.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MypageCRV: UICollectionReusableView {

@IBAction func deleteButtonTapped(_ sender: UIButton) {
setKeywordLabel(label: searchTextField, keyword: "")
NotificationCenter.default.post(name: .init("keyword"), object: nil, userInfo: ["keyword": ""])
MypageCRVDelegate?.deleteButtonSearch()
}

Expand All @@ -91,6 +92,7 @@ class MypageCRV: UICollectionReusableView {
moveHighLightBar(to: sender)
}
@IBAction func searchButtonTapped(_ sender: UIButton) {
NotificationCenter.default.post(name: .init("keyword"), object: nil, userInfo: ["keyword": searchTextField.text! ])
MypageCRVDelegate?.searchButtonSearch()
}

Expand Down Expand Up @@ -179,11 +181,13 @@ extension MypageCRV: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
print("TextFieldDId")
print(textField.text!)
NotificationCenter.default.post(name: .init("keyword"), object: nil, userInfo: ["keyword": textField.text!])

}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
NotificationCenter.default.post(name: .init("keyword"), object: nil, userInfo: ["keyword": textField.text!])

self.endEditing(true)

MypageCRVDelegate?.searchButtonSearch()
return true
}
Expand Down
5 changes: 3 additions & 2 deletions BeMe/BeMe/Mypage/Cells/MypageOthersScrapTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class MypageOthersScrapTVC: UITableViewCell {
}

// writer profile image init
writerImageView.image = UIImage(named: writerImg)

writerImageView.imageFromUrl(writerImg, defaultImgPath: "img")
writerImageView.makeRounded(cornerRadius: 10)
writerImageView.contentMode = .scaleAspectFill

// color
questionLabel.textColor = .black
Expand Down
Loading

0 comments on commit b578179

Please sign in to comment.