Skip to content

Commit

Permalink
Merge pull request #1846 from nextcloud/text-view-cells-with-dynamic-…
Browse files Browse the repository at this point in the history
…font

Add new TextFieldTableViewCell and TextViewTableViewCell that use a dynamic font
  • Loading branch information
SystemKeeper authored Oct 30, 2024
2 parents b3e0e8b + 5556b5c commit 3019dcf
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 295 deletions.
24 changes: 8 additions & 16 deletions NextcloudTalk.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions NextcloudTalk/PollCreationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import UIKit
}

override func viewDidAppear(_ animated: Bool) {
if let questionCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: PollCreationSection.kPollCreationSectionQuestion.rawValue)) as? TextInputTableViewCell {
if let questionCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: PollCreationSection.kPollCreationSectionQuestion.rawValue)) as? TextFieldTableViewCell {
questionCell.textField.becomeFirstResponder()
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ import UIKit
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.keyboardDismissMode = UIScrollView.KeyboardDismissMode.onDrag
self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: TextFieldTableViewCell.identifier)
}

// MARK: - Table view data source
Expand Down Expand Up @@ -150,7 +150,7 @@ import UIKit
tableView.beginUpdates()
tableView.insertRows(at: [indexPath], with: .automatic)
tableView.endUpdates()
if let optionCell = self.tableView.cellForRow(at: indexPath) as? TextInputTableViewCell {
if let optionCell = self.tableView.cellForRow(at: indexPath) as? TextFieldTableViewCell {
optionCell.textField.becomeFirstResponder()
}
} else {
Expand Down Expand Up @@ -192,41 +192,40 @@ import UIKit
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)
textInputCell.textField.delegate = self
textInputCell.textField.autocapitalizationType = .sentences
let actionCell = tableView.dequeueReusableCell(withIdentifier: "PollSettingCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "PollSettingCellIdentifier")

if indexPath.section == PollCreationSection.kPollCreationSectionQuestion.rawValue {
let textInputCell: TextFieldTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextFieldTableViewCell.identifier)
textInputCell.textField.delegate = self
textInputCell.textField.placeholder = NSLocalizedString("Ask a question", comment: "")
textInputCell.textField.tag = kQuestionTextFieldTag
textInputCell.textField.text = question
return textInputCell
} else if indexPath.section == PollCreationSection.kPollCreationSectionOptions.rawValue {
if indexPath.row == options.count {
let actionCell = tableView.dequeueOrCreateCell(withIdentifier: "PollSettingCellIdentifier")
actionCell.textLabel?.text = NSLocalizedString("Add answer", comment: "")
return actionCell
} else if indexPath.row < options.count {
let textInputCell: TextFieldTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextFieldTableViewCell.identifier)
textInputCell.textField.delegate = self
textInputCell.textField.placeholder = NSLocalizedString("Answer", comment: "") + " " + String(indexPath.row + 1)
textInputCell.textField.tag = indexPath.row
textInputCell.textField.text = options[indexPath.row]
return textInputCell
}
} else if indexPath.section == PollCreationSection.kPollCreationSectionSettings.rawValue {
if indexPath.row == PollSetting.kPollSettingPrivate.rawValue {
let actionCell = tableView.dequeueOrCreateCell(withIdentifier: "PollSettingCellIdentifier")
actionCell.textLabel?.text = NSLocalizedString("Private poll", comment: "")
actionCell.accessoryView = privateSwitch
return actionCell
} else if indexPath.row == PollSetting.kPollSettingMultiple.rawValue {
let actionCell = tableView.dequeueOrCreateCell(withIdentifier: "PollSettingCellIdentifier")
actionCell.textLabel?.text = NSLocalizedString("Multiple answers", comment: "")
actionCell.accessoryView = multipleSwitch
return actionCell
}
return actionCell
}

