Explorar o código

Merge pull request #412 from deltachat/signature-fixes

implement multiline text cell for signature (#404, #225)
björn petersen %!s(int64=5) %!d(string=hai) anos
pai
achega
a6ac7ed65a

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -11,6 +11,7 @@
 		300C50A1234BDAB800F8AE22 /* TextMediaMessageSizeCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 300C50A0234BDAB800F8AE22 /* TextMediaMessageSizeCalculator.swift */; };
 		30149D9322F21129003C12B5 /* QrViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30149D9222F21129003C12B5 /* QrViewController.swift */; };
 		3022E6BE22E8768800763272 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3022E6C022E8768800763272 /* InfoPlist.strings */; };
+		30260CA7238F02F700D8D52C /* MultilineTextFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30260CA6238F02F700D8D52C /* MultilineTextFieldCell.swift */; };
 		3040F45E234DFBC000FA34D5 /* Audio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3040F45D234DFBC000FA34D5 /* Audio.swift */; };
 		3040F460234F419400FA34D5 /* BasicAudioController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3040F45F234F419300FA34D5 /* BasicAudioController.swift */; };
 		3040F462234F550300FA34D5 /* AudioPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3040F461234F550300FA34D5 /* AudioPlayerView.swift */; };
@@ -181,6 +182,7 @@
 		3022E6D122E8769E00763272 /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		3022E6D222E8769F00763272 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
 		3022E6D322E876A100763272 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+		30260CA6238F02F700D8D52C /* MultilineTextFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilineTextFieldCell.swift; sourceTree = "<group>"; };
 		3040F45D234DFBC000FA34D5 /* Audio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Audio.swift; sourceTree = "<group>"; };
 		3040F45F234F419300FA34D5 /* BasicAudioController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicAudioController.swift; sourceTree = "<group>"; };
 		3040F461234F550300FA34D5 /* AudioPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerView.swift; sourceTree = "<group>"; };
@@ -708,6 +710,7 @@
 				70B8882D2091B8550074812E /* ContactCell.swift */,
 				78ED839321D5AF8A00243125 /* QrCodeView.swift */,
 				78ED838221D5379000243125 /* TextFieldCell.swift */,
+				30260CA6238F02F700D8D52C /* MultilineTextFieldCell.swift */,
 				78E45E3B21D3D03700D4B15E /* TextFieldTableViewCell.swift */,
 				789E879C21D6DF86003ED1C5 /* ProgressHud.swift */,
 				AE38B31722672DFC00EC37A1 /* ActionCell.swift */,
@@ -1110,6 +1113,7 @@
 				305961E12346125100C80F33 /* LocationItem.swift in Sources */,
 				305961E72346125100C80F33 /* AccessoryPosition.swift in Sources */,
 				7A451DBE1FB4AD0700177250 /* Wrapper.swift in Sources */,
+				30260CA7238F02F700D8D52C /* MultilineTextFieldCell.swift in Sources */,
 				305961DE2346125100C80F33 /* MessageType.swift in Sources */,
 				AE851ACE227CA54400ED86F0 /* InitialsBadge.swift in Sources */,
 				305961DA2346125100C80F33 /* MediaItem.swift in Sources */,

+ 13 - 5
deltachat-ios/Controller/EditSettingsController.swift

@@ -25,9 +25,10 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
 
     private var childCoordinators: Coordinator?
 
-    private lazy var statusCell: TextFieldCell = {
-        let cell = TextFieldCell(description: String.localized("pref_default_status_label"), placeholder: String.localized("pref_default_status_label"))
-        cell.setText(text: DcConfig.selfstatus ?? nil)
+    private lazy var statusCell: MultilineTextFieldCell = {
+        let cell = MultilineTextFieldCell(description: String.localized("pref_default_status_label"),
+                                          multilineText: DcConfig.selfstatus,
+                                          placeholder: String.localized("pref_default_status_label"))
         return cell
     }()
 
@@ -104,8 +105,15 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     }
 
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        if indexPath.section == section1 && indexPath.row == section1Avatar {
-            return AvatarSelectionCell.cellSize
+        if indexPath.section == section1 {
+            switch indexPath.row {
+            case section1Avatar:
+                return AvatarSelectionCell.cellSize
+            case section1Status:
+                return MultilineTextFieldCell.cellHeight
+            default:
+                 return Constants.defaultCellHeight
+            }
         } else {
             return Constants.defaultCellHeight
         }

+ 91 - 0
deltachat-ios/View/MultilineTextFieldCell.swift

@@ -0,0 +1,91 @@
+import Foundation
+import UIKit
+
+class MultilineTextFieldCell: UITableViewCell, UITextViewDelegate {
+    static let cellHeight: CGFloat = 125
+
+    var onTextFieldChange:((_:UITextView) -> Void)?    // set this from outside to get notified about textfield changes
+
+    lazy var descriptionField: UITextField = {
+        let textField = UITextField()
+        textField.translatesAutoresizingMaskIntoConstraints = false
+        textField.isEnabled = false
+        return textField
+    }()
+
+    lazy var textField: UITextView = {
+        let textField = UITextView()
+        textField.delegate = self
+        textField.translatesAutoresizingMaskIntoConstraints = false
+        textField.font = UIFont.systemFont(ofSize: 16)
+        textField.backgroundColor = .none
+        return textField
+    }()
+
+    lazy var placeholder: UILabel = {
+        let placeholderLabel = UILabel()
+        placeholderLabel.font = self.textField.font
+        placeholderLabel.textColor = UIColor.lightGray
+        placeholderLabel.translatesAutoresizingMaskIntoConstraints = false
+        return placeholderLabel
+    }()
+
+    init(description: String, multilineText: String?, placeholder: String) {
+        super.init(style: .value1, reuseIdentifier: nil)
+        self.descriptionField.text = "\(description):"
+        self.textField.text = multilineText
+        self.placeholder.text = placeholder
+        self.placeholder.isHidden = !textField.text.isEmpty
+        selectionStyle = .none
+        setupViews()
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    func setupViews() {
+        contentView.addSubview(descriptionField)
+        contentView.addSubview(textField)
+        contentView.addSubview(placeholder)
+        let margins = contentView.layoutMarginsGuide
+
+        descriptionField.alignLeadingToAnchor(margins.leadingAnchor)
+        descriptionField.alignTrailingToAnchor(margins.trailingAnchor)
+        descriptionField.alignTopToAnchor(margins.topAnchor)
+
+        textField.alignLeadingToAnchor(margins.leadingAnchor, paddingLeading: -5)
+        textField.alignTrailingToAnchor(margins.trailingAnchor)
+        contentView.addConstraint(textField.constraintHeightTo(95))
+        textField.alignTopToAnchor(descriptionField.bottomAnchor)
+
+        placeholder.alignLeadingToAnchor(margins.leadingAnchor)
+        placeholder.alignTrailingToAnchor(textField.layoutMarginsGuide.trailingAnchor)
+        placeholder.alignTopToAnchor(textField.layoutMarginsGuide.topAnchor)
+    }
+
+    override func setSelected(_ selected: Bool, animated _: Bool) {
+        if selected {
+            textField.becomeFirstResponder()
+        }
+    }
+
+    func getText() -> String? {
+        return textField.text
+    }
+
+    func setText(text: String?) {
+        textField.text = text
+    }
+
+    // MARK: - UITextViewDelegate
+
+    func textViewDidChange(_ textView: UITextView) {
+        onTextFieldChange?(self.textField)
+    }
+
+    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
+        placeholder.isHidden = !(text.isEmpty && range.length == textView.text.count)
+        return true
+    }
+}