123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- //
- // CommunityFollowUserViewModel.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/7/2.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- class CommunityFollowUserViewModel: NSObject {
- static let shared : CommunityFollowUserViewModel = CommunityFollowUserViewModel()
-
- /// 关注
- 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)
- }
- }
-
-
- /// 设置关注
- ///
- /// - Parameters:
- /// - followButton: 关注button
- /// - followType: 关注类型
- func setFollowType(followButton:UIButton,followType: FollowType) {
- 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
- }
- }
-
- /// 设置关注
- ///
- /// - Parameters:
- /// - followButton: 关注button
- /// - followType: 关注类型
- func setVideoFollowType(followButton:UIButton,followType: FollowType) {
- switch followType {
- case .futureFollow:
- followButton.setTitle("关注", for: UIControl.State.normal)
- followButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- followButton.setImage(kImage(name: "star_attention"), for: UIControl.State.normal)
- followButton.layer.borderColor = kThemeColor.cgColor
- followButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 2)
-
- break
- case .alreadyFollow:
- followButton.setTitle("关注", for: UIControl.State.normal)
- followButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- followButton.setImage(kImage(name: "star_followed"), for: UIControl.State.normal)
- followButton.layer.borderColor = kffffffColor.cgColor
- followButton.setBackgroundImage(UIImage.imageWithColor(color: UIColor.clear), for: UIControl.State.normal)
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 2)
- break
- case .mutualFollow:
- followButton.setTitle("互相关注", for: UIControl.State.normal)
- followButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- followButton.setImage(nil, for: UIControl.State.normal)
- followButton.layer.borderColor = kffffffColor.cgColor
- followButton.setBackgroundImage(UIImage.imageWithColor(color: UIColor.clear), for: UIControl.State.normal)
- followButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 0)
-
- break
- }
- }
-
- }
- // MARK: - communityPostDetailModel
- extension CommunityFollowUserViewModel {
- /// 关注/取消关注
- ///
- /// - Parameter communityPostDetailModel: 帖子模型
- func follow(communityPostDetailModel: CommunityPostDetailModel,button:UIButton) {
- if communityPostDetailModel.isFollow == 0 {//加关注
- self.userFollow(followUid: communityPostDetailModel.uid ?? 0, completion: { (isFollow) -> Void in
- communityPostDetailModel.isFollow = isFollow
- CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityPostDetailModel.isFollow ?? 0) ?? .futureFollow)
- })
- }else {//取消关注
- self.userCancelFollow(followUid: communityPostDetailModel.uid ?? 0, completion: { (isFollow) -> Void in
- communityPostDetailModel.isFollow = isFollow
- CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityPostDetailModel.isFollow ?? 0) ?? .futureFollow)
- })
- }
- }
- }
- // MARK: - CommunityRecommendDataModel
- extension CommunityFollowUserViewModel {
- /// 关注/取消关注
- ///
- /// - Parameter communityRecommendDataModel: 帖子模型
- func follow(communityRecommendDataModel: CommunityRecommendDataModel,communityRecommendDataModels: Array<CommunityRecommendDataModel>,tableView:UITableView) {
- if communityRecommendDataModel.isFollow == 0 {//加关注
- self.userFollow(followUid: communityRecommendDataModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityRecommendDataModels.enumerated() {
- if model.uid == communityRecommendDataModel.uid {
- model.isFollow = isFollow
- tableView.reloadData()
- }
- }
- })
- }else {//取消关注
- self.userCancelFollow(followUid: communityRecommendDataModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityRecommendDataModels.enumerated() {
- if model.uid == communityRecommendDataModel.uid {
- model.isFollow = isFollow
- tableView.reloadData()
- }
- }
- })
- }
- }
- }
- // MARK: - communityRecommendTypeDataModel
- extension CommunityFollowUserViewModel {
- /// 关注/取消关注
- ///
- /// - Parameter communityRecommendTypeDataModel: 帖子模型
- func follow(communityRecommendTypeDataModel: CommunityRecommendTypeDataModel,communityRecommendTypeDataModels: Array<CommunityRecommendTypeDataModel>,collectionView:UICollectionView,completion: @escaping (Int) -> Void) {
- if communityRecommendTypeDataModel.followStatus == 0 {//加关注
- self.userFollow(followUid: communityRecommendTypeDataModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityRecommendTypeDataModels.enumerated() {
- if model.uid == communityRecommendTypeDataModel.uid {
- model.followStatus = isFollow
- collectionView.reloadData()
- }
- }
- })
- }else {//取消关注
- self.userCancelFollow(followUid: communityRecommendTypeDataModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityRecommendTypeDataModels.enumerated() {
- if model.uid == communityRecommendTypeDataModel.uid {
- model.followStatus = isFollow
- collectionView.reloadData()
- }
- }
- })
- }
- }
- }
- // MARK: - cmsMemberModel
- extension CommunityFollowUserViewModel {
- /// 关注/取消关注
- ///
- /// - Parameter cmsMemberModel: 帖子模型
- func follow(cmsMemberModel: CMSMemberModel,cmsMemberModels: Array<CMSMemberModel>,collectionView:UICollectionView,completion: @escaping (Int) -> Void) {
- if cmsMemberModel.followStatus == 0 {//加关注
- self.userFollow(followUid: cmsMemberModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in cmsMemberModels.enumerated() {
- if model.uid == cmsMemberModel.uid {
- model.followStatus = isFollow
- collectionView.reloadData()
- }
- }
- })
- }else {//取消关注
- self.userCancelFollow(followUid: cmsMemberModel.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in cmsMemberModels.enumerated() {
- if model.uid == cmsMemberModel.uid {
- model.followStatus = isFollow
- collectionView.reloadData()
- }
- }
- })
- }
- }
- }
- // MARK: - communityFollowDataModel
- extension CommunityFollowUserViewModel {
-
- /// 关注/取消关注
- ///
- /// - Parameter communityRecommendDataModel: 帖子模型
- func follow(communityFollowDataModel: CommunityFollowDataModel,communityFollowDataModels: Array<CommunityFollowDataModel>,tableView:UITableView) {
- if communityFollowDataModel.relateData?.isFollow == 0 {//加关注
- self.userFollow(followUid: communityFollowDataModel.relateData?.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityFollowDataModels.enumerated() {
- if model.relateData?.uid == communityFollowDataModel.relateData?.uid {
- model.relateData?.isFollow = isFollow
- tableView.reloadData()
- }
- }
- })
- }else {//取消关注
- self.userCancelFollow(followUid: communityFollowDataModel.relateData?.uid ?? 0, completion: { (isFollow) -> Void in
- for (_,model) in communityFollowDataModels.enumerated() {
- if model.relateData?.uid == communityFollowDataModel.relateData?.uid {
- model.relateData?.isFollow = isFollow
- tableView.reloadData()
- }
- }
- })
- }
- }
- }
- // MARK: - CommunityVideoItemModel
- extension CommunityFollowUserViewModel {
- /// 关注/取消关注
- ///
- /// - Parameter communityVideoItemModel: 帖子模型
- func follow(communityVideoItemModel: CommunityVideoItemModel,videoItemList:Array<CommunityVideoItemModel>,button:UIButton) {
- if communityVideoItemModel.isFollow == 0 {//加关注
- self.userFollow(followUid: communityVideoItemModel.uid ?? 0, completion: { (isFollow) -> Void in
- communityVideoItemModel.isFollow = isFollow
- CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityVideoItemModel.isFollow ?? 0) ?? .futureFollow)
- for (_,model) in videoItemList.enumerated() {
- if model.uid == communityVideoItemModel.uid {
- model.isFollow = isFollow
- }
- }
-
- })
- }else {//取消关注
- self.userCancelFollow(followUid: communityVideoItemModel.uid ?? 0, completion: { (isFollow) -> Void in
- communityVideoItemModel.isFollow = isFollow
- CommunityFollowUserViewModel.shared.setFollowType(followButton: button, followType: FollowType(rawValue: communityVideoItemModel.isFollow ?? 0) ?? .futureFollow)
- for (_,model) in videoItemList.enumerated() {
- if model.uid == communityVideoItemModel.uid {
- model.isFollow = isFollow
- }
- }
- })
- }
- }
- }
|