Comment interface adjustments

dev
wenlei 12 months ago
parent 8f9479a7dc
commit 2bdc1bdea7

@ -47,10 +47,7 @@ enum CommentListType {
}
enum CommentType {
case comment(Comment)
case quote(Comment)
}
struct Comment: Codable {
@ -89,6 +86,11 @@ struct Comment: Codable {
}
enum CommentType {
case comment(Comment)
case quote(Comment)
}
struct CommentSection {
var items: [CommentType]
}

@ -10,7 +10,7 @@ import UIKit
class FilterViewCell: UICollectionViewCell {
var titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.font = UIFont.systemFont(ofSize: 12)
titleLabel.font = UIFont.systemFont(ofSize: 11)
titleLabel.textColor = .secondaryText()
// titleLabel.backgroundColor = .red
titleLabel.textAlignment = .center
@ -49,10 +49,6 @@ class FilterViewCell: UICollectionViewCell {
func makeUI() {
// layer.cornerRadius = 14
// layer.borderColor = UIColor.yellow.cgColor
// layer.masksToBounds = true
// layer.borderWidth = 1
contentView.layer.cornerRadius = 14
contentView.layer.masksToBounds = true
@ -64,6 +60,12 @@ class FilterViewCell: UICollectionViewCell {
titleLabel.snp.makeConstraints { make in
make.edges.equalTo(contentView)
// make.left.equalTo(contentView).offset(10)
// make.right.equalTo(contentView).offset(10)
// make.top.equalTo(contentView).offset(10)
// make.bottom.equalTo(contentView).offset(10)
}
}
@ -103,7 +105,7 @@ class FilterHeaderView: UICollectionReusableView {
}
class FilterBottomView: UIView {
class FilterBottomView: UIControl {
let lineView: UIView = {
let lineView = UIView.init()
lineView.backgroundColor = .separator()

@ -94,6 +94,17 @@ class FilterViewController: ViewController {
self?.navigator.dismiss(sender: self)
}.disposed(by: rx.disposeBag)
filterBottomView.rx.controlEvent(.touchUpInside)
.subscribe { [weak self] _ in
viewModel.filter.accept(nil)
self?.navigator.dismiss(sender: self)
}.disposed(by: rx.disposeBag)
}
override func viewDidLayoutSubviews() {

@ -29,7 +29,6 @@ class AudioMoreActionController: ViewController, UIScrollViewDelegate {
var audioMoreActionBottomView: AudioMoreActionBottomView = {
let audioMoreActionBottomView = AudioMoreActionBottomView.init()
// audioMoreActionBottomView.backgroundColor = .blue
return audioMoreActionBottomView
}()

@ -83,7 +83,9 @@ class CommentViewController: ViewController {
let input = CommentViewModel.Input.init(viewWillAppear: rx.viewWillAppear,
selection: tableView.rx.itemSelected.asDriver(),
currentCommentListType: currentCommentListType)
currentCommentListType: currentCommentListType,
commentText: commentToolView.textField.rx.text.asDriver(),
sendCommentTrigger: commentToolView.textField.rx.controlEvent(.editingDidEndOnExit).asDriver())
let output = viewModel.transform(input: input)
let dataSource = RxTableViewSectionedReloadDataSource<CommentSection>(

@ -16,12 +16,16 @@ class CommentViewModel: ViewModel, ViewModelType {
let viewWillAppear: ControlEvent<Bool>
let selection: Driver<IndexPath>
let currentCommentListType: BehaviorRelay<CommentListType>
let commentText: Driver<String?>
let sendCommentTrigger: Driver<Void>
}
struct Output {
let items: BehaviorRelay<[CommentSection]>
let itemSelected: PublishSubject<Comment>
let insertCommment: PublishSubject<Comment>
}
@ -33,6 +37,7 @@ class CommentViewModel: ViewModel, ViewModelType {
let itemSelected = PublishSubject<Comment>()
let likeSelected = PublishSubject<String>()
let insertCommment: PublishSubject<Comment> = .init()
var journalID: String
@ -45,7 +50,7 @@ class CommentViewModel: ViewModel, ViewModelType {
func transform(input: Input) -> Output {
input.viewWillAppear.subscribe { _ in
self.requestCommentData(journalID: self.journalID, page: self.page, size: 10)
self.requestHotCommentListData(journalID: self.journalID, page: self.page, size: 10)
.subscribe { commentArray in
self.handleReceivedComments(comments: commentArray)
} onError: { error in
@ -57,7 +62,33 @@ class CommentViewModel: ViewModel, ViewModelType {
input.currentCommentListType.subscribe { commentListType in
switch commentListType {
case .hot:
self.requestHotCommentListData(journalID: self.journalID, page: self.page, size: 10)
.subscribe { comments in
self.handleReceivedComments(comments: comments)
} onError: { error in
} .disposed(by: self.rx.disposeBag)
case .latest:
self.requestLatestCommentListData(journalID: self.journalID, page: self.page, size: 10)
.subscribe { comments in
self.handleReceivedComments(comments: comments)
} onError: { error in
} .disposed(by: self.rx.disposeBag)
}
} onError: { error in
@ -85,10 +116,34 @@ class CommentViewModel: ViewModel, ViewModelType {
}.disposed(by: rx.disposeBag)
let sendComment = input.sendCommentTrigger
.withLatestFrom(input.commentText) // 使 commentText
.drive(onNext: { comment in
if let comment = comment, !comment.isEmpty {
self.sendCommentData(content: comment, journalId: self.journalID, parentId: nil, journalImage: nil)
.subscribe { comment in
} onError: { error in
}.disposed(by: self.rx.disposeBag)
} else {
print("评论为空,不发送")
}
})
return Output.init(items: items,
itemSelected: itemSelected)
itemSelected: itemSelected,
insertCommment: insertCommment)
}
private func handleReceivedComments(comments: [Comment]) {
@ -125,13 +180,24 @@ class CommentViewModel: ViewModel, ViewModelType {
func requestCommentData(journalID: String, page: Int, size: Int) -> Observable<[Comment]> {
return self.provider.commentList(journalId: journalID, page: page, size: size)
func requestHotCommentListData(journalID: String, page: Int, size: Int) -> Observable<[Comment]> {
return self.provider.hotCommentList(journalId: journalID, page: page, size: size)
.trackActivity(loading)
.trackError(error)
}
func requestLatestCommentListData(journalID: String, page: Int, size: Int) -> Observable<[Comment]> {
return self.provider.latestCommentList(journalId: journalID, page: page, size: size)
.trackActivity(loading)
.trackError(error)
}
func requestSubCommentData(parentId: String, page: Int, size: Int) -> Observable<[Comment]> {
return self.provider.subCommentList(parentId: parentId, page: page, size: size)
.trackActivity(loading)
@ -153,6 +219,14 @@ class CommentViewModel: ViewModel, ViewModelType {
items.accept([updatedSection])
}
}
func sendCommentData(content: String, journalId: String?, parentId: String?, journalImage: String?) -> Observable<Comment> {
return self.provider.sendComment(content: content, journalId: journalId, parentId: parentId, journalImage: journalImage)
.trackActivity(loading)
.trackError(error)
}

@ -52,7 +52,6 @@ class JournalAudioHeaderView: UICollectionReusableView {
var tagsContainerView: UIView = {
let tagsContainerView = UIView.init()
tagsContainerView.backgroundColor = .blue
return tagsContainerView
}()
@ -766,6 +765,7 @@ class CommentToolView: UIView {
string: "说点想说的",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.secondaryText()]
)
textField.returnKeyType = .send
return textField
}()

@ -25,7 +25,6 @@ class AudioTrackListViewController: ViewController {
var audioMoreActionBottomView: AudioMoreActionBottomView = {
let audioMoreActionBottomView = AudioMoreActionBottomView.init()
// audioMoreActionBottomView.backgroundColor = .blue
return audioMoreActionBottomView
}()

@ -370,8 +370,6 @@ class PlayerLyricsView: UIView {
}
func makeUI() {
// audioTrackView.backgroundColor = .red
// tableView.backgroundColor = .blue
addSubview(audioTrackView)
addSubview(tableView)

@ -211,7 +211,6 @@ class MusicStyleViewController: ViewController {
class MusicStyleHeaderView: UICollectionReusableView {
let titleImageView: UIImageView = {
let titleImageView = UIImageView.init()
titleImageView.backgroundColor = .blue
return titleImageView
}()

@ -32,16 +32,16 @@ class SearchViewModel: ViewModel, ViewModelType {
func transform(input: Input) -> Output {
input.viewWillAppear.subscribe { _ in
self.fetchSearchCategoryData().subscribe { searchCategoryArray in
self.items.accept([SearchCategorySection.init(items: searchCategoryArray)])
} onError: { error in
}.disposed(by: self.rx.disposeBag)
}.disposed(by: rx.disposeBag)
self.fetchSearchCategoryData().subscribe { searchCategoryArray in
self.items.accept([SearchCategorySection.init(items: searchCategoryArray)])
} onError: { error in
}.disposed(by: rx.disposeBag)

@ -65,12 +65,19 @@ protocol IndieMusicAPI {
///
func checkVersion (platform: String, deviceId: String, appVersion: String) -> Single<Void>
///
func commentList(journalId: String, page: Int, size: Int) -> Single<[Comment]>
///
func hotCommentList(journalId: String, page: Int, size: Int) -> Single<[Comment]>
///
func latestCommentList(journalId: String, page: Int, size: Int) -> Single<[Comment]>
///
func subCommentList(parentId: String, page: Int, size: Int) -> Single<[Comment]>
///
func commentLike(commentId: String) -> Single<Void>
///
func sendComment(content: String, journalId: String?, parentId: String?, journalImage: String?) -> Single<Comment>
///
func filterMenu() -> Single<FilterMenu>
///

@ -41,10 +41,13 @@ enum APIConfig {
case followerList(String, Int, Int)
case blackList(Int, Int)
case checkVersion([String: Any])
case commentList(String, Int, Int)
case hotCommentList(String, Int, Int)
case latestCommentList(String, Int, Int)
case subCommentList(String, Int, Int)
case commentLike(String, [String: Any])
case sendComment([String: Any])
case filterMenu
case journalRecommend(String)
@ -111,13 +114,16 @@ extension APIConfig: TargetType {
case .checkVersion:
return "luoo-user/update/checkVersion"
case .commentList(let journalId, let page, let size):
return "luoo-comment/comment/\(journalId)/\(page)/\(size)"
case .hotCommentList(let journalId, let page, let size):
return "luoo-comment/comment/hot/\(journalId)/\(page)/\(size)"
case .latestCommentList(let journalId, let page, let size):
return "luoo-comment/comment/new/\(journalId)/\(page)/\(size)"
case .subCommentList(let parentId, let page, let size):
return "luoo-comment/comment/comment/\(parentId)/\(page)/\(size)"
case .commentLike(let commentID, _):
return "luoo-comment/comment/thumbup/\(commentID)"
case .sendComment:
return "luoo-comment/comment"
case .filterMenu:
return "luoo-music/journal/filter"
case .journalRecommend(let journalID):
@ -135,9 +141,9 @@ extension APIConfig: TargetType {
var method: Moya.Method {
switch self {
case .wechatAccessToken, .journalList, .journalMusic, .countryCode, .imageCheckCode, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .commentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
case .wechatAccessToken, .journalList, .journalMusic, .countryCode, .imageCheckCode, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .hotCommentList, .latestCommentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
return .get
case .sendsms, .login, .autoLogin, .editAvatar, .like, .checkVersion, .logout:
case .sendsms, .login, .autoLogin, .editAvatar, .like, .checkVersion, .logout, .sendComment:
return .post
case .editUserInfo, .commentLike:
return .put
@ -149,10 +155,10 @@ extension APIConfig: TargetType {
var parameterEncoding: ParameterEncoding {
switch self {
case .wechatAccessToken, .journalList, .journalMusic, .countryCode, .sendsms, .imageCheckCode, .login, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .like, .cancelLike, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .commentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
case .wechatAccessToken, .journalList, .journalMusic, .countryCode, .sendsms, .imageCheckCode, .login, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .like, .cancelLike, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .hotCommentList, .latestCommentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
return URLEncoding.default
case .autoLogin, .editUserInfo, .editAvatar, .checkVersion, .logout, .commentLike:
case .autoLogin, .editUserInfo, .editAvatar, .checkVersion, .logout, .commentLike, .sendComment:
return JSONEncoding.default
}
}
@ -161,10 +167,10 @@ extension APIConfig: TargetType {
var task: Task {
var parameters: [String: Any] = [:]
switch self {
case .wechatAccessToken, .countryCode, .journalMusic, .imageCheckCode, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .commentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
case .wechatAccessToken, .countryCode, .journalMusic, .imageCheckCode, .getUserInfo, .carousel, .otherUserInfo, .single, .journal, .messageList, .collectSongList, .journalCollectList, .followingList, .followerList, .blackList, .hotCommentList, .latestCommentList, .subCommentList, .filterMenu, .journalRecommend, .searchCategory, .serach, .randomAudioTrack:
return .requestPlain
case .login(let dic), .journalList(let dic), .sendsms(let dic), .autoLogin(let dic), .editUserInfo(let dic), .like(let dic), .cancelLike(let dic), .logout(let dic), .checkVersion(let dic), .commentLike(_, let dic):
case .login(let dic), .journalList(let dic), .sendsms(let dic), .autoLogin(let dic), .editUserInfo(let dic), .like(let dic), .cancelLike(let dic), .logout(let dic), .checkVersion(let dic), .commentLike(_, let dic), .sendComment(let dic):
parameters = dic
return .requestParameters(parameters: parameters, encoding: parameterEncoding)
@ -190,7 +196,7 @@ extension APIConfig: TargetType {
var headers : [String : String]? {
switch self {
case .autoLogin, .getUserInfo, .journalList, .journalMusic, .otherUserInfo, .like, .cancelLike, .single, .journal, .collectSongList, .journalCollectList, .followingList, .messageList, .followerList, .blackList, .editUserInfo, .logout, .editAvatar, .commentList, .subCommentList, .commentLike, .filterMenu, .journalRecommend, .serach, .randomAudioTrack:
case .autoLogin, .getUserInfo, .journalList, .journalMusic, .otherUserInfo, .like, .cancelLike, .single, .journal, .collectSongList, .journalCollectList, .followingList, .messageList, .followerList, .blackList, .editUserInfo, .logout, .editAvatar, .hotCommentList, .latestCommentList, .subCommentList, .commentLike, .filterMenu, .journalRecommend, .serach, .randomAudioTrack, .sendComment:
return ["Authorization": AuthManager.shared.token?.basicToken ?? ""]
default:
return nil

@ -236,11 +236,19 @@ extension RestApi {
}
func hotCommentList(journalId: String, page: Int, size: Int) -> Single<[Comment]> {
return requestObject(.hotCommentList(journalId, page, size), with: "data.rows", type: [Comment].self)
}
func commentList(journalId: String, page: Int, size: Int) -> Single<[Comment]> {
return requestObject(.commentList(journalId, page, size), with: "data.rows", type: [Comment].self)
func latestCommentList(journalId: String, page: Int, size: Int) -> Single<[Comment]> {
return requestObject(.latestCommentList(journalId, page, size), with: "data.rows", type: [Comment].self)
}
func subCommentList(parentId: String, page: Int, size: Int) -> Single<[Comment]> {
return requestObject(.subCommentList(parentId, page, size), with: "data.rows", type: [Comment].self)
@ -250,6 +258,25 @@ extension RestApi {
return requestWithoutMapping(.commentLike(commentId, ["":""])).map{ _ in }
}
func sendComment(content: String, journalId: String?, parentId: String?, journalImage: String?) -> Single<Comment> {
var commentVo = ["content": content]
if let journalId = journalId {
commentVo["journalId"] = journalId
}
if let parentId = parentId {
commentVo["parentId"] = parentId
}
if let journalImage = journalImage {
commentVo["journalImage"] = journalImage
}
let dic = ["commentVo": commentVo]
return requestObject(.sendComment(dic), with: "data", type: Comment.self)
}
func filterMenu() -> Single<FilterMenu> {
return requestObject(.filterMenu, with: "data", type: FilterMenu.self)
}

Loading…
Cancel
Save