From d7e7bd1de8d16781ddf7590818d60fc75fef329c Mon Sep 17 00:00:00 2001
From: Oliver Wiese <oliver.wiese@fu-berlin.de>
Date: Fri, 21 May 2021 10:03:53 +0200
Subject: [PATCH] active avatars

---
 enzevalos_iphone/ContactHandler.swift         |  2 +-
 enzevalos_iphone/StudySettings.swift          |  3 +-
 .../SwiftUI/Inbox/simple/MailRowView.swift    | 46 +++++++++++++++++--
 3 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/enzevalos_iphone/ContactHandler.swift b/enzevalos_iphone/ContactHandler.swift
index 7c652f9c..6f0351d1 100644
--- a/enzevalos_iphone/ContactHandler.swift
+++ b/enzevalos_iphone/ContactHandler.swift
@@ -24,7 +24,7 @@ import SwiftUI
 
 // TODO: Mark displayname as from CNContact
 class ContactHandler {
-    static var cartoons = false
+    static var cartoons = StudySettings.useAvatars
     
     private let store = CNContactStore()
     static let handler = ContactHandler()
diff --git a/enzevalos_iphone/StudySettings.swift b/enzevalos_iphone/StudySettings.swift
index e335b092..0256810b 100644
--- a/enzevalos_iphone/StudySettings.swift
+++ b/enzevalos_iphone/StudySettings.swift
@@ -53,7 +53,8 @@ class StudySettings {
     static var securityIndicator: SecurityIndicator = SecurityIndicator.load() as! SecurityIndicator
     static var invitationsmode: Inviation = Inviation.load() as! Inviation
     
-    static var showCategorizedInterface = true
+    static var showCategorizedInterface = false
+    static var useAvatars = true
     
     public static var invitationEnabled: Bool {
         get {
diff --git a/enzevalos_iphone/SwiftUI/Inbox/simple/MailRowView.swift b/enzevalos_iphone/SwiftUI/Inbox/simple/MailRowView.swift
index 236c419c..5ae7e849 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/simple/MailRowView.swift
+++ b/enzevalos_iphone/SwiftUI/Inbox/simple/MailRowView.swift
@@ -28,25 +28,54 @@ struct MailRowView <M: DisplayMail>: View {
     var activateOnTap: Bool = true
     
     var body: some View {
-       body_v2
+       body_v3
     }
     
     private var content: String {
         get {
             let max = 500
             if mail.subject.count < max {
-                return mail.subject + "\n" + mail.body.prefix(max - mail.subject.count)
+                return mail.subject + "\n" + mail.body.prefix(max - mail.subject.count).replacingOccurrences(of: "\n", with: " ")
             }
             return mail.subject
         }
     }
     
+    private var body_v3: some View {
+        HStack(alignment:.center){
+            avatar
+                .padding(StudySettings.useAvatars ? -15 : 0)
+                .frame(width: 60, height: 60, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
+            VStack (alignment: .leading){
+                HStack{
+                    // Sender name
+                   sender
+                    
+                    Spacer()
+                    if !mail.displayAttachments.isEmpty {
+                        Image(systemName: "paperclip")
+                            .font(.caption)
+                            .foregroundColor(.secondary)
+                    }
+                    // Arrival time
+                    Text(mail.date.timeAgoText())
+                        .font(.caption)
+                }
+                // Subject
+                Text(content)
+                    .font(.caption)
+                    .lineLimit(3)
+            }
+        }
+        .foregroundColor(mail.isRead ? .secondary : .primary)
+    }
+    
     private var body_v2: some View {
         VStack(alignment: .leading) {
             HStack{
                 // Sender name
                 Text(mail.sender.name)
-                    .fontWeight(mail.isRead ? .regular : .medium)
+                    .fontWeight(mail.isRead ? .regular : .light)
                     .lineLimit(2)
                 
                 Spacer()
@@ -64,7 +93,7 @@ struct MailRowView <M: DisplayMail>: View {
             }
             HStack {
                 avatar
-                                
+                    .padding(StudySettings.useAvatars ? -15 : 0)
                 // Subject
                 Text(content)
                     .font(.caption)
@@ -132,6 +161,15 @@ struct MailRowView <M: DisplayMail>: View {
                 .hidden()
             )
     }
+    
+    private var sender: some View {
+        Text(mail.sender.name)
+            .font(mail.sender.name.contains("@") ? .callout : .body)
+            .fontWeight(mail.isRead ? .regular : .light)
+            .lineLimit(1)
+            .truncationMode(.head)
+            .minimumScaleFactor(0.5)
+    }
 }
 
 struct MailRowView_Previews: PreviewProvider {
-- 
GitLab