Эх сурвалжийг харах

added formatted time in chat list

Bastian van de Wetering 6 жил өмнө
parent
commit
45a2c0b731

+ 47 - 0
deltachat-ios/Helper/Utils.swift

@@ -176,3 +176,50 @@ extension UIColor {
     self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
   }
 }
+
+class DateUtils {
+
+	static func getBriefRelativeTimeSpanString(timeStamp: Int) -> String {
+		let unixTime = Int(Date().timeIntervalSince1970)
+		let seconds = unixTime - timeStamp
+
+		if seconds < 60 {
+			return "Now"	// under one minute
+		} else if seconds < 3600 {
+			let mins = seconds / 60
+			let minTitle = mins > 1 ? "mins" : "min"
+			return "\(mins) \(minTitle)"
+		} else if seconds < 86400 {
+			let hours = seconds / 3600
+			let hoursTitle = hours > 1 ? "hours" : "hour"
+			return "\(hours) \(hoursTitle)"
+		} else {
+			let date = Date(timeIntervalSince1970: Double(timeStamp))
+			let dateFormatter = DateFormatter()
+			dateFormatter.timeStyle = DateFormatter.Style.medium //Set time style
+			dateFormatter.dateStyle = DateFormatter.Style.medium //Set date style
+			dateFormatter.timeZone = .current
+			let localDate = dateFormatter.string(from: date)
+			return localDate
+		}
+	}
+}
+
+/*
+if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
+return c.getString(R.string.now);
+} else if (isWithin(timestamp, 1, TimeUnit.HOURS)) {
+int mins = convertDelta(timestamp, TimeUnit.MINUTES);
+return c.getResources().getQuantityString(R.plurals.n_minutes, mins, mins);
+} else if (isWithin(timestamp, 1, TimeUnit.DAYS)) {
+int hours = convertDelta(timestamp, TimeUnit.HOURS);
+return c.getResources().getQuantityString(R.plurals.n_hours, hours, hours);
+} else if (isWithin(timestamp, 6, TimeUnit.DAYS)) {
+return getFormattedDateTime(timestamp, "EEE", locale);
+} else if (isWithin(timestamp, 365, TimeUnit.DAYS)) {
+return getFormattedDateTime(timestamp, "MMM d", locale);
+} else {
+return getFormattedDateTime(timestamp, "MMM d, yyyy", locale);
+}
+
+*/

+ 10 - 2
deltachat-ios/View/ContactCell.swift

@@ -197,10 +197,12 @@ class ContactCell: UITableViewCell {
 		switch status {
 		case .OUTPENDING, .OUTPAIRING:
 			indicatorImage = #imageLiteral(resourceName: "ic_delivery_status_sending").withRenderingMode(.alwaysTemplate)
+			deliveryStatusIndicator.tintColor = UIColor.black
 		case .OUTDELIVERED:
 			indicatorImage = #imageLiteral(resourceName: "ic_done_36pt").withRenderingMode(.alwaysTemplate)
 		case .OUTERROR:
 			indicatorImage = #imageLiteral(resourceName: "ic_error_36pt").withRenderingMode(.alwaysTemplate)
+			deliveryStatusIndicator.tintColor = UIColor.red
 		case .INSEEN:
 			indicatorImage = #imageLiteral(resourceName: "ic_done_all_36pt").withRenderingMode(.alwaysTemplate)
 		default: break
@@ -214,8 +216,14 @@ class ContactCell: UITableViewCell {
 		deliveryStatusIndicator.image = indicatorImage
 	}
 
-	func setTimeLabel(_ timestamp: Int) {
-		
+	func setTimeLabel(_ timestamp: Int?) {
+		if let timestamp = timestamp {
+			timeLabel.isHidden = false
+			timeLabel.text = DateUtils.getBriefRelativeTimeSpanString(timeStamp: timestamp)
+		} else {
+			timeLabel.isHidden = true
+			timeLabel.text = nil
+		}
 	}
 
 	func setColor(_ color: UIColor) {