Skip to content
Snippets Groups Projects
BubbleBuilder.swift 15 KiB
Newer Older
Bruno Muniz's avatar
Bruno Muniz committed
import UIKit
import Shared
import XXModels
Bruno Muniz's avatar
Bruno Muniz committed

final class Bubbler {
    static func build(
        audioBubble: AudioMessageView,
        with item: Message
Bruno Muniz's avatar
Bruno Muniz committed
    ) {
        audioBubble.dateLabel.text = item.date.asHoursAndMinutes()

        switch item.status {
        case .received:
Ahmed Shehata's avatar
Ahmed Shehata committed
            audioBubble.lockerImageView.removeFromSuperview()
Bruno Muniz's avatar
Bruno Muniz committed
            audioBubble.backgroundColor = Asset.neutralWhite.color
            audioBubble.dateLabel.textColor = Asset.neutralDisabled.color
            audioBubble.progressLabel.textColor = Asset.neutralDisabled.color
        case .receiving:
Bruno Muniz's avatar
Bruno Muniz committed
            audioBubble.backgroundColor = Asset.neutralWhite.color
            audioBubble.dateLabel.textColor = Asset.neutralDisabled.color
            audioBubble.progressLabel.textColor = Asset.neutralDisabled.color
        case .sendingTimedOut:
            audioBubble.backgroundColor = Asset.accentWarning.color
            audioBubble.dateLabel.textColor = Asset.neutralWhite.color
            audioBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .sendingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            audioBubble.backgroundColor = Asset.accentDanger.color
            audioBubble.dateLabel.textColor = Asset.neutralWhite.color
            audioBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .sent:
            audioBubble.backgroundColor = Asset.brandBubble.color
            audioBubble.dateLabel.textColor = Asset.neutralWhite.color
            audioBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .sending:
Bruno Muniz's avatar
Bruno Muniz committed
            audioBubble.backgroundColor = Asset.brandBubble.color
            audioBubble.dateLabel.textColor = Asset.neutralWhite.color
            audioBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            audioBubble.backgroundColor = Asset.accentWarning.color
            audioBubble.dateLabel.textColor = Asset.neutralWhite.color
            audioBubble.progressLabel.textColor = Asset.neutralWhite.color
Bruno Muniz's avatar
Bruno Muniz committed
        }
    }

    static func build(
        imageBubble: ImageMessageView,
        with message: Message,
        with transfer: FileTransfer
Bruno Muniz's avatar
Bruno Muniz committed
    ) {
        imageBubble.progressLabel.text = String(format: "%.1f%%", transfer.progress * 100)
        imageBubble.dateLabel.text = message.date.asHoursAndMinutes()
Bruno Muniz's avatar
Bruno Muniz committed

        switch message.status {
        case .received:
Ahmed Shehata's avatar
Ahmed Shehata committed
            imageBubble.lockerImageView.removeFromSuperview()
Bruno Muniz's avatar
Bruno Muniz committed
            imageBubble.backgroundColor = Asset.neutralWhite.color
            imageBubble.dateLabel.textColor = Asset.neutralDisabled.color
            imageBubble.progressLabel.textColor = Asset.neutralDisabled.color
        case .receiving:
Bruno Muniz's avatar
Bruno Muniz committed
            imageBubble.backgroundColor = Asset.neutralWhite.color
            imageBubble.dateLabel.textColor = Asset.neutralDisabled.color
            imageBubble.progressLabel.textColor = Asset.neutralDisabled.color
        case .sendingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            imageBubble.backgroundColor = Asset.accentDanger.color
            imageBubble.dateLabel.textColor = Asset.neutralWhite.color
            imageBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .sendingTimedOut:
            imageBubble.backgroundColor = Asset.accentWarning.color
            imageBubble.dateLabel.textColor = Asset.neutralWhite.color
            imageBubble.progressLabel.textColor = Asset.neutralWhite.color
Bruno Muniz's avatar
Bruno Muniz committed
        case .sent:
            imageBubble.backgroundColor = Asset.brandBubble.color
            imageBubble.dateLabel.textColor = Asset.neutralWhite.color
            imageBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .sending:
Bruno Muniz's avatar
Bruno Muniz committed
            imageBubble.backgroundColor = Asset.brandBubble.color
            imageBubble.dateLabel.textColor = Asset.neutralWhite.color
            imageBubble.progressLabel.textColor = Asset.neutralWhite.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            imageBubble.backgroundColor = Asset.accentWarning.color
            imageBubble.dateLabel.textColor = Asset.neutralWhite.color
            imageBubble.progressLabel.textColor = Asset.neutralWhite.color
Bruno Muniz's avatar
Bruno Muniz committed
        }
    }

    static func build(
        bubble: StackMessageView,
        with item: Message
Bruno Muniz's avatar
Bruno Muniz committed
    ) {
        bubble.textView.text = item.text
Bruno Muniz's avatar
Bruno Muniz committed
        bubble.senderLabel.removeFromSuperview()
        bubble.dateLabel.text = item.date.asHoursAndMinutes()

        let roundButtonColor: UIColor

        switch item.status {
        case .received, .receiving:
Ahmed Shehata's avatar
Ahmed Shehata committed
            bubble.lockerImageView.removeFromSuperview()
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.backgroundColor = Asset.neutralWhite.color
            bubble.textView.textColor = Asset.neutralActive.color
            bubble.dateLabel.textColor = Asset.neutralDisabled.color
            roundButtonColor = Asset.neutralDisabled.color
            bubble.revertBottomStackOrder()
        case .sendingTimedOut:
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .sendingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.backgroundColor = Asset.accentDanger.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .sent:
            bubble.backgroundColor = Asset.brandBubble.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .sending:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.backgroundColor = Asset.brandBubble.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
Bruno Muniz's avatar
Bruno Muniz committed
        }

        let attrString = NSAttributedString(
            string: "show mix",
            attributes: [
                .underlineStyle: NSUnderlineStyle.single.rawValue,
                .underlineColor: roundButtonColor,
                .foregroundColor: roundButtonColor,
                .font: Fonts.Mulish.regular.font(size: 12.0) as Any
            ]
        )
Ahmed Shehata's avatar
Ahmed Shehata committed

Bruno Muniz's avatar
Bruno Muniz committed
        bubble.roundButton.setAttributedTitle(attrString, for: .normal)
    }

