Skip to content

Commit f21fd77

Browse files
authored
Merge pull request #2247 from nextcloud/feat/noid/autocompletion-to-swift
feat: Move AutoCompletionTableViewCell to swift
2 parents 85926e5 + 5340196 commit f21fd77

File tree

7 files changed

+124
-155
lines changed

7 files changed

+124
-155
lines changed

NextcloudTalk.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
492492
membershipExceptions = (
493493
CalendarEvent.swift,
494-
"Chat cells/AutoCompletionTableViewCell.m",
494+
"Chat cells/AutoCompletionTableViewCell.swift",
495495
"Chat cells/EmojiUtils.swift",
496496
"Chat cells/SwiftMarkdownObjCBridge.swift",
497497
"Chat views/NCChatTitleView.m",

NextcloudTalk/Chat/Chat cells/AutoCompletionTableViewCell.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

NextcloudTalk/Chat/Chat cells/AutoCompletionTableViewCell.m

Lines changed: 0 additions & 123 deletions
This file was deleted.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//
2+
// SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
//
5+
6+
class AutoCompletionTableViewCell: UITableViewCell {
7+
8+
public static let identifier = "AutoCompletionCellIdentifier"
9+
public static let cellHeight = 50.0
10+
11+
private let avatarHeight = 30.0
12+
13+
public lazy var titleLabel = {
14+
let label = UILabel()
15+
label.translatesAutoresizingMaskIntoConstraints = false
16+
label.backgroundColor = .clear
17+
label.isUserInteractionEnabled = false
18+
label.numberOfLines = 1
19+
label.font = .preferredFont(forTextStyle: .body)
20+
label.textColor = .label
21+
22+
return label
23+
}()
24+
25+
public lazy var avatarButton = {
26+
let button = AvatarButton(frame: .init(x: 0, y: 0, width: avatarHeight, height: avatarHeight))
27+
button.translatesAutoresizingMaskIntoConstraints = false
28+
button.backgroundColor = NCAppBranding.placeholderColor()
29+
button.layer.cornerRadius = avatarHeight / 2
30+
button.layer.masksToBounds = true
31+
button.showsMenuAsPrimaryAction = true
32+
button.imageView?.contentMode = .scaleToFill
33+
34+
return button
35+
}()
36+
37+
private lazy var userStatusImageView = {
38+
let imageView = UIImageView(frame: .init(x: 0, y: 0, width: 12, height: 12))
39+
imageView.translatesAutoresizingMaskIntoConstraints = false
40+
imageView.isUserInteractionEnabled = false
41+
42+
return imageView
43+
}()
44+
45+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
46+
super.init(style: style, reuseIdentifier: reuseIdentifier)
47+
48+
self.backgroundColor = .secondarySystemBackground
49+
self.configureSubviews()
50+
}
51+
52+
required init?(coder: NSCoder) {
53+
fatalError("init(coder:) has not been implemented")
54+
}
55+
56+
override func prepareForReuse() {
57+
super.prepareForReuse()
58+
59+
self.titleLabel.font = .preferredFont(forTextStyle: .body)
60+
self.titleLabel.text = ""
61+
62+
self.avatarButton.cancelCurrentRequest()
63+
self.avatarButton.setImage(nil, for: .normal)
64+
65+
self.userStatusImageView.image = nil
66+
self.userStatusImageView.backgroundColor = .clear
67+
}
68+
69+
func configureSubviews() {
70+
self.contentView.addSubview(self.avatarButton)
71+
self.contentView.addSubview(self.userStatusImageView)
72+
self.contentView.addSubview(self.titleLabel)
73+
74+
let views = [
75+
"avatarButton": self.avatarButton,
76+
"userStatusImageView": self.userStatusImageView,
77+
"titleLabel": self.titleLabel
78+
]
79+
80+
let metrics = [
81+
"avatarSize": avatarHeight,
82+
"right": 10
83+
]
84+
85+
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-right-[avatarButton(avatarSize)]-right-[titleLabel]-right-|", metrics: metrics, views: views))
86+
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[titleLabel]|", metrics: metrics, views: views))
87+
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-32-[userStatusImageView(12)]-(>=0)-|", metrics: metrics, views: views))
88+
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-32-[userStatusImageView(12)]-(>=0)-|", metrics: metrics, views: views))
89+
self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-right-[avatarButton(avatarSize)]-(>=0)-|", metrics: metrics, views: views))
90+
}
91+
92+
public func setUserStatus(_ status: String) {
93+
var statusImage: UIImage?
94+
95+
if status == "online" {
96+
statusImage = NCUserStatus.getOnlineSFIcon()
97+
} else if status == "away" {
98+
statusImage = NCUserStatus.getAwaySFIcon()
99+
} else if status == "busy" {
100+
statusImage = NCUserStatus.getBusySFIcon()
101+
} else if status == "dnd" {
102+
statusImage = NCUserStatus.getDoNotDisturbSFIcon()
103+
}
104+
105+
if let statusImage = NCUtils.renderAspectImage(image: statusImage, ofSize: .init(width: 10, height: 10), centerImage: false) {
106+
userStatusImageView.image = statusImage
107+
userStatusImageView.contentMode = .center
108+
userStatusImageView.layer.cornerRadius = 6
109+
userStatusImageView.clipsToBounds = true
110+
111+
// When a background color is set directly to the cell it seems that there is no background configuration.
112+
// In this class, even when no background color is set, the background configuration is nil.
113+
userStatusImageView.backgroundColor = self.backgroundColor ?? self.backgroundConfiguration?.backgroundColor
114+
}
115+
}
116+
117+
}

