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

"Invite friends" from settings and "New Chat" #2284

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 24 additions & 4 deletions deltachat-ios/Controller/NewChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class NewChatViewController: UITableViewController {

private let sectionNew = 0
private let sectionContacts = 1
private let sectionsCount = 2
private let sectionInviteFriends = 2

private let sectionsCount = 3

private lazy var searchController: UISearchController = {
let searchController = UISearchController(searchResultsController: nil)
Expand Down Expand Up @@ -100,6 +102,14 @@ class NewChatViewController: UITableViewController {
}

// MARK: - actions

private func inviteFriends(cell: UITableViewCell) {
guard let inviteLink = Utils.getInviteLink(context: dcContext, chatId: 0) else { return }

let invitationText = String.localized(stringID: "invite_friends_text", parameter: inviteLink)
Utils.share(text: invitationText, parentViewController: self, sourceView: cell)
}

@objc func cancelButtonPressed() {
dismiss(animated: true, completion: nil)
}
Expand All @@ -112,14 +122,16 @@ class NewChatViewController: UITableViewController {
override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == sectionNew {
return newOptions.count
} else if section == sectionInviteFriends {
return 1
} else {
return isFiltering ? filteredContactIds.count : contactIds.count
}
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let section = indexPath.section
if section == sectionNew {
if section == sectionNew || section == sectionInviteFriends {
return UITableView.automaticDimension
} else {
return ContactCell.cellHeight
Expand All @@ -132,7 +144,7 @@ class NewChatViewController: UITableViewController {

if section == sectionNew {
guard let actionCell = tableView.dequeueReusableCell(withIdentifier: ActionCell.reuseIdentifier, for: indexPath) as? ActionCell else { fatalError("No Action Cell") }

switch newOptions[row] {
case .scanQRCode:
actionCell.actionTitle = String.localized("menu_new_contact")
Expand All @@ -143,8 +155,14 @@ class NewChatViewController: UITableViewController {
case .newContact:
actionCell.actionTitle = String.localized("menu_new_classic_contact")
}

return actionCell
} else if section == sectionInviteFriends {
guard let actionCell = tableView.dequeueReusableCell(withIdentifier: ActionCell.reuseIdentifier, for: indexPath) as? ActionCell else { fatalError("No Action Cell") }

actionCell.actionTitle = String.localized("invite_friends")
return actionCell

} else {
guard let contactCell = tableView.dequeueReusableCell(withIdentifier: ContactCell.reuseIdentifier, for: indexPath) as? ContactCell else { fatalError("ContactCell expected") }

Expand All @@ -171,6 +189,8 @@ class NewChatViewController: UITableViewController {
} else if newOption == .newContact {
showNewContactController()
}
} else if section == sectionInviteFriends, let cell = tableView.cellForRow(at: indexPath) {
inviteFriends(cell: cell)
} else {
showChatAt(row: row)
}
Expand Down
53 changes: 38 additions & 15 deletions deltachat-ios/Controller/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ internal final class SettingsViewController: UITableViewController {
let headerTitle: String?
let footerTitle: String?
let cells: [UITableViewCell]

init(headerTitle: String? = nil, footerTitle: String? = nil, cells: [UITableViewCell]) {
self.headerTitle = headerTitle
self.footerTitle = footerTitle
self.cells = cells
}
}

private enum CellTags: Int {
Expand All @@ -19,6 +25,7 @@ internal final class SettingsViewController: UITableViewController {
case advanced
case help
case connectivity
case inviteFriends
}

private var dcContext: DcContext
Expand All @@ -39,7 +46,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.chatsAndMedia.rawValue
cell.textLabel?.text = String.localized("pref_chats_and_media")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "message") // added in ios13
cell.imageView?.image = UIImage(systemName: "message")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -57,7 +64,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.notifications.rawValue
cell.textLabel?.text = String.localized("pref_notifications")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "bell") // added in ios13
cell.imageView?.image = UIImage(systemName: "bell")
}
cell.accessoryView = notificationSwitch
cell.selectionStyle = .none
Expand All @@ -69,7 +76,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.addAnotherDevice.rawValue
cell.textLabel?.text = String.localized("multidevice_title")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "macbook.and.iphone") // added in ios16
cell.imageView?.image = UIImage(systemName: "ipad.and.iphone")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -80,7 +87,18 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.advanced.rawValue
cell.textLabel?.text = String.localized("menu_advanced")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "chevron.left.forwardslash.chevron.right") // added in ios15
cell.imageView?.image = UIImage(systemName: "chevron.left.forwardslash.chevron.right")
}
cell.accessoryType = .disclosureIndicator
return cell
}()

private lazy var inviteFriendsCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.tag = CellTags.inviteFriends.rawValue
cell.textLabel?.text = String.localized("invite_friends")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "heart")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -91,7 +109,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.help.rawValue
cell.textLabel?.text = String.localized("menu_help")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "questionmark.circle") // added in ios13
cell.imageView?.image = UIImage(systemName: "questionmark.circle")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -102,7 +120,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.connectivity.rawValue
cell.textLabel?.text = String.localized("connectivity")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "arrow.up.arrow.down") // added in ios13
cell.imageView?.image = UIImage(systemName: "arrow.up.arrow.down")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -113,7 +131,7 @@ internal final class SettingsViewController: UITableViewController {
cell.tag = CellTags.selectBackground.rawValue
cell.textLabel?.text = String.localized("pref_background")
if #available(iOS 16.0, *) {
cell.imageView?.image = UIImage(systemName: "photo") // added in ios13
cell.imageView?.image = UIImage(systemName: "photo")
}
cell.accessoryType = .disclosureIndicator
return cell
Expand All @@ -126,21 +144,18 @@ internal final class SettingsViewController: UITableViewController {
}
let profileSection = SectionConfigs(
headerTitle: String.localized("pref_profile_info_headline"),
footerTitle: nil,
cells: [profileCell]
cells: [self.profileCell]
)
let preferencesSection = SectionConfigs(
headerTitle: nil,
footerTitle: nil,
cells: [chatsAndMediaCell, notificationCell, selectBackgroundCell, addAnotherDeviceCell, connectivityCell, advancedCell]
cells: [self.chatsAndMediaCell, self.notificationCell, self.selectBackgroundCell, self.addAnotherDeviceCell, self.connectivityCell, self.advancedCell]
)
let inviteFriendsSection = SectionConfigs(cells: [self.inviteFriendsCell])
let helpSection = SectionConfigs(
headerTitle: nil,
footerTitle: appNameAndVersion,
cells: [helpCell]
cells: [self.helpCell]
)