return actionCell
return UITableViewCell()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
29 changes: 12 additions & 17 deletions NextcloudTalk/RoomAvatarInfoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum RoomAvatarInfoSection: Int {
UITextFieldDelegate,
AvatarEditViewDelegate,
EmojiAvatarPickerViewControllerDelegate,
RoomDescriptionTableViewCellDelegate,
TextViewTableViewCellDelegate,
TOCropViewControllerDelegate {

var room: NCRoom
Expand Down Expand Up @@ -69,8 +69,8 @@ enum RoomAvatarInfoSection: Int {
self.navigationItem.compactAppearance = appearance
self.navigationItem.scrollEdgeAppearance = appearance

self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(UINib(nibName: RoomDescriptionTableViewCell.nibName, bundle: nil), forCellReuseIdentifier: RoomDescriptionTableViewCell.identifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: TextFieldTableViewCell.identifier)
self.tableView.register(TextViewTableViewCell.self, forCellReuseIdentifier: TextViewTableViewCell.identifier)
self.tableView.tableHeaderView = self.headerView

self.modifyingView.color = NCAppBranding.themeTextColor()
Expand Down Expand Up @@ -126,27 +126,22 @@ enum RoomAvatarInfoSection: Int {
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)

if indexPath.section == RoomAvatarInfoSection.kRoomNameSection.rawValue {
let textInputCell: TextFieldTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextFieldTableViewCell.identifier)
textInputCell.textField.delegate = self
textInputCell.textField.text = self.room.displayName
textInputCell.textField.autocapitalizationType = .sentences
textInputCell.selectionStyle = .none
return textInputCell
} else if indexPath.section == RoomAvatarInfoSection.kRoomDescriptionSection.rawValue {
let descriptionCell = tableView.dequeueReusableCell(withIdentifier: RoomDescriptionTableViewCell.identifier) as? RoomDescriptionTableViewCell ??
RoomDescriptionTableViewCell(style: .default, reuseIdentifier: RoomDescriptionTableViewCell.identifier)
descriptionCell.textView?.text = self.room.roomDescription
descriptionCell.textView?.isEditable = true
let descriptionCell: TextViewTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextViewTableViewCell.identifier)
descriptionCell.textView.text = self.room.roomDescription
descriptionCell.textView.isEditable = true
descriptionCell.delegate = self
descriptionCell.characterLimit = 500
descriptionCell.selectionStyle = .none
return descriptionCell
}

return textInputCell
return UITableViewCell()
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
Expand Down Expand Up @@ -274,19 +269,19 @@ enum RoomAvatarInfoSection: Int {
self.dismiss(animated: true, completion: nil)
}

// MARK: - RoomDescriptionTableViewCellDelegate
// MARK: - TextViewTableViewCellDelegate

func roomDescriptionCellTextViewDidChange(_ cell: RoomDescriptionTableViewCell) {
func textViewCellTextViewDidChange(_ cell: TextViewTableViewCell) {
DispatchQueue.main.async {
self.tableView?.beginUpdates()
self.tableView?.endUpdates()

self.currentDescription = cell.textView?.text ?? ""
self.currentDescription = cell.textView.text ?? ""
self.descriptionHeaderView.button.isHidden = self.currentDescription == self.room.roomDescription
}
}

func roomDescriptionCellDidExceedLimit(_ cell: RoomDescriptionTableViewCell) {
func textViewCellDidExceedCharacterLimit(_ cell: TextViewTableViewCell) {
NotificationPresenter.shared().present(
text: NSLocalizedString("Description cannot be longer than 500 characters", comment: ""),
dismissAfterDelay: 3.0,
Expand Down
43 changes: 19 additions & 24 deletions NextcloudTalk/RoomCreationTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum RoomVisibilityOption: Int {
AvatarEditViewDelegate,
AddParticipantsTableViewControllerDelegate,
EmojiAvatarPickerViewControllerDelegate,
RoomDescriptionTableViewCellDelegate,
TextViewTableViewCellDelegate,
TOCropViewControllerDelegate {

var account: TalkAccount
Expand Down Expand Up @@ -90,8 +90,8 @@ enum RoomVisibilityOption: Int {
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.cancelButtonPressed))
self.navigationItem.leftBarButtonItem?.tintColor = NCAppBranding.themeTextColor()

self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(UINib(nibName: RoomDescriptionTableViewCell.nibName, bundle: nil), forCellReuseIdentifier: RoomDescriptionTableViewCell.identifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: TextFieldTableViewCell.identifier)
self.tableView.register(TextViewTableViewCell.self, forCellReuseIdentifier: TextViewTableViewCell.identifier)
self.tableView.register(UINib(nibName: kContactsTableCellNibName, bundle: nil), forCellReuseIdentifier: kContactCellIdentifier)
self.tableView.tableHeaderView = self.headerView
self.tableView.keyboardDismissMode = .onDrag
Expand Down Expand Up @@ -426,36 +426,31 @@ enum RoomVisibilityOption: Int {
let roomCreationSection = sections[indexPath.section]

if roomCreationSection == RoomCreationSection.kRoomNameSection.rawValue {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)
textInputCell.textField.autocapitalizationType = .sentences
let textInputCell: TextFieldTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextFieldTableViewCell.identifier)
textInputCell.textField.tag = kRoomNameTextFieldTag
textInputCell.textField.delegate = self
textInputCell.textField.text = self.roomName
textInputCell.textField.becomeFirstResponder()
textInputCell.selectionStyle = .none
return textInputCell
} else if roomCreationSection == RoomCreationSection.kRoomDescriptionSection.rawValue {
let descriptionCell = tableView.dequeueReusableCell(withIdentifier: RoomDescriptionTableViewCell.identifier) as? RoomDescriptionTableViewCell ??
RoomDescriptionTableViewCell(style: .default, reuseIdentifier: RoomDescriptionTableViewCell.identifier)
descriptionCell.textView?.text = self.roomDescription
descriptionCell.textView?.isEditable = true
let descriptionCell: TextViewTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: TextViewTableViewCell.identifier)
descriptionCell.textView.text = self.roomDescription
descriptionCell.textView.isEditable = true
descriptionCell.delegate = self
descriptionCell.characterLimit = 500
descriptionCell.selectionStyle = .none
return descriptionCell
} else if roomCreationSection == RoomCreationSection.kRoomParticipantsSection.rawValue {
if self.roomParticipants.isEmpty {
let addParticipantCell = tableView.dequeueReusableCell(withIdentifier: "AddParticipantCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "AllowGuestsCellIdentifier")
let addParticipantCell = tableView.dequeueOrCreateCell(withIdentifier: "AddParticipantCellIdentifier")
addParticipantCell.textLabel?.text = NSLocalizedString("Add participants", comment: "")
addParticipantCell.imageView?.image = UIImage(systemName: "person.badge.plus")
addParticipantCell.imageView?.tintColor = .secondaryLabel
addParticipantCell.imageView?.contentMode = .scaleAspectFit
return addParticipantCell
} else {
let participant = self.roomParticipants[indexPath.row]
let participantCell = tableView.dequeueReusableCell(withIdentifier: kContactCellIdentifier) as? ContactsTableViewCell ??
ContactsTableViewCell(style: .default, reuseIdentifier: kContactCellIdentifier)
let participantCell: ContactsTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: kContactCellIdentifier)

participantCell.labelTitle.text = participant.name

Expand All @@ -470,27 +465,27 @@ enum RoomVisibilityOption: Int {
var roomVisibilityOptionCell = UITableViewCell()
switch option {
case RoomVisibilityOption.kAllowGuestsOption.rawValue:
roomVisibilityOptionCell = tableView.dequeueReusableCell(withIdentifier: "AllowGuestsCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "AllowGuestsCellIdentifier")
roomVisibilityOptionCell = tableView.dequeueOrCreateCell(withIdentifier: "AllowGuestsCellIdentifier")
roomVisibilityOptionCell.textLabel?.text = NSLocalizedString("Allow guests", comment: "")
let optionSwicth = UISwitch()
optionSwicth.isOn = self.isPublic
optionSwicth.addTarget(self, action: #selector(allowGuestValueChanged(_:)), for: .valueChanged)
roomVisibilityOptionCell.accessoryView = optionSwicth
roomVisibilityOptionCell.imageView?.image = UIImage(systemName: "link")
case RoomVisibilityOption.kPasswordProtectionOption.rawValue:
roomVisibilityOptionCell = tableView.dequeueReusableCell(withIdentifier: "SetPasswordCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "SetPasswordCellIdentifier")
roomVisibilityOptionCell = tableView.dequeueOrCreateCell(withIdentifier: "SetPasswordCellIdentifier")
roomVisibilityOptionCell.textLabel?.text = self.roomPassword.isEmpty ? NSLocalizedString("Set password", comment: "") : NSLocalizedString("Change password", comment: "")
roomVisibilityOptionCell.imageView?.image = self.roomPassword.isEmpty ? UIImage(systemName: "lock.open") : UIImage(systemName: "lock")
case RoomVisibilityOption.kOpenConversationOption.rawValue:
roomVisibilityOptionCell = tableView.dequeueReusableCell(withIdentifier: "OpenConversationCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "OpenConversationCellIdentifier")
roomVisibilityOptionCell = tableView.dequeueOrCreateCell(withIdentifier: "OpenConversationCellIdentifier")
roomVisibilityOptionCell.textLabel?.text = NSLocalizedString("Open conversation to registered users", comment: "")
let optionSwicth = UISwitch()
optionSwicth.isOn = self.isOpenConversation
optionSwicth.addTarget(self, action: #selector(openConversationValueChanged(_:)), for: .valueChanged)
roomVisibilityOptionCell.accessoryView = optionSwicth
roomVisibilityOptionCell.imageView?.image = UIImage(systemName: "list.bullet")
case RoomVisibilityOption.kOpenConversationGuestsOption.rawValue:
roomVisibilityOptionCell = tableView.dequeueReusableCell(withIdentifier: "OpenConversationGuestsCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "OpenConversationGuestsCellIdentifier")
roomVisibilityOptionCell = tableView.dequeueOrCreateCell(withIdentifier: "OpenConversationGuestsCellIdentifier")
roomVisibilityOptionCell.textLabel?.text = NSLocalizedString("Also open to guest app users", comment: "")
let optionSwicth = UISwitch()
optionSwicth.isOn = self.isOpenForGuests
Expand Down Expand Up @@ -633,21 +628,21 @@ enum RoomVisibilityOption: Int {
self.dismiss(animated: true, completion: nil)
}

// MARK: - RoomDescriptionTableViewCellDelegate
// MARK: - TextViewTableViewCellDelegate

func roomDescriptionCellTextViewDidChange(_ cell: RoomDescriptionTableViewCell) {
func textViewCellTextViewDidChange(_ cell: TextViewTableViewCell) {
DispatchQueue.main.async {
self.tableView?.beginUpdates()
self.tableView?.endUpdates()
self.roomDescription = cell.textView?.text ?? ""
self.roomDescription = cell.textView.text ?? ""
}
}

func roomDescriptionCellDidEndEditing(_ cell: RoomDescriptionTableViewCell) {
self.roomDescription = cell.textView?.text ?? ""
func textViewCellDidEndEditing(_ cell: TextViewTableViewCell) {
self.roomDescription = cell.textView.text ?? ""
}

func roomDescriptionCellDidExceedLimit(_ cell: RoomDescriptionTableViewCell) {
func textViewCellDidExceedCharacterLimit(_ cell: TextViewTableViewCell) {
NotificationPresenter.shared().present(
text: NSLocalizedString("Description cannot be longer than 500 characters", comment: ""),
dismissAfterDelay: 3.0,
Expand Down
Loading

0 comments on commit 3019dcf

Please sign in to comment.