Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new TextFieldTableViewCell and TextViewTableViewCell that use a dynamic font #1846

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions NextcloudTalk.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 12 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: textFieldCellIdentifier)
}

// 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,41 @@ 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: textFieldCellIdentifier)
textInputCell.textField.delegate = self
textInputCell.textField.autocapitalizationType = .sentences
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: textFieldCellIdentifier)
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
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 UITableViewCell()
}

return actionCell
return UITableViewCell()
SystemKeeper marked this conversation as resolved.
Show resolved Hide resolved
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
27 changes: 12 additions & 15 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: textFieldCellIdentifier)
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,24 @@ 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: textFieldCellIdentifier)
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 +271,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
41 changes: 19 additions & 22 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: textFieldCellIdentifier)
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,8 +426,7 @@ 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)
let textInputCell: TextFieldTableViewCell = tableView.dequeueOrCreateCell(withIdentifier: textFieldCellIdentifier)
textInputCell.textField.autocapitalizationType = .sentences
textInputCell.textField.tag = kRoomNameTextFieldTag
textInputCell.textField.delegate = self
Expand All @@ -436,26 +435,24 @@ enum RoomVisibilityOption: Int {
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 +467,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 +630,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
Loading