NextcloudTalk/Chat/InputbarViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ import UIKit
148148
self.textInputbar.setShadowImage(UIImage(), forToolbarPosition: .any)
149149
self.textView.delegate = self
150150

151-
self.autoCompletionView.register(AutoCompletionTableViewCell.self, forCellReuseIdentifier: AutoCompletionCellIdentifier)
151+
self.autoCompletionView.register(AutoCompletionTableViewCell.self, forCellReuseIdentifier: AutoCompletionTableViewCell.identifier)
152152
self.registerPrefixes(forAutoCompletion: ["@"])
153153

154154
self.autoCompletionView.backgroundColor = .systemBackground
@@ -247,7 +247,7 @@ import UIKit
247247
}
248248

249249
public override func heightForAutoCompletionView() -> CGFloat {
250-
return kAutoCompletionCellHeight * CGFloat(self.autocompletionUsers.count) + (self.autoCompletionView.tableHeaderView?.frame.height ?? 0)
250+
return AutoCompletionTableViewCell.cellHeight * CGFloat(self.autocompletionUsers.count) + (self.autoCompletionView.tableHeaderView?.frame.height ?? 0)
251251
}
252252

253253
func showSuggestions(for string: String) {
@@ -352,9 +352,9 @@ import UIKit
352352
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
353353
guard tableView == self.autoCompletionView,
354354
indexPath.row < self.autocompletionUsers.count,
355-
let cell = self.autoCompletionView.dequeueReusableCell(withIdentifier: AutoCompletionCellIdentifier) as? AutoCompletionTableViewCell
355+
let cell = self.autoCompletionView.dequeueReusableCell(withIdentifier: AutoCompletionTableViewCell.identifier) as? AutoCompletionTableViewCell
356356
else {
357-
return AutoCompletionTableViewCell(style: .default, reuseIdentifier: AutoCompletionCellIdentifier)
357+
return AutoCompletionTableViewCell(style: .default, reuseIdentifier: AutoCompletionTableViewCell.identifier)
358358
}
359359

360360
let suggestion = self.autocompletionUsers[indexPath.row]
@@ -388,7 +388,7 @@ import UIKit
388388
cell.layer.borderWidth = 0.0
389389
}
390390

391-
cell.accessibilityIdentifier = AutoCompletionCellIdentifier
391+
cell.accessibilityIdentifier = AutoCompletionTableViewCell.identifier
392392
return cell
393393
}
394394

@@ -412,7 +412,7 @@ import UIKit
412412
}
413413

414414
public override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
415-
return kAutoCompletionCellHeight
415+
return AutoCompletionTableViewCell.cellHeight
416416
}
417417

418418
// MARK: - TextView functiosn

NextcloudTalk/NextcloudTalk-Bridging-Header-Extensions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#import "NCMessageTextView.h"
2121
#import "ReplyMessageView.h"
2222
#import "NCSettingsController.h"
23-
#import "AutoCompletionTableViewCell.h"
2423
#import "NCKeyChainController.h"
2524
#import "CCCertificate.h"
2625

NextcloudTalk/NextcloudTalk-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#import "ShareLocationViewController.h"
6464
#import "VoiceMessageTranscribeViewController.h"
6565
#import "AppDelegate.h"
66-
#import "AutoCompletionTableViewCell.h"
6766
#import "NCKeyChainController.h"
6867
#import "NCIntentController.h"
6968
#import "CCCertificate.h"

0 commit comments

Comments
 (0)