|
@@ -13,17 +13,24 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
var cellHeightsDictionary = Dictionary<IndexPath, Any>()
|
|
|
var id : Int = 0
|
|
|
var communityRecommendDataModels = Array<CommunityRecommendDataModel>()
|
|
|
-
|
|
|
+ var communityTopicDetailModel : CommunityTopicDetailModel?
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
setupViews()
|
|
|
- setupLayouts()
|
|
|
setupData()
|
|
|
+ setupLayouts()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ super.viewWillAppear(animated)
|
|
|
+ communityTopicDetailApi()
|
|
|
}
|
|
|
|
|
|
override func setupViews() {
|
|
|
view.addSubview(bgImageView)
|
|
|
+ view.addSubview(bgView)
|
|
|
view.addSubview(tableView)
|
|
|
view.insertSubview(navigationBar, aboveSubview: tableView)
|
|
|
setnavigationBar()
|
|
@@ -34,14 +41,12 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
func setnavigationBar() {
|
|
|
navigationBar.addSubview(navigationBgView)
|
|
|
navigationBar.addSubview(topicLable)
|
|
|
- navigationBar.addSubview(followButton)
|
|
|
+ navigationBar.addSubview(focusButton)
|
|
|
navigationBar.insertSubview(navigationBgView, aboveSubview: navigationBar.backgroundImageView)
|
|
|
navigationBar.backgroundImageView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth)
|
|
|
navigationBar.clipsToBounds = true
|
|
|
navigationBar.wr_setLeftButton(image: kImage(name: "navbar_back_white")!)
|
|
|
navigationBar.wr_setRightButton(title: "我的话题", titleColor: .white)
|
|
|
- // 设置导航栏显示图片
|
|
|
- navigationBar.barBackgroundImage = UIImage(named: "pic_example_12")
|
|
|
// 设置初始导航栏透明度
|
|
|
navigationBar.wr_setBackgroundAlpha(alpha: 0)
|
|
|
// 设置状态栏style
|
|
@@ -53,6 +58,9 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
make.top.left.right.equalToSuperview()
|
|
|
make.height.equalTo(kScreenWidth)
|
|
|
}
|
|
|
+ bgView.snp.makeConstraints { (make) in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
tableView.snp.makeConstraints { (make) in
|
|
|
make.top.left.right.bottom.equalToSuperview()
|
|
|
}
|
|
@@ -63,7 +71,7 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
make.centerY.equalTo(navigationBar.leftButton)
|
|
|
make.left.equalTo(navigationBar.leftButton.snp_right)
|
|
|
}
|
|
|
- followButton.snp_makeConstraints { (make) in
|
|
|
+ focusButton.snp_makeConstraints { (make) in
|
|
|
make.right.equalTo(-14)
|
|
|
make.centerY.equalTo(navigationBar.leftButton)
|
|
|
make.width.equalTo(60)
|
|
@@ -85,10 +93,15 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
|
|
|
private lazy var bgImageView: UIImageView = {
|
|
|
let bgImageView = UIImageView()
|
|
|
- bgImageView.image = kImage(name: "pic_example_12")
|
|
|
return bgImageView
|
|
|
}()
|
|
|
|
|
|
+ private lazy var bgView: UIView = {
|
|
|
+ let bgView = UIView()
|
|
|
+ bgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.4)
|
|
|
+ return bgView
|
|
|
+ }()
|
|
|
+
|
|
|
private lazy var communityFeaturedTopicsHeaderView: CommunityFeaturedTopicsHeaderView = {
|
|
|
let communityFeaturedTopicsHeaderView = CommunityFeaturedTopicsHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 200 + kSafeStatusBarHeight))
|
|
|
return communityFeaturedTopicsHeaderView
|
|
@@ -103,17 +116,30 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
return topicLable
|
|
|
}()
|
|
|
|
|
|
- private lazy var followButton: UIButton = {
|
|
|
- let followButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- followButton.titleLabel?.font = kMediumFont13
|
|
|
- followButton.alpha = 0
|
|
|
- followButton.cornerRadius = 12
|
|
|
- followButton.masksToBounds = true
|
|
|
- followButton.rx.tap.subscribe(onNext: {
|
|
|
- [weak self] (data) in
|
|
|
- followButton.isSelected = !followButton.isSelected
|
|
|
+ private lazy var focusButton: UIButton = {
|
|
|
+ let focusButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ focusButton.setImage(kImage(name: "star_attention"), for: UIControl.State.normal)
|
|
|
+ focusButton.setImage(kImage(name: "star_followed"), for: UIControl.State.selected)
|
|
|
+ focusButton.setTitleColor(k666666Color, for: UIControl.State.selected)
|
|
|
+ focusButton.setTitleColor(kThemeColor, for: UIControl.State.normal)
|
|
|
+ focusButton.setTitle("关注", for: UIControl.State.normal)
|
|
|
+ focusButton.setTitle("关注", for: UIControl.State.selected)
|
|
|
+ focusButton.titleLabel?.font = kMediumFont13
|
|
|
+ focusButton.setBackgroundImage(UIImage.imageWithColor(color: kffffffColor), for: UIControl.State.normal)
|
|
|
+ focusButton.setBackgroundImage(UIImage.imageWithColor(color: kf7f8faColor), for: UIControl.State.selected)
|
|
|
+ focusButton.alpha = 0
|
|
|
+ focusButton.layer.borderWidth = 1
|
|
|
+ focusButton.cornerRadius = 12
|
|
|
+ focusButton.masksToBounds = true
|
|
|
+ focusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ if self?.communityTopicDetailModel?.isFollow == 1 {
|
|
|
+ self?.communityMemberFollowTopicCancelFollowApi()
|
|
|
+ }else {
|
|
|
+ self?.communityMemberFollowTopicFollowApi()
|
|
|
+ }
|
|
|
}).disposed(by: disposeBag)
|
|
|
- return followButton
|
|
|
+
|
|
|
+ return focusButton
|
|
|
}()
|
|
|
|
|
|
private lazy var navigationBgView: UIView = {
|
|
@@ -125,20 +151,25 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
|
|
|
|
|
|
override func setupData() {
|
|
|
+ communityPostTopicApi(page: 1)
|
|
|
//下拉刷新
|
|
|
- tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) {
|
|
|
+ tableView.addHeaderWithHeader(withBeginRefresh: false, animation: false) {
|
|
|
[weak self] (page) in
|
|
|
- self?.communityTopicDetailApi()
|
|
|
self?.communityPostTopicApi(page: page)
|
|
|
+ self?.communityTopicDetailApi()
|
|
|
+
|
|
|
}
|
|
|
tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
|
|
|
[weak self] (page) in
|
|
|
self?.communityPostTopicApi(page: page)
|
|
|
}
|
|
|
- tableView.tableHeaderView = communityFeaturedTopicsHeaderView
|
|
|
communityFeaturedTopicsHeaderView.followClosureName = {
|
|
|
- (button:UIButton) -> Bool in
|
|
|
- return !button.isSelected
|
|
|
+ [weak self] in
|
|
|
+ if self?.communityTopicDetailModel?.isFollow == 1 {
|
|
|
+ self?.communityMemberFollowTopicCancelFollowApi()
|
|
|
+ }else {
|
|
|
+ self?.communityMemberFollowTopicFollowApi()
|
|
|
+ }
|
|
|
}
|
|
|
navigationBar.onClickRightButton = {
|
|
|
[weak self] in
|
|
@@ -152,42 +183,11 @@ class CommunityFeaturedTopicsViewController: BaseViewController {
|
|
|
tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
|
|
|
}
|
|
|
|
|
|
- var followType: FollowType! {
|
|
|
- didSet {
|
|
|
- switch followType {
|
|
|
- case .futureFollow?:
|
|
|
- followButton.setTitle("关注", for: UIControl.State.normal)
|
|
|
- followButton.setTitleColor(kThemeColor, for: UIControl.State.normal)
|
|
|
- followButton.setImage(kImage(name: "star_attention"), for: UIControl.State.normal)
|
|
|
- followButton.layer.borderColor = kThemeColor.cgColor
|
|
|
- followButton.setBackgroundImage(UIImage.imageWithColor(color: kffffffColor), for: UIControl.State.normal)
|
|
|
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 2)
|
|
|
-
|
|
|
- break
|
|
|
- case .alreadyFollow?:
|
|
|
- followButton.setTitle("关注", for: UIControl.State.normal)
|
|
|
- followButton.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
- followButton.setImage(kImage(name: "star_followed"), for: UIControl.State.normal)
|
|
|
- followButton.layer.borderColor = kf7f8faColor.cgColor
|
|
|
- followButton.setBackgroundImage(UIImage.imageWithColor(color: kf7f8faColor), for: UIControl.State.normal)
|
|
|
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 2)
|
|
|
- break
|
|
|
- case .mutualFollow?:
|
|
|
- followButton.setTitle("互相关注", for: UIControl.State.normal)
|
|
|
- followButton.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
- followButton.setImage(nil, for: UIControl.State.normal)
|
|
|
- followButton.layer.borderColor = kCCCCCCColor.cgColor
|
|
|
- followButton.setBackgroundImage(UIImage.imageWithColor(color: kffffffColor), for: UIControl.State.normal)
|
|
|
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 0)
|
|
|
-
|
|
|
- break
|
|
|
- default:
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
extension CommunityFeaturedTopicsViewController {
|
|
|
func scrollViewDidScroll(_ scrollView: UIScrollView)
|
|
|
{
|
|
@@ -196,7 +196,7 @@ extension CommunityFeaturedTopicsViewController {
|
|
|
{
|
|
|
let alpha = (offsetY - kSafeStatusBarHeight) / CGFloat(kNavBarTotalHeight)
|
|
|
navigationBar.wr_setBackgroundAlpha(alpha: alpha)
|
|
|
- followButton.alpha = alpha
|
|
|
+ focusButton.alpha = alpha
|
|
|
topicLable.alpha = alpha
|
|
|
navigationBgView.alpha = alpha
|
|
|
navigationBar.rightButton.alpha = 1 - alpha
|
|
@@ -204,7 +204,7 @@ extension CommunityFeaturedTopicsViewController {
|
|
|
else
|
|
|
{
|
|
|
navigationBar.wr_setBackgroundAlpha(alpha: 0)
|
|
|
- followButton.alpha = 0
|
|
|
+ focusButton.alpha = 0
|
|
|
topicLable.alpha = 0
|
|
|
navigationBgView.alpha = 0
|
|
|
navigationBar.rightButton.alpha = 1
|
|
@@ -213,18 +213,34 @@ extension CommunityFeaturedTopicsViewController {
|
|
|
}
|
|
|
|
|
|
extension CommunityFeaturedTopicsViewController {
|
|
|
+ func isFollow() {
|
|
|
+ if communityTopicDetailModel?.isFollow == 1 {
|
|
|
+ focusButton.isSelected = true
|
|
|
+ focusButton.layer.borderColor = kf7f8faColor.cgColor
|
|
|
+ }else {
|
|
|
+ focusButton.isSelected = false
|
|
|
+ focusButton.layer.borderColor = kThemeColor.cgColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension CommunityFeaturedTopicsViewController {
|
|
|
+
|
|
|
+ /// 话题详情页面
|
|
|
func communityTopicDetailApi() {
|
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityTopicDetailApi(id: id) {
|
|
|
[weak self] (communityTopicDetailModel) -> (Void) in
|
|
|
- let communityTopicDetailModel = communityTopicDetailModel as? CommunityTopicDetailModel
|
|
|
- self?.topicLable.text = communityTopicDetailModel?.name
|
|
|
- self?.followType = FollowType(rawValue: communityTopicDetailModel?.isFollow ?? 0)
|
|
|
- self?.bgImageView.kf.setImage(with: kURLImage(name: communityTopicDetailModel?.img ?? ""), placeholder: kImage(name: "pic_example_12"))
|
|
|
+ self?.communityTopicDetailModel = communityTopicDetailModel as? CommunityTopicDetailModel
|
|
|
+ self?.topicLable.text = self?.communityTopicDetailModel?.name
|
|
|
+ self?.isFollow()
|
|
|
+ self?.bgImageView.kf.setImage(with: kURLImage(name: self?.communityTopicDetailModel?.img ?? ""), placeholder: kImage(name: "pic_example_12"))
|
|
|
self?.navigationBar.barBackgroundImage = self?.bgImageView.image
|
|
|
- self?.communityFeaturedTopicsHeaderView.communityTopicDetailModel = communityTopicDetailModel
|
|
|
+ self?.communityFeaturedTopicsHeaderView.communityTopicDetailModel = self?.communityTopicDetailModel
|
|
|
+ self?.tableView.tableHeaderView = self?.communityFeaturedTopicsHeaderView
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// 话题帖子
|
|
|
func communityPostTopicApi(page:Int) {
|
|
|
SwiftMoyaNetWorkServiceCommunity.shared().communityPostTopicApi(id: id, page: page) {
|
|
|
[weak self] (communityRecommendFeedModel) -> (Void) in
|
|
@@ -243,8 +259,55 @@ extension CommunityFeaturedTopicsViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// 关注话题(单个)
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - topicId: 话题Id
|
|
|
+ /// - completion: 回调
|
|
|
+ func communityMemberFollowTopicFollowApi() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityMemberFollowTopicFollowApi(topicId: id) {
|
|
|
+ [weak self] (data) -> (Void) in
|
|
|
+ self?.communityTopicDetailModel?.isFollow = 1
|
|
|
+ self?.communityFeaturedTopicsHeaderView.communityTopicDetailModel = self?.communityTopicDetailModel
|
|
|
+ self?.isFollow()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 取消关注话题
|
|
|
+ ///
|
|
|
+ /// - Parameters:
|
|
|
+ /// - topicId: 话题Id
|
|
|
+ /// - completion: 回调
|
|
|
+ func communityMemberFollowTopicCancelFollowApi() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityMemberFollowTopicCancelFollowApi(topicId:id) {
|
|
|
+ [weak self] (data) -> (Void) in
|
|
|
+ self?.communityTopicDetailModel?.isFollow = 0
|
|
|
+ self?.communityFeaturedTopicsHeaderView.communityTopicDetailModel = self?.communityTopicDetailModel
|
|
|
+ self?.isFollow()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 关注
|
|
|
+ func userFollow(followUid:Int,completion: @escaping (Int) -> Void) {
|
|
|
+ SwiftMoyaNetWorkServiceUser.shared().userFollowApi(followUid: followUid) { (followStatusModel) -> (Void) in
|
|
|
+ let followStatusModel = followStatusModel as? FollowStatusModel
|
|
|
+ completion(followStatusModel?.isFollowStatus ?? 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 取消关注
|
|
|
+ func userCancelFollow(followUid:Int,completion: @escaping (Int) -> Void) {
|
|
|
+ SwiftMoyaNetWorkServiceUser.shared().userCancelFollowApi(followUid: followUid) {
|
|
|
+ (followStatusModel) -> (Void) in
|
|
|
+ let followStatusModel = followStatusModel as? FollowStatusModel
|
|
|
+ completion(followStatusModel?.isFollowStatus ?? 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableViewDataSource {
|
|
|
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
@@ -262,6 +325,32 @@ extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableVie
|
|
|
case 0:
|
|
|
let cell = CardContentUserTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
cell.communityRecommendDataModel = communityRecommendDataModel
|
|
|
+ cell.followClosure = {
|
|
|
+ if communityRecommendDataModel.isFollow == 0 {//加关注
|
|
|
+ self.userFollow(followUid: cell.communityRecommendDataModel?.uid ?? 0, completion: { [weak self] (isFollow) -> Void in
|
|
|
+ for (_,communityRecommendDataModel) in (self?.communityRecommendDataModels.enumerated())! {
|
|
|
+ if communityRecommendDataModel.uid == cell.communityRecommendDataModel?.uid {
|
|
|
+ communityRecommendDataModel.isFollow = isFollow
|
|
|
+ self?.tableView.reloadData()
|
|
|
+// let indexPath1 = IndexPath(row: 0, section: index)
|
|
|
+// self?.tableView.reloadRows(at: [indexPath1], with: UITableView.RowAnimation.none)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else {//取消关注
|
|
|
+ self.userCancelFollow(followUid: cell.communityRecommendDataModel?.uid ?? 0, completion: { [weak self] (isFollow) -> Void in
|
|
|
+
|
|
|
+ for (_,communityRecommendDataModel) in (self?.communityRecommendDataModels.enumerated())! {
|
|
|
+ if communityRecommendDataModel.uid == cell.communityRecommendDataModel?.uid {
|
|
|
+ communityRecommendDataModel.isFollow = isFollow
|
|
|
+ self?.tableView.reloadData()
|
|
|
+// let indexPath1 = IndexPath(row: 0, section: index)
|
|
|
+// self?.tableView.reloadRows(at: [indexPath1], with: UITableView.RowAnimation.none)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
return cell
|
|
|
//图片视频
|
|
|
case 1:
|