return [profileSection, preferencesSection, helpSection]
return [profileSection, preferencesSection, inviteFriendsSection, helpSection]
}()

init(dcAccounts: DcAccounts) {
Expand Down Expand Up @@ -210,6 +225,7 @@ internal final class SettingsViewController: UITableViewController {
case .help: showHelp()
case .connectivity: showConnectivity()
case .selectBackground: selectBackground()
case .inviteFriends: inviteFriends()
}
}

Expand Down Expand Up @@ -293,4 +309,11 @@ internal final class SettingsViewController: UITableViewController {
private func selectBackground() {
navigationController?.pushViewController(BackgroundOptionsViewController(dcContext: dcContext), animated: true)
}

private func inviteFriends() {
guard let inviteLink = Utils.getInviteLink(context: dcContext, chatId: 0) else { return }

let invitationText = String.localized(stringID: "invite_friends_text", parameter: inviteLink)
Utils.share(text: invitationText, parentViewController: self, sourceView: inviteFriendsCell)
}
}
7 changes: 7 additions & 0 deletions deltachat-ios/Helper/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ struct Utils {
activityVC.popoverPresentationController?.barButtonItem = sourceItem // iPad crashes without a source
parentViewController.present(activityVC, animated: true, completion: nil)
}

public static func share(text: String, parentViewController: UIViewController, sourceView: UIView) {
let activityVC = UIActivityViewController(activityItems: [text], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = sourceView // iPad crashes without a source
parentViewController.present(activityVC, animated: true, completion: nil)
}

}
Loading