mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-05 23:47:44 +02:00
MESSENGER-2762 Initial Merge
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2021 BWI GmbH
|
||||
*
|
||||
* 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
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class ContentScannerStatus: ObservableObject, ContentScannerContentDelegate {
|
||||
|
||||
var theme: Theme!
|
||||
|
||||
@Published var scanStatus = ""
|
||||
@Published var fileName = ""
|
||||
@Published var statusImagePath = ""
|
||||
@Published var progressing = false
|
||||
|
||||
@Published var scanStatusVisibility = false
|
||||
|
||||
@Published var backgroundColor: UIColor = .white
|
||||
@Published var tintColor: UIColor = .black
|
||||
@Published var statusColor: UIColor = .black
|
||||
|
||||
func render(with viewData: ContentScannerStatusViewData) {
|
||||
|
||||
let scanStatus = viewData.scanStatus
|
||||
|
||||
switch scanStatus {
|
||||
case .inProgress:
|
||||
statusImagePath = ""
|
||||
case .infected:
|
||||
statusImagePath = Asset.Images.fileScanInfected.name
|
||||
case .unknown:
|
||||
statusImagePath = Asset.Images.error.name
|
||||
case .trusted:
|
||||
statusImagePath = Asset.Images.fileAttachmentIcon.name
|
||||
@unknown default:
|
||||
statusImagePath = Asset.Images.fileAttachmentIcon.name
|
||||
}
|
||||
|
||||
self.fileName = viewData.attachment
|
||||
self.scanStatus = self.scanStatusMessage(for: viewData.scanStatus)
|
||||
|
||||
self.progressing = statusImagePath.isEmpty
|
||||
|
||||
self.scanStatusVisibility = (scanStatus == .infected) ? false : true
|
||||
|
||||
self.backgroundColor = (scanStatus == .infected) ? self.theme.textPrimaryColor : self.theme.baseColor
|
||||
self.tintColor = (scanStatus != .infected) ? self.theme.backgroundColor : self.theme.textSecondaryColor
|
||||
self.statusColor = (scanStatus != .infected) ? self.theme.textPrimaryColor : self.theme.textSecondaryColor
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2021 BWI GmbH
|
||||
*
|
||||
* 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
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
@objcMembers
|
||||
class ContentScannerStatusCell: ContentScannerBaseCell {
|
||||
|
||||
private var tapRecognizer: UITapGestureRecognizer?
|
||||
|
||||
required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
let view = self.setupInnerContentView()
|
||||
self.setupTapRecognizer(view)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func setupInnerContentView() -> UIView {
|
||||
let innerContent = ContentScannerStatus()
|
||||
|
||||
let controller = UIHostingController(rootView:ContentScannerStatusContentView(scanStatus: innerContent))
|
||||
|
||||
innerContent.theme = ThemeService.shared().theme
|
||||
|
||||
controller.view.backgroundColor = .clear
|
||||
//self.bubbleCellContentView?.innerContentView.addSubview(controller.view)
|
||||
self.bubbleCellContentView?.innerContentView.vc_addSubViewMatchingParentSafeArea(controller.view)
|
||||
self.innerContent = innerContent
|
||||
|
||||
return controller.view
|
||||
}
|
||||
|
||||
override func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
||||
|
||||
// Recognize touch only if scan status is trusted
|
||||
guard gestureRecognizer == self.tapRecognizer, self.scanStatusViewData?.scanStatus == .trusted else {
|
||||
return false
|
||||
}
|
||||
|
||||
return super.gestureRecognizer(gestureRecognizer, shouldReceive: touch)
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func setupTapRecognizer(_ view: UIView) {
|
||||
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
|
||||
tapRecognizer.delegate = self
|
||||
view.addGestureRecognizer(tapRecognizer)
|
||||
self.tapRecognizer = tapRecognizer
|
||||
}
|
||||
|
||||
@objc private func handleTap(_ gestureRecognizer: UITapGestureRecognizer) {
|
||||
guard let scanStatusViewData = self.scanStatusViewData, let delegate = self.delegate else {
|
||||
return
|
||||
}
|
||||
|
||||
if scanStatusViewData.scanStatus == .trusted {
|
||||
delegate.cell(self, didRecognizeAction: kMXKRoomBubbleCellTapOnAttachmentView, userInfo: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2021 BWI GmbH
|
||||
*
|
||||
* 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 SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct ContentScannerStatusContentView: View {
|
||||
@ObservedObject var scanStatus: ContentScannerStatus
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack {
|
||||
ZStack {
|
||||
if scanStatus.progressing {
|
||||
ProgressView()
|
||||
} else {
|
||||
Image(scanStatus.statusImagePath)
|
||||
}
|
||||
}
|
||||
.background(Color(scanStatus.backgroundColor))
|
||||
|
||||
Text(scanStatus.fileName)
|
||||
.font(.system(size: 15))
|
||||
.foregroundColor(Color(scanStatus.statusColor))
|
||||
|
||||
}
|
||||
.background(Color.clear)
|
||||
Text(scanStatus.scanStatus)
|
||||
.font(.system(size: 12))
|
||||
.foregroundColor(Color(scanStatus.tintColor))
|
||||
}
|
||||
.frame(
|
||||
maxWidth: .infinity,
|
||||
maxHeight: .infinity,
|
||||
alignment: .topLeading
|
||||
)
|
||||
.background(Color.clear)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct ContentScannerScanStatusContentView_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
let scanStatus = ContentScannerStatus()
|
||||
ContentScannerStatusContentView(scanStatus:scanStatus)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user