|
@@ -32,7 +32,6 @@ internal final class SettingsViewController: UITableViewController {
|
|
|
let documentInteractionController = UIDocumentInteractionController()
|
|
|
var backupProgressObserver: Any?
|
|
|
var configureProgressObserver: Any?
|
|
|
- private let externalPathDescr = "File Sharing/Delta Chat"
|
|
|
|
|
|
private lazy var hudHandler: HudHandler = {
|
|
|
let hudHandler = HudHandler(parentView: self.view)
|
|
@@ -301,197 +300,22 @@ internal final class SettingsViewController: UITableViewController {
|
|
|
return sections[section].footerTitle
|
|
|
}
|
|
|
|
|
|
- private func customProfileCell() -> UITableViewCell {
|
|
|
- let cell = UITableViewCell()
|
|
|
-
|
|
|
- cell.contentView.subviews.forEach({ $0.removeFromSuperview() })
|
|
|
-
|
|
|
- let badge = createProfileBadge()
|
|
|
- let nameLabel = createNameLabel()
|
|
|
- let signatureLabel = createSubtitle()
|
|
|
-
|
|
|
- cell.contentView.addSubview(badge)
|
|
|
- cell.contentView.addSubview(nameLabel)
|
|
|
- cell.contentView.addSubview(signatureLabel)
|
|
|
-
|
|
|
- let badgeConstraints = [
|
|
|
- badge.constraintAlignLeadingTo(cell.contentView, paddingLeading: 16),
|
|
|
- badge.constraintCenterYTo(cell.contentView),
|
|
|
- badge.constraintAlignTopTo(cell.contentView, paddingTop: 8),
|
|
|
- badge.constraintAlignBottomTo(cell.contentView, paddingBottom: 8)]
|
|
|
- let textViewConstraints = [
|
|
|
- nameLabel.constraintToTrailingOf(badge, paddingLeading: 12),
|
|
|
- nameLabel.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 16),
|
|
|
- nameLabel.constraintAlignTopTo(cell.contentView, paddingTop: 14)]
|
|
|
- let subtitleViewConstraints = [
|
|
|
- signatureLabel.constraintToTrailingOf(badge, paddingLeading: 12),
|
|
|
- signatureLabel.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 16),
|
|
|
- signatureLabel.constraintToBottomOf(nameLabel, paddingTop: 0),
|
|
|
- signatureLabel.constraintAlignBottomTo(cell.contentView, paddingBottom: 12)]
|
|
|
-
|
|
|
- cell.contentView.addConstraints(badgeConstraints)
|
|
|
- cell.contentView.addConstraints(textViewConstraints)
|
|
|
- cell.contentView.addConstraints(subtitleViewConstraints)
|
|
|
-
|
|
|
- return cell
|
|
|
- }
|
|
|
-
|
|
|
- private func createProfileBadge() -> InitialsBadge {
|
|
|
- let selfContact = DcContact(id: Int(DC_CONTACT_ID_SELF))
|
|
|
- let badgeSize: CGFloat = 48
|
|
|
- if let image = selfContact.profileImage {
|
|
|
- return InitialsBadge(image: image, size: badgeSize)
|
|
|
- } else {
|
|
|
- return InitialsBadge(name: DcConfig.displayname ?? selfContact.email, color: selfContact.color, size: badgeSize)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func createNameLabel() -> UILabel {
|
|
|
- let nameLabel = UILabel.init()
|
|
|
- nameLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- nameLabel.text = DcConfig.displayname ?? String.localized("pref_your_name")
|
|
|
- return nameLabel
|
|
|
- }
|
|
|
-
|
|
|
- private func createSubtitle() -> UILabel {
|
|
|
- let subtitle = (DcConfig.addr ?? "")
|
|
|
- let subtitleView = UILabel.init()
|
|
|
- subtitleView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- subtitleView.text = subtitle
|
|
|
- subtitleView.font = UIFont.systemFont(ofSize: 13)
|
|
|
- subtitleView.lineBreakMode = .byTruncatingTail
|
|
|
- return subtitleView
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- private func setTable() {
|
|
|
-
|
|
|
- var appNameAndVersion = "Delta Chat"
|
|
|
- if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
|
|
|
- appNameAndVersion += " v" + appVersion
|
|
|
- }
|
|
|
-
|
|
|
- tableContents = [
|
|
|
- Section(
|
|
|
- title: String.localized("pref_profile_info_headline"),
|
|
|
- rows: [
|
|
|
- //The profile row has a custom view and is set in
|
|
|
- //tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
|
|
|
- NavigationRow(text: "",
|
|
|
- detailText: .none,
|
|
|
- action: { _ in
|
|
|
- self.coordinator?.showEditSettingsController()
|
|
|
- }),
|
|
|
- ]
|
|
|
- ),
|
|
|
-
|
|
|
- Section(
|
|
|
- title: nil,
|
|
|
- rows: [
|
|
|
- NavigationRow(text: String.localized("menu_deaddrop"),
|
|
|
- detailText: .none,
|
|
|
- action: { [weak self] in self?.showDeaddrop($0) }),
|
|
|
- NavigationRow(text: String.localized("pref_show_emails"),
|
|
|
- detailText: .value1(SettingsClassicViewController.getValString(val: DcConfig.showEmails)),
|
|
|
- action: { [weak self] in self?.showClassicMail($0) }),
|
|
|
- NavigationRow(text: String.localized("pref_blocked_contacts"),
|
|
|
- detailText: .none,
|
|
|
- action: { [weak self] in self?.showBlockedContacts($0) }),
|
|
|
- SwitchRow(text: String.localized("pref_notifications"),
|
|
|
- switchValue: !UserDefaults.standard.bool(forKey: "notifications_disabled"),
|
|
|
- action: { row in
|
|
|
- if let row = row as? SwitchRow {
|
|
|
- UserDefaults.standard.set(!row.switchValue, forKey: "notifications_disabled")
|
|
|
- }
|
|
|
- }),
|
|
|
- SwitchRow(text: String.localized("pref_read_receipts"),
|
|
|
- switchValue: DcConfig.mdnsEnabled,
|
|
|
- action: { row in
|
|
|
- if let row = row as? SwitchRow {
|
|
|
- DcConfig.mdnsEnabled = row.switchValue
|
|
|
- }
|
|
|
- }),
|
|
|
- ],
|
|
|
- footer: String.localized("pref_read_receipts_explain")
|
|
|
- ),
|
|
|
-
|
|
|
- Section(
|
|
|
- title: String.localized("autocrypt"),
|
|
|
- rows: [
|
|
|
- SwitchRow(text: String.localized("autocrypt_prefer_e2ee"),
|
|
|
- switchValue: DcConfig.e2eeEnabled,
|
|
|
- action: { row in
|
|
|
- if let row = row as? SwitchRow {
|
|
|
- DcConfig.e2eeEnabled = row.switchValue
|
|
|
- }
|
|
|
- }),
|
|
|
- TapActionRow(text: String.localized("autocrypt_send_asm_title"), action: { [weak self] in self?.sendAsm($0) }),
|
|
|
- TapActionRow(text: String.localized("menu_advanced"),
|
|
|
- action: { [weak self] in self?.showKeyManagementDialog($0) }),
|
|
|
- ],
|
|
|
- footer: String.localized("autocrypt_explain")
|
|
|
- ),
|
|
|
-
|
|
|
- Section(
|
|
|
- title: nil,
|
|
|
- rows: [
|
|
|
- TapActionRow(text: String.localized("pref_backup"), action: { [weak self] in self?.createBackup($0) }),
|
|
|
- ],
|
|
|
- footer: String.localized("pref_backup_explain")
|
|
|
- ),
|
|
|
-
|
|
|
- Section(
|
|
|
- title: nil,
|
|
|
- rows: [
|
|
|
- TapActionRow(text: String.localized("menu_help"), action: { [weak self] in self?.openHelp($0) }),
|
|
|
- ],
|
|
|
- footer: appNameAndVersion
|
|
|
- ),
|
|
|
- ]
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- private func startImex(what: Int32) {
|
|
|
- let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
|
|
|
- if !documents.isEmpty {
|
|
|
- self.hudHandler.showHud(String.localized("one_moment"))
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.dcContext.imex(what: what, directory: documents[0])
|
|
|
- }
|
|
|
- } else {
|
|
|
- logger.error("document directory not found")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func createBackup(_: Row) {
|
|
|
+ // MARK: - actions
|
|
|
+
|
|
|
+ private func createBackup() {
|
|
|
let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
|
|
|
self.dismiss(animated: true, completion: nil)
|
|
|
- self.startImex(what: DC_IMEX_EXPORT_BACKUP)
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
- present(alert, animated: true, completion: nil)
|
|
|
- }
|
|
|
-
|
|
|
- private func showKeyManagementDialog(_: Row) {
|
|
|
- let alert = UIAlertController(title: String.localized("pref_manage_keys"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_export_secret_keys"), style: .default, handler: { _ in
|
|
|
- let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_export_explain"), self.externalPathDescr)
|
|
|
- let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
|
|
|
- self.startImex(what: DC_IMEX_EXPORT_SELF_KEYS)
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_import_secret_keys"), style: .default, handler: { _ in
|
|
|
- let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_import_explain"), self.externalPathDescr)
|
|
|
- let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
|
|
|
- self.startImex(what: DC_IMEX_IMPORT_SELF_KEYS)
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
+ let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
|
|
|
+ if !documents.isEmpty {
|
|
|
+ logger.info("create backup in \(documents)")
|
|
|
+ self.hudHandler.showHud(String.localized("one_moment"))
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ dc_imex(mailboxPointer, DC_IMEX_EXPORT_BACKUP, documents[0], nil)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("document directory not found")
|
|
|
+ }
|
|
|
}))
|
|
|
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
present(alert, animated: true, completion: nil)
|