mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 08:03:50 +02:00
Reactions: Plug button actions
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ReactionsMenuReactions: String {
|
||||
enum ReactionsMenuReaction: String {
|
||||
case agree = "👍"
|
||||
case disagree = "👎"
|
||||
case like = "🙂"
|
||||
@@ -29,8 +29,6 @@ final class ReactionsMenuView: UIView, NibOwnerLoadable {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
//private var strengthViews: [UIView] = []
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var viewModel: ReactionsMenuViewModelType? {
|
||||
@@ -54,18 +52,36 @@ final class ReactionsMenuView: UIView, NibOwnerLoadable {
|
||||
self.commonInit()
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction private func agreeButtonAction(_ sender: Any) {
|
||||
self.viewModel?.process(viewAction: .toggleReaction(.agree))
|
||||
}
|
||||
|
||||
@IBAction private func disagreeButtonAction(_ sender: Any) {
|
||||
self.viewModel?.process(viewAction: .toggleReaction(.disagree))
|
||||
}
|
||||
|
||||
@IBAction private func likeButtonAction(_ sender: Any) {
|
||||
self.viewModel?.process(viewAction: .toggleReaction(.like))
|
||||
}
|
||||
|
||||
@IBAction private func dislikeButtonAction(_ sender: Any) {
|
||||
self.viewModel?.process(viewAction: .toggleReaction(.dislike))
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func commonInit() {
|
||||
|
||||
agreeButton.setTitle(VectorL10n.roomEventActionReactionAgree(ReactionsMenuReactions.agree.rawValue), for: .normal)
|
||||
agreeButton.setTitle(VectorL10n.roomEventActionReactionAgree(ReactionsMenuReactions.agree.rawValue), for: .highlighted)
|
||||
disagreeButton.setTitle(VectorL10n.roomEventActionReactionDisagree(ReactionsMenuReactions.disagree.rawValue), for: .normal)
|
||||
disagreeButton.setTitle(VectorL10n.roomEventActionReactionDisagree(ReactionsMenuReactions.disagree.rawValue), for: .highlighted)
|
||||
likeButton.setTitle(VectorL10n.roomEventActionReactionLike(ReactionsMenuReactions.like.rawValue), for: .normal)
|
||||
likeButton.setTitle(VectorL10n.roomEventActionReactionLike(ReactionsMenuReactions.like.rawValue), for: .highlighted)
|
||||
dislikeButton.setTitle(VectorL10n.roomEventActionReactionDislike(ReactionsMenuReactions.dislike.rawValue), for: .normal)
|
||||
dislikeButton.setTitle(VectorL10n.roomEventActionReactionDislike(ReactionsMenuReactions.dislike.rawValue), for: .highlighted)
|
||||
agreeButton.setTitle(VectorL10n.roomEventActionReactionAgree(ReactionsMenuReaction.agree.rawValue), for: .normal)
|
||||
agreeButton.setTitle(VectorL10n.roomEventActionReactionAgree(ReactionsMenuReaction.agree.rawValue), for: .highlighted)
|
||||
disagreeButton.setTitle(VectorL10n.roomEventActionReactionDisagree(ReactionsMenuReaction.disagree.rawValue), for: .normal)
|
||||
disagreeButton.setTitle(VectorL10n.roomEventActionReactionDisagree(ReactionsMenuReaction.disagree.rawValue), for: .highlighted)
|
||||
likeButton.setTitle(VectorL10n.roomEventActionReactionLike(ReactionsMenuReaction.like.rawValue), for: .normal)
|
||||
likeButton.setTitle(VectorL10n.roomEventActionReactionLike(ReactionsMenuReaction.like.rawValue), for: .highlighted)
|
||||
dislikeButton.setTitle(VectorL10n.roomEventActionReactionDislike(ReactionsMenuReaction.dislike.rawValue), for: .normal)
|
||||
dislikeButton.setTitle(VectorL10n.roomEventActionReactionDislike(ReactionsMenuReaction.dislike.rawValue), for: .highlighted)
|
||||
|
||||
customizeViewRendering()
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
<state key="normal" title="Agree 👍">
|
||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="agreeButtonAction:" destination="-1" eventType="touchUpInside" id="uLG-m0-aTt"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ebe-PT-0R2" customClass="ReactionsMenuButton" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="104" y="59" width="100" height="38"/>
|
||||
@@ -48,6 +51,9 @@
|
||||
<state key="normal" title="Disagree 👎">
|
||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="disagreeButtonAction:" destination="-1" eventType="touchUpInside" id="8Ir-5R-jpn"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kao-MQ-QFq" customClass="ReactionsMenuButton" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="210" y="13" width="100" height="38"/>
|
||||
@@ -62,6 +68,9 @@
|
||||
<state key="normal" title="Like 🙂">
|
||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="likeButtonAction:" destination="-1" eventType="touchUpInside" id="3Bb-iJ-Q8R"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AgH-2U-HpP" customClass="ReactionsMenuButton" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="210" y="59" width="100" height="38"/>
|
||||
@@ -78,6 +87,9 @@
|
||||
<state key="normal" title="Dislike 😔">
|
||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="dislikeButtonAction:" destination="-1" eventType="touchUpInside" id="vE5-Jn-5WM"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
|
||||
/// Action chosen by the user
|
||||
enum ReactionsMenuViewAction {
|
||||
case toggleReaction(ReactionsMenuReaction)
|
||||
}
|
||||
@@ -38,7 +38,6 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
|
||||
// MARK: - Setup
|
||||
|
||||
init(aggregations: MXAggregations, roomId: String, eventId: String) {
|
||||
|
||||
self.aggregations = aggregations
|
||||
self.roomId = roomId
|
||||
self.eventId = eventId
|
||||
@@ -47,8 +46,36 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
|
||||
self.listenToDataUpdate()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
// MARK: - Public
|
||||
|
||||
func process(viewAction: ReactionsMenuViewAction) {
|
||||
var reaction: ReactionsMenuReaction?
|
||||
var newState: Bool?
|
||||
|
||||
switch viewAction {
|
||||
case .toggleReaction(let menuReaction):
|
||||
reaction = menuReaction
|
||||
|
||||
switch menuReaction {
|
||||
case .agree:
|
||||
newState = !self.isAgreeButtonSelected
|
||||
case .disagree:
|
||||
newState = !self.isDisagreeButtonSelected
|
||||
case .like:
|
||||
newState = !self.isLikeButtonSelected
|
||||
case .dislike:
|
||||
newState = !self.isDislikeButtonSelected
|
||||
}
|
||||
}
|
||||
|
||||
guard let theReaction = reaction, let theNewState = newState else {
|
||||
return
|
||||
}
|
||||
|
||||
self.react(withReaction: theReaction, selected: theNewState)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func resetData() {
|
||||
self.isAgreeButtonSelected = false
|
||||
@@ -64,7 +91,7 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
|
||||
|
||||
self.resetData()
|
||||
reactionCounts.forEach { (reaction) in
|
||||
if let reaction = ReactionsMenuReactions(rawValue: reaction.reaction) {
|
||||
if let reaction = ReactionsMenuReaction(rawValue: reaction.reaction) {
|
||||
switch reaction {
|
||||
case .agree:
|
||||
self.isAgreeButtonSelected = true
|
||||
@@ -78,9 +105,7 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
|
||||
}
|
||||
}
|
||||
|
||||
if let viewDelegate = self.viewDelegate {
|
||||
viewDelegate.reactionsMenuViewModelDidUpdate(self)
|
||||
}
|
||||
self.viewDelegate?.reactionsMenuViewModelDidUpdate(self)
|
||||
}
|
||||
|
||||
private func listenToDataUpdate() {
|
||||
@@ -96,4 +121,34 @@ final class ReactionsMenuViewModel: ReactionsMenuViewModelType {
|
||||
}
|
||||
}
|
||||
|
||||
private func react(withReaction reaction: ReactionsMenuReaction, selected: Bool) {
|
||||
if selected {
|
||||
self.aggregations.sendReaction(reaction.rawValue, toEvent: self.eventId, inRoom: self.roomId, success: {_ in
|
||||
|
||||
}, failure: {(error) in
|
||||
print("[ReactionsMenuViewModel] react: Error: \(error)")
|
||||
})
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
|
||||
self.fakeToggleReaction(reaction: reaction)
|
||||
}
|
||||
|
||||
// TODO: to remove
|
||||
private func fakeToggleReaction(reaction: ReactionsMenuReaction) {
|
||||
switch reaction {
|
||||
case .agree:
|
||||
isAgreeButtonSelected = !isDislikeButtonSelected
|
||||
case .disagree:
|
||||
isDisagreeButtonSelected = !isDisagreeButtonSelected
|
||||
case .like:
|
||||
isLikeButtonSelected = !isLikeButtonSelected
|
||||
case .dislike:
|
||||
isDislikeButtonSelected = !isDislikeButtonSelected
|
||||
}
|
||||
|
||||
self.viewDelegate?.reactionsMenuViewModelDidUpdate(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ protocol ReactionsMenuViewModelType {
|
||||
var isLikeButtonSelected: Bool { get }
|
||||
var isDislikeButtonSelected: Bool { get }
|
||||
|
||||
|
||||
var viewDelegate: ReactionsMenuViewModelDelegate? { get set }
|
||||
var coordinatorDelegate: ReactionsMenuViewModelCoordinatorDelegate? { get set }
|
||||
|
||||
func process(viewAction: ReactionsMenuViewAction)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user