浏览代码

Merge pull request #345 from deltachat/tweak-state

tweak and fix delivery-state indicator
cyBerta 5 年之前
父节点
当前提交
a1fb2fea2b
共有 3 个文件被更改,包括 24 次插入46 次删除
  1. 17 1
      deltachat-ios/Controller/ChatViewController.swift
  2. 0 23
      deltachat-ios/DC/Wrapper.swift
  3. 7 22
      deltachat-ios/View/ContactCell.swift

+ 17 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -618,8 +618,24 @@ extension ChatViewController: MessagesDataSource {
             let text = NSMutableAttributedString()
             text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
 
+            // TODO: this should be replaced by the respective icons,
+            // for accessibility, the a11y strings should be added
+            var stateDescription: String
+            switch Int32(m.state) {
+            case DC_STATE_OUT_PENDING:
+                stateDescription = "Pending"
+            case DC_STATE_OUT_DELIVERED:
+                stateDescription = "Sent"
+            case DC_STATE_OUT_MDN_RCVD:
+                stateDescription = "Read"
+            case DC_STATE_OUT_FAILED:
+                stateDescription = "Failed"
+            default:
+                stateDescription = "Unknown"
+            }
+
             text.append(NSAttributedString(
-                string: " - " + m.stateDescription(),
+                string: " - " + stateDescription,
                 attributes: [
                     .font: UIFont.systemFont(ofSize: 12),
                     .foregroundColor: UIColor.darkText,

+ 0 - 23
deltachat-ios/DC/Wrapper.swift

@@ -690,29 +690,6 @@ class DcMsg: MessageType {
         return Int(dc_msg_get_state(messagePointer))
     }
 
-    func stateDescription() -> String {
-        switch Int32(state) {
-        case DC_STATE_IN_FRESH:
-            return "Fresh"
-        case DC_STATE_IN_NOTICED:
-            return "Noticed"
-        case DC_STATE_IN_SEEN:
-            return "Seen"
-        case DC_STATE_OUT_DRAFT:
-            return "Draft"
-        case DC_STATE_OUT_PENDING:
-            return "Pending"
-        case DC_STATE_OUT_DELIVERED:
-            return "Sent"
-        case DC_STATE_OUT_MDN_RCVD:
-            return "Read"
-        case DC_STATE_OUT_FAILED:
-            return "Failed"
-        default:
-            return "Unknown"
-        }
-    }
-
     var timestamp: Int64 {
         return Int64(dc_msg_get_timestamp(messagePointer))
     }

+ 7 - 22
deltachat-ios/View/ContactCell.swift

@@ -2,17 +2,6 @@ import UIKit
 
 // TODO: integrate InitialsBadge in here
 
-enum MessageDeliveryState: Int {
-    case UNDEFINED =  0
-    case INNOTICED = 13
-    case INSEEN = 16
-    case OUTPAIRING = 18
-    case OUTPENDING = 20
-    case OUTERROR = 24
-    case OUTDELIVERED = 26
-    case OUTMDNRCVD = 28
-}
-
 protocol ContactCellDelegate: class {
     func onAvatarTapped(at index: Int)
 }
@@ -197,32 +186,28 @@ class ContactCell: UITableViewCell {
     }
 
     func setDeliveryStatusIndicator(_ status: Int) {
-        guard let status = MessageDeliveryState(rawValue: status) else {
-            return
-        }
-
         var indicatorImage: UIImage?
-        switch status {
-        case .OUTPENDING, .OUTPAIRING:
+        switch Int32(status) {
+        case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING:
             indicatorImage = #imageLiteral(resourceName: "ic_hourglass_empty_36pt").withRenderingMode(.alwaysTemplate)
             deliveryStatusIndicator.tintColor = UIColor.black.withAlphaComponent(0.5)
-        case .OUTDELIVERED:
+        case DC_STATE_OUT_DELIVERED:
             indicatorImage = #imageLiteral(resourceName: "ic_done_36pt").withRenderingMode(.alwaysTemplate)
             deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
-        case .OUTERROR:
+        case DC_STATE_OUT_FAILED:
             indicatorImage = #imageLiteral(resourceName: "ic_error_36pt").withRenderingMode(.alwaysTemplate)
             deliveryStatusIndicator.tintColor = UIColor.red
-        case .INSEEN:
+        case DC_STATE_OUT_MDN_RCVD:
             indicatorImage = #imageLiteral(resourceName: "ic_done_all_36pt").withRenderingMode(.alwaysTemplate)
             deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
-        default: break
+        default:
+            break
         }
         if indicatorImage != nil {
             deliveryStatusIndicator.isHidden = false
         } else {
             deliveryStatusIndicator.isHidden = true
         }
-
         deliveryStatusIndicator.image = indicatorImage
     }