Bläddra i källkod

implemented provider info showing and hiding - has bugs

nayooti 5 år sedan
förälder
incheckning
268d415a9e

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

@@ -153,6 +153,7 @@
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
 		AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC472283045D00EDC689 /* EditSettingsController.swift */; };
 		AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC472283045D00EDC689 /* EditSettingsController.swift */; };
 		AEFBE22F23FEF23D0045327A /* ProviderInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */; };
 		AEFBE22F23FEF23D0045327A /* ProviderInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */; };
+		AEFBE23123FF09B20045327A /* TypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFBE23023FF09B20045327A /* TypeAlias.swift */; };
 		B21005DB23383664004C70C5 /* SettingsClassicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B21005DA23383664004C70C5 /* SettingsClassicViewController.swift */; };
 		B21005DB23383664004C70C5 /* SettingsClassicViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B21005DA23383664004C70C5 /* SettingsClassicViewController.swift */; };
 		B26B3BC7236DC3DC008ED35A /* SwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B26B3BC6236DC3DC008ED35A /* SwitchCell.swift */; };
 		B26B3BC7236DC3DC008ED35A /* SwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B26B3BC6236DC3DC008ED35A /* SwitchCell.swift */; };
 /* End PBXBuildFile section */
 /* End PBXBuildFile section */
@@ -383,6 +384,7 @@
 		AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailboxViewController.swift; sourceTree = "<group>"; };
 		AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailboxViewController.swift; sourceTree = "<group>"; };
 		AEE6EC472283045D00EDC689 /* EditSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditSettingsController.swift; sourceTree = "<group>"; };
 		AEE6EC472283045D00EDC689 /* EditSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditSettingsController.swift; sourceTree = "<group>"; };
 		AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderInfoCell.swift; sourceTree = "<group>"; };
 		AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProviderInfoCell.swift; sourceTree = "<group>"; };
+		AEFBE23023FF09B20045327A /* TypeAlias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeAlias.swift; sourceTree = "<group>"; };
 		B21005DA23383664004C70C5 /* SettingsClassicViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsClassicViewController.swift; sourceTree = "<group>"; };
 		B21005DA23383664004C70C5 /* SettingsClassicViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsClassicViewController.swift; sourceTree = "<group>"; };
 		B253ED992336E759004DD215 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		B253ED992336E759004DD215 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		B253ED9A2336E759004DD215 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
 		B253ED9A2336E759004DD215 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -766,6 +768,7 @@
 				30AC265E237F1807002A943F /* AvatarHelper.swift */,
 				30AC265E237F1807002A943F /* AvatarHelper.swift */,
 				302B84C42396627F001C261F /* RelayHelper.swift */,
 				302B84C42396627F001C261F /* RelayHelper.swift */,
 				AE1988A423EB2FBA00B4CD5F /* Errors.swift */,
 				AE1988A423EB2FBA00B4CD5F /* Errors.swift */,
+				AEFBE23023FF09B20045327A /* TypeAlias.swift */,
 			);
 			);
 			path = Helper;
 			path = Helper;
 			sourceTree = "<group>";
 			sourceTree = "<group>";
@@ -1157,6 +1160,7 @@
 				305962072346125100C80F33 /* MessagesCollectionViewFlowLayout.swift in Sources */,
 				305962072346125100C80F33 /* MessagesCollectionViewFlowLayout.swift in Sources */,
 				78ED838321D5379000243125 /* TextFieldCell.swift in Sources */,
 				78ED838321D5379000243125 /* TextFieldCell.swift in Sources */,
 				78E45E3C21D3D03700D4B15E /* TextFieldTableViewCell.swift in Sources */,
 				78E45E3C21D3D03700D4B15E /* TextFieldTableViewCell.swift in Sources */,