    static func buildReply(
        bubble: ReplyStackMessageView,
        with item: Message,
        reply: (contactTitle: String, messageText: String)
Bruno Muniz's avatar
Bruno Muniz committed
    ) {
        bubble.dateLabel.text = item.date.asHoursAndMinutes()
        bubble.textView.text = item.text
Bruno Muniz's avatar
Bruno Muniz committed

        bubble.replyView.message.text = reply.messageText
        bubble.replyView.title.text = reply.contactTitle
Bruno Muniz's avatar
Bruno Muniz committed

        let roundButtonColor: UIColor

        switch item.status {
        case .received, .receiving:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.neutralWhite.color
            bubble.textView.textColor = Asset.neutralActive.color
            bubble.dateLabel.textColor = Asset.neutralDisabled.color
            roundButtonColor = Asset.neutralDisabled.color
            bubble.replyView.container.backgroundColor = Asset.brandDefault.color
            bubble.replyView.space.backgroundColor = Asset.brandPrimary.color
            bubble.revertBottomStackOrder()
        case .sendingTimedOut:
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        case .sendingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.accentDanger.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        case .sent, .sending:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.backgroundColor = Asset.brandBubble.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
Bruno Muniz's avatar
Bruno Muniz committed
        }

        let attrString = NSAttributedString(
            string: "show mix",
            attributes: [
                .underlineStyle: NSUnderlineStyle.single.rawValue,
                .underlineColor: roundButtonColor,
                .foregroundColor: roundButtonColor,
                .font: Fonts.Mulish.regular.font(size: 12.0) as Any
            ]
        )
        bubble.roundButton.setAttributedTitle(attrString, for: .normal)
    }

    static func buildReplyGroup(
        bubble: ReplyStackMessageView,
        with item: Message,
        reply: (contactTitle: String, messageText: String),
        sender: String
    ) {
        bubble.dateLabel.text = item.date.asHoursAndMinutes()
        bubble.textView.text = item.text

        bubble.replyView.message.text = reply.messageText
        bubble.replyView.title.text = reply.contactTitle

        let roundButtonColor: UIColor

        switch item.status {
        case .received, .receiving:
            bubble.senderLabel.text = sender
            bubble.backgroundColor = Asset.neutralWhite.color
            bubble.textView.textColor = Asset.neutralActive.color
            bubble.dateLabel.textColor = Asset.neutralDisabled.color
            roundButtonColor = Asset.neutralDisabled.color
            bubble.replyView.container.backgroundColor = Asset.brandDefault.color
            bubble.replyView.space.backgroundColor = Asset.brandPrimary.color
            bubble.lockerImageView.removeFromSuperview()
            bubble.revertBottomStackOrder()
        case .sendingFailed, .sendingTimedOut:
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.accentDanger.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        case .sent, .sending:
            bubble.senderLabel.removeFromSuperview()
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.backgroundColor = Asset.brandBubble.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
            bubble.replyView.space.backgroundColor = Asset.neutralWhite.color
            bubble.replyView.container.backgroundColor = Asset.brandLight.color
        }

        let attrString = NSAttributedString(
            string: "show mix",
            attributes: [
                .underlineStyle: NSUnderlineStyle.single.rawValue,
                .underlineColor: roundButtonColor,
                .foregroundColor: roundButtonColor,
                .font: Fonts.Mulish.regular.font(size: 12.0) as Any
            ]
        )

        bubble.roundButton.setAttributedTitle(attrString, for: .normal)
    }

    static func buildGroup(
        bubble: StackMessageView,
        with item: Message,
        with senderName: String
    ) {
        bubble.textView.text = item.text
        bubble.dateLabel.text = item.date.asHoursAndMinutes()

        let roundButtonColor: UIColor

        switch item.status {
        case .received, .receiving:
            bubble.senderLabel.text = senderName
            bubble.backgroundColor = Asset.neutralWhite.color
            bubble.textView.textColor = Asset.neutralActive.color
            bubble.dateLabel.textColor = Asset.neutralDisabled.color
            roundButtonColor = Asset.neutralDisabled.color
            bubble.lockerImageView.removeFromSuperview()
            bubble.revertBottomStackOrder()
        case .sendingFailed, .sendingTimedOut:
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.accentDanger.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .sent, .sending:
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.brandBubble.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        case .receivingFailed:
Bruno Muniz's avatar
Bruno Muniz committed
            bubble.senderLabel.removeFromSuperview()
            bubble.backgroundColor = Asset.accentWarning.color
            bubble.textView.textColor = Asset.neutralWhite.color
            bubble.dateLabel.textColor = Asset.neutralWhite.color
            roundButtonColor = Asset.neutralWhite.color
        }

        let attrString = NSAttributedString(
            string: "show mix",
            attributes: [
                .underlineStyle: NSUnderlineStyle.single.rawValue,
                .underlineColor: roundButtonColor,
                .foregroundColor: roundButtonColor,
                .font: Fonts.Mulish.regular.font(size: 12.0) as Any
            ]
        )

        bubble.roundButton.setAttributedTitle(attrString, for: .normal)
    }


Bruno Muniz's avatar
Bruno Muniz committed
}