+				AEFBE23123FF09B20045327A /* TypeAlias.swift in Sources */,
 				AE19887523EB264000B4CD5F /* HelpViewController.swift in Sources */,
 				AE19887523EB264000B4CD5F /* HelpViewController.swift in Sources */,
 				305961D52346125100C80F33 /* MessagesViewController+Menu.swift in Sources */,
 				305961D52346125100C80F33 /* MessagesViewController+Menu.swift in Sources */,
 				305961F22346125100C80F33 /* LocationMessageCell.swift in Sources */,
 				305961F22346125100C80F33 /* LocationMessageCell.swift in Sources */,

+ 16 - 9
deltachat-ios/Controller/AccountSetupController.swift

@@ -137,6 +137,10 @@ class AccountSetupController: UITableViewController {
 
 
     private lazy var providerInfoCell: ProviderInfoCell = {
     private lazy var providerInfoCell: ProviderInfoCell = {
         let cell = ProviderInfoCell()
         let cell = ProviderInfoCell()
+        cell.onInfoButtonPressed = {
+            [unowned self] in
+            self.handleProviderInfoButton()
+        }
         return cell
         return cell
     }()
     }()
     
     
@@ -452,11 +456,7 @@ class AccountSetupController: UITableViewController {
     
     
     override func tableView(_: UITableView, titleForFooterInSection section: Int) -> String? {
     override func tableView(_: UITableView, titleForFooterInSection section: Int) -> String? {
         if sections[section] == basicSection {
         if sections[section] == basicSection {
-            if provider != nil && (provider?.status==DC_PROVIDER_STATUS_PREPARATION || provider?.status==DC_PROVIDER_STATUS_BROKEN) {
-                return provider?.beforeLoginHint
-            } else {
-                return String.localized("login_no_servers_hint")
-            }
+            return String.localized("login_no_servers_hint")
         } else if sections[section] == advancedSection {
         } else if sections[section] == advancedSection {
             if advancedSectionShowing && dcContext.isConfigured() {
             if advancedSectionShowing && dcContext.isConfigured() {
                 var info = String.localized("used_settings") + "\n"
                 var info = String.localized("used_settings") + "\n"
@@ -572,8 +572,12 @@ class AccountSetupController: UITableViewController {
 
 
     func updateProviderInfo() {
     func updateProviderInfo() {
         provider = dcContext.getProviderFromEmail(addr: emailCell.getText() ?? "")
         provider = dcContext.getProviderFromEmail(addr: emailCell.getText() ?? "")
-        if let hint = provider?.beforeLoginHint, let status = provider?.status, !hint.isEmpty {
-            showProviderInfo(with: hint, hintType: .preparation)
+        if
+            let hint = provider?.beforeLoginHint,
+            let status = provider?.status,
+            let statusType = ProviderInfoStatus(rawValue: status),
+            !hint.isEmpty {
+            showProviderInfo(with: hint, hintType: statusType)
         } else {
         } else {
             hideProviderInfo()
             hideProviderInfo()
         }
         }
@@ -581,7 +585,7 @@ class AccountSetupController: UITableViewController {
 
 
     func showProviderInfo(with hint: String, hintType: ProviderInfoStatus) {
     func showProviderInfo(with hint: String, hintType: ProviderInfoStatus) {
         providerInfoCell.updateInfo(hint: hint, hintType: hintType)
         providerInfoCell.updateInfo(hint: hint, hintType: hintType)
-        basicSectionCells = [emailCell, passwordCell, providerInfoCell]
+        basicSectionCells.append(providerInfoCell)
         let providerInfoCellIndexPath = IndexPath(row: 2, section: 0)
         let providerInfoCellIndexPath = IndexPath(row: 2, section: 0)
         tableView.insertRows(at: [providerInfoCellIndexPath], with: .automatic)
         tableView.insertRows(at: [providerInfoCellIndexPath], with: .automatic)
     }
     }
@@ -857,6 +861,10 @@ class AccountSetupController: UITableViewController {
     private func handleLoginButton() {
     private func handleLoginButton() {
         loginButton.isEnabled = !(emailCell.getText() ?? "").isEmpty && !(passwordCell.getText() ?? "").isEmpty
         loginButton.isEnabled = !(emailCell.getText() ?? "").isEmpty && !(passwordCell.getText() ?? "").isEmpty
     }
     }
+
+    private func handleProviderInfoButton() {
+        print("handle provider info button")
+    }
     
     
     func resignCell(cell: UITableViewCell) {
     func resignCell(cell: UITableViewCell) {
         if let c = cell as? TextFieldCell {
         if let c = cell as? TextFieldCell {
@@ -901,7 +909,6 @@ extension AccountSetupController: UITextFieldDelegate {
             let _ = showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
             let _ = showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
                 self.passwordCell.textField.becomeFirstResponder()
                 self.passwordCell.textField.becomeFirstResponder()
             })
             })
-            
             updateProviderInfo()
             updateProviderInfo()
         }
         }
     }
     }

+ 2 - 2
deltachat-ios/DC/Wrapper.swift

@@ -1005,8 +1005,8 @@ class DcProvider {
         dc_provider_unref(dcProviderPointer)
         dc_provider_unref(dcProviderPointer)
     }
     }
 
 
-    var status: Int32 {
-        return dc_provider_get_status(dcProviderPointer)
+    var status: Int {
+        return Int(dc_provider_get_status(dcProviderPointer))
     }
     }
 
 
     var beforeLoginHint: String {
     var beforeLoginHint: String {

+ 11 - 0
deltachat-ios/Helper/TypeAlias.swift

@@ -0,0 +1,11 @@
+//
+//  TypeDefs.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 20.02.20.
+//  Copyright © 2020 Jonas Reinsch. All rights reserved.
+//
+
+import Foundation
+
+typealias VoidFunction = ()->Void

+ 42 - 20
deltachat-ios/View/ProviderInfoCell.swift

@@ -8,27 +8,35 @@
 
 
 import UIKit
 import UIKit
 
 
-enum ProviderInfoStatus {
-     case preparation
-     case broken
-     case ok
+enum ProviderInfoStatus: Int {
+     case preparation = 2
+     case broken = 1
  }
  }
 
 
 class ProviderInfoCell: UITableViewCell {
 class ProviderInfoCell: UITableViewCell {
 
 
+    let fontSize: CGFloat = 13
+
+    var onInfoButtonPressed: VoidFunction?
+
     private var hintBackgroundView: UIView = {
     private var hintBackgroundView: UIView = {
         let view = UIView()
         let view = UIView()
         return view
         return view
     }()
     }()
 
 
-    private var hintLabel: UILabel = {
+    private lazy var hintLabel: UILabel = {
         let label = UILabel()
         let label = UILabel()
+        label.numberOfLines = 0
+        label.font = UIFont.systemFont(ofSize: fontSize)
         return label
         return label
     }()
     }()
 
 
-    private var infoButton: UIButton = {
+    private lazy var infoButton: UIButton = {
         let button = UIButton()
         let button = UIButton()
-        button.setTitle("more_info_desktop".lowercased(), for: .normal)
+        let title = String.localized("more_info_desktop")
+        button.setTitle(title, for: .normal)
+        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: fontSize)
+        button.addTarget(self, action: #selector(infoButtonPressed(_:)), for: .touchUpInside)
         return button
         return button
     }()
     }()
 
 
@@ -41,43 +49,57 @@ class ProviderInfoCell: UITableViewCell {
         fatalError("init(coder:) has not been implemented")
         fatalError("init(coder:) has not been implemented")
     }
     }
 
 
+    override func setSelected(_ selected: Bool, animated: Bool) {
+        // ... no highlight
+    }
+
     private func setupSubviews() {
     private func setupSubviews() {
 
 
-        let margin: CGFloat = 20
+        let margin: CGFloat = 15
 
 
         contentView.addSubview(hintBackgroundView)
         contentView.addSubview(hintBackgroundView)
         hintBackgroundView.addSubview(hintLabel)
         hintBackgroundView.addSubview(hintLabel)
         hintBackgroundView.addSubview(infoButton)
         hintBackgroundView.addSubview(infoButton)
 
 
-        contentView.translatesAutoresizingMaskIntoConstraints = false
-        contentView.translatesAutoresizingMaskIntoConstraints = false
-        contentView.translatesAutoresizingMaskIntoConstraints = false
+        hintBackgroundView.translatesAutoresizingMaskIntoConstraints = false
+        hintLabel.translatesAutoresizingMaskIntoConstraints = false
+        infoButton.translatesAutoresizingMaskIntoConstraints = false
 
 
         hintBackgroundView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: margin).isActive = true
         hintBackgroundView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: margin).isActive = true
-        hintBackgroundView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
+        hintBackgroundView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15).isActive = true
         hintBackgroundView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
         hintBackgroundView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
-        hintBackgroundView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
+        hintBackgroundView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -15).isActive = true
 
 
-        hintLabel.leadingAnchor.constraint(equalTo: hintBackgroundView.leadingAnchor, constant: 5).isActive = true
+        hintLabel.leadingAnchor.constraint(equalTo: hintBackgroundView.leadingAnchor, constant: 10).isActive = true
         hintLabel.topAnchor.constraint(equalTo: hintBackgroundView.topAnchor, constant: 5).isActive = true
         hintLabel.topAnchor.constraint(equalTo: hintBackgroundView.topAnchor, constant: 5).isActive = true
-        hintLabel.trailingAnchor.constraint(equalTo: hintBackgroundView.trailingAnchor, constant: -5).isActive = true
+        hintLabel.trailingAnchor.constraint(equalTo: hintBackgroundView.trailingAnchor, constant: -10).isActive = true
 
 
         infoButton.topAnchor.constraint(equalTo: hintLabel.bottomAnchor, constant: 10).isActive = true
         infoButton.topAnchor.constraint(equalTo: hintLabel.bottomAnchor, constant: 10).isActive = true
-        infoButton.leadingAnchor.constraint(equalTo: hintBackgroundView.leadingAnchor, constant: 5).isActive = true
+        infoButton.leadingAnchor.constraint(equalTo: hintBackgroundView.leadingAnchor, constant: 10).isActive = true
         infoButton.bottomAnchor.constraint(equalTo: hintBackgroundView.bottomAnchor, constant: -5).isActive = true
         infoButton.bottomAnchor.constraint(equalTo: hintBackgroundView.bottomAnchor, constant: -5).isActive = true
     }
     }
 
 
+    // MARK: -update
     func updateInfo(hint text: String?, hintType: ProviderInfoStatus?) {
     func updateInfo(hint text: String?, hintType: ProviderInfoStatus?) {
         hintLabel.text = text
         hintLabel.text = text
         switch hintType {
         switch hintType {
         case .preparation:
         case .preparation:
-            hintBackgroundView.backgroundColor = SystemColor.yellow.uiColor
+            hintBackgroundView.backgroundColor = SystemColor.yellow.uiColor.withAlphaComponent(0.5)
+            let textColor = DcColors.grayTextColor
+            hintLabel.textColor = textColor
+            infoButton.setTitleColor(textColor, for: .normal)
         case .broken:
         case .broken:
-            hintBackgroundView.backgroundColor = SystemColor.red.uiColor
-        case .ok:
-            hintBackgroundView.backgroundColor = .clear
+            hintBackgroundView.backgroundColor = SystemColor.red.uiColor.withAlphaComponent(0.5)
+            let textColor = UIColor.white
+            hintLabel.textColor = textColor
+            infoButton.setTitleColor(textColor, for: .normal)
         case .none:
         case .none:
             break
             break
         }
         }
     }
     }
+
+    // MARK: -actions
+    @objc func infoButtonPressed(_:UIButton) {
+        onInfoButtonPressed?()
+    }
 }
 }