From c9cc1ee64e44f5823d9d4d3175fc00ca66067a9e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 14 Sep 2020 11:31:45 +1000 Subject: [PATCH] Fix profile picture issue --- Signal/Images.xcassets/Loki V2/Contents.json | 6 +-- .../SessionWhite16.imageset/Contents.json | 23 ++++++++++ .../SessionWhite16.png | Bin 0 -> 459 bytes .../SessionWhite16@2x.png | Bin 0 -> 989 bytes .../SessionWhite16@3x.png | Bin 0 -> 1469 bytes .../Components/ConversationTitleView.swift | 2 +- .../OWSConversationSettingsViewController.m | 18 ++------ .../Components/ProfilePictureView.swift | 40 +++++++++++++----- 8 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/Contents.json create mode 100644 Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16.png create mode 100644 Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@2x.png create mode 100644 Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@3x.png diff --git a/Signal/Images.xcassets/Loki V2/Contents.json b/Signal/Images.xcassets/Loki V2/Contents.json index da4a164c9..73c00596a 100644 --- a/Signal/Images.xcassets/Loki V2/Contents.json +++ b/Signal/Images.xcassets/Loki V2/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/Contents.json b/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/Contents.json new file mode 100644 index 000000000..4bfca47bb --- /dev/null +++ b/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "SessionWhite16.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "SessionWhite16@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "SessionWhite16@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16.png b/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16.png new file mode 100644 index 0000000000000000000000000000000000000000..a941b7f011604ff6d24f84ae53888ed25e9400bc GIT binary patch literal 459 zcmV;+0W|)JP)E6p+P`@}ivdGG=guVZ59F zBZ66^$xB)eCtTcGYd1}ZV7+D7){RwZ5~n77cz8jBlI!smD$7%zX+aXXD2FT(I1Vg~ zF|5IsP1hlg>))qk(Kzlg6-XYyC%*BDEvzFRe4GVW-~e52ZV)%fPR>FO?==L_WK3gdi7xj6V_Ep;~9^p^eX&N@@}Bp zYVsK_l&r5Sj|~=jrbf5|tLRphF)W8kEDL=fMI8!gueI7WO{e;(mT;+w6>X$h%zL6nGgHGYFdg9O2!8zHJ=o-MC2tOrWQ%m zHi;3YY(qna&9wKq{r~Rkth0Hx=RC9XuU}_7=YFpLx$pbBulqiZcw~%;!X*`K23cS+ zm?Wc<0WF{gTn5)1$LVk%Iv&&UxEun7AW?tV3fg6KV(f`vipIJJ_QJf;eMr;kxSR&t zK^M5qHv}(1hm20HaT+KFDWDeQ!2B~!qroxI1Ac;S+WRpPVvz;liLpBCK3JxP9bk(D zAT?jF9v?uGXm6?WV4MUXHI4;!YM#R^-URx^W?h#AAjIXR4}1l2Ad$w4z&Fq&0f{|^ zV!%w$Lq8h3OR86bRW_IlzJO}J%`465H4=byewTt;&86eK&+gwBJKUML`2h1_d<5f2 z%>xNxnzDGLgZ&^`y-M968^CYS0FuRDFS0;0_&x$Zz%PwWu7la$AQQk{9fm6)Y;8uH zeDkk*bdA1O8o_ID736`KP=Qv0cN*XZSPmQ?#;%Fc-kk$!AYRw46Rr~swieWDkS1_q z(9nc7E(a-~)Y$50wAZJ=Eb%L2Yw88iuW%F&f`k!_`M(2}fJ-``?r0Q)IKSpm#@5v; z(5pe78M}ET3^g9|Te1#3)EB3o^Pc#X&JztDfj$jX39`YyP{tl}&hHNJRNHleBI9S* zL!%fD6XzKe7@MV3D|j=U@sJmo1`Zp$F);b|4A+=jWSOy5ra_a;#Z4Zs%EP?8JO72C z+t{_8>TQsyNz~yP8a5iKK(v4(5`N@FNA9A=X7UakeM)dS3c5js*rU%!vD@Wv; zVmFoMvVi9Lk`BAw%@V7}N+Hqw~qARgc+OK{>?Zw0L1Oxijc zSBjnE+_6q9O)CDm5ESX{ioYuX4>EN9wt<}gF?WqTu%EOc&Es)d4f4T8z(YW^52H{^kQI>U^eV9*e>E^2^ws$X*SPJJBln6|00000 LNkvXXu0mjfyl}mk literal 0 HcmV?d00001 diff --git a/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@3x.png b/Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..823fb5e1d6eb9ff4d992659ab1eb7a486999dc1f GIT binary patch literal 1469 zcmV;u1w#6XP)RIPbr{{M8zVaF==Yh#wdwUv4SyxUU}h#iI|{VU{DDLL@v;1F9dHiF~owR zXksu{6Ez9~5gSV=jR{}^DHan2D`5C(g_hEf_su!Oemg9sGrP;qn>?AFGc#x2Idgu# zb7oU=6{+fQZ0-hgKrOf*+yKT%anud|1Fhg!@C|5BrBWBKc_qw_0S%xH^y&52Meqw) z684q~8Rh=7V41kmwL0TVpo^zU;WZ3Q1UH7#H-I%L=|9C9_GatBCUBFv;1943Yy~HZ zYDA)uO`!E)ha^C#v*)mB64z$v zbq1f}bM4-RD5iy*ANom){vJ#S3iWYL;ZGY^N|N z!c*+*S-oaX#V0*%y@h{ zNQZAS6ZHBM&w@A9g`05x|z%;A=A`8uv+uzp@N8?nY4v6 z@Ao&IA1;-F42RCE0~>t_Td|N{0}~{UXb9W`J_V;jra1z!eol#M*q=LI-4NUoGX1~0 z5qO&9BV=%!x`uKzbOZL?oVip-F>LZ>?7)V-Q?si|2dI&Jgbd2nbxCZ5c2$U77rU_L zsD^#MX?0yFyHeYud}T{IH9!Ux*zm+#LAki_(~4_v4}hoS>RN{Z;1!7=bulm(bQp*Q zJ<<uZB9;T%5JXr@8(?L8Defv@CV@SD28BVRE9S}rlA zZuRGFli#;sl3iPyiA@7|&|JqjqD@@1e@>#Q9W>%K9+sGbr#rFPC$9SaD{i6kavWh> zK8MYh!DK11;Nf%Q>%CxbXfTN#;CYP@@Dx+<@uI1s+nKOHGpm-Y+;x&5!OvXt_B&aM zth1H=_#W`HBukvtcl+PvG|a_gHa-T>AEJ>YYHdQ?BqNyP_0#apeut~;e@XJhAShU! zI!VK2e&@VgIc-UT9sw2pcPkACD}!StVJkoCLf86W7wo0s7N5YcH?t%mQum#3DY(lg z?FZk}Fc&K5o(=Cw%_rh7tR4o7%>Iwy0H1_0>~1q~d;lt?M8dsCs9SYEVLb86KzVQi zgXfpbK?dWEr6_52k>V=Np1CtjSQwmRgP)DqJS{HJppJmA#eGl=zJL~5>|?n$!3AqB z;>-rOo8!m8GvKG-qoOrjh0SUSBBG3ri(8rRmcom@0ADo&^|7I2Y-I0%O<7++!-DZ8 zV3!sqCXOmj6k5TXV012jsT_tm406eIzPLDJhPcsYxD-bm2RO>^7WdZ!_67%YPKTgN XSFNTq1vky~00000NkvXXu0mjfthB60 literal 0 HcmV?d00001 diff --git a/Signal/src/Loki/Components/ConversationTitleView.swift b/Signal/src/Loki/Components/ConversationTitleView.swift index 89c8aee7f..c811495f1 100644 --- a/Signal/src/Loki/Components/ConversationTitleView.swift +++ b/Signal/src/Loki/Components/ConversationTitleView.swift @@ -17,7 +17,7 @@ final class ConversationTitleView : UIView { // MARK: Components private lazy var profilePictureView: ProfilePictureView = { let result = ProfilePictureView() - let size = Values.smallProfilePictureSize + let size: CGFloat = 40 result.set(.width, to: size) result.set(.height, to: size) result.size = size diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 7acc435d0..99701d8fb 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -954,20 +954,8 @@ const CGFloat kIconViewLength = 24; CGFloat horizontalSpacing = isSmallScreen ? LKValues.largeSpacing : LKValues.veryLargeSpacing; stackView.layoutMargins = UIEdgeInsetsMake(LKValues.mediumSpacing, horizontalSpacing, LKValues.mediumSpacing, horizontalSpacing); [stackView setLayoutMarginsRelativeArrangement:YES]; - - if (self.isGroupThread) { - TSGroupThread* groupThread = (TSGroupThread *)self.thread; - if (groupThread.isPublicChat && groupThread.groupModel.groupImage != nil - && ![groupThread.groupModel.groupName isEqual:@"Loki Public Chat"] && ![groupThread.groupModel.groupName isEqual:@"Session Public Chat"]) { - profilePictureView.openGroupProfilePicture = groupThread.groupModel.groupImage; - profilePictureView.isRSSFeed = false; - } else { - profilePictureView.hexEncodedPublicKey = @""; - profilePictureView.isRSSFeed = true; // For now just always show the Session logo - } - } else { - profilePictureView.hexEncodedPublicKey = self.thread.contactIdentifier; - + + if (!self.isGroupThread) { SRCopyableLabel *subtitleView = [SRCopyableLabel new]; subtitleView.textColor = LKColors.text; subtitleView.font = [LKFonts spaceMonoOfSize:LKValues.smallFontSize]; @@ -978,7 +966,7 @@ const CGFloat kIconViewLength = 24; [stackView addArrangedSubview:subtitleView]; } - [profilePictureView update]; + [profilePictureView updateForThread:self.thread]; return stackView; } diff --git a/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift b/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift index d1242cdc8..305ab0d2f 100644 --- a/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift +++ b/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift @@ -3,6 +3,8 @@ public final class ProfilePictureView : UIView { private var imageViewWidthConstraint: NSLayoutConstraint! private var imageViewHeightConstraint: NSLayoutConstraint! + private var additionalImageViewWidthConstraint: NSLayoutConstraint! + private var additionalImageViewHeightConstraint: NSLayoutConstraint! @objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations @objc public var isRSSFeed = false @objc public var hexEncodedPublicKey: String! @@ -37,8 +39,8 @@ public final class ProfilePictureView : UIView { additionalImageView.pin(.trailing, to: .trailing, of: self) additionalImageView.pin(.bottom, to: .bottom, of: self) let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize) - additionalImageView.set(.width, to: additionalImageViewSize) - additionalImageView.set(.height, to: additionalImageViewSize) + additionalImageViewWidthConstraint = additionalImageView.set(.width, to: additionalImageViewSize) + additionalImageViewHeightConstraint = additionalImageView.set(.height, to: additionalImageViewSize) additionalImageView.layer.cornerRadius = additionalImageViewSize / 2 } @@ -46,16 +48,16 @@ public final class ProfilePictureView : UIView { @objc(updateForThread:) public func update(for thread: TSThread) { openGroupProfilePicture = nil - if thread.isGroupThread() { + if let thread = thread as? TSGroupThread { if thread.name() == "Loki Public Chat" || thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat hexEncodedPublicKey = "" isRSSFeed = true - } else if let openGroupProfilePicture = (thread as! TSGroupThread).groupModel.groupImage { // An open group with a profile picture + } else if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture self.openGroupProfilePicture = openGroupProfilePicture isRSSFeed = false - } else if (thread as! TSGroupThread).groupModel.groupType == .openGroup - || (thread as! TSGroupThread).groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed + } else if thread.groupModel.groupType == .openGroup + || thread.groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed hexEncodedPublicKey = "" isRSSFeed = true } else { // A closed group @@ -66,7 +68,7 @@ public final class ProfilePictureView : UIView { additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : "" isRSSFeed = false } - } else { // A one-on-one chat + } else { // A one-to-one chat hexEncodedPublicKey = thread.contactIdentifier()! additionalHexEncodedPublicKey = nil isRSSFeed = false @@ -78,13 +80,26 @@ public final class ProfilePictureView : UIView { AssertIsOnMainThread() func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? { guard !hexEncodedPublicKey.isEmpty else { return nil } - return OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) ?? Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey, size: size) + if let profilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) { + return profilePicture + } else { + let displayName = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey + return Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: displayName, size: size) + } } let size: CGFloat if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil { - size = Values.smallProfilePictureSize + if self.size == 40 { + size = 32 + } else if self.size == Values.largeProfilePictureSize { + size = 56 + } else { + size = Values.smallProfilePictureSize + } imageViewWidthConstraint.constant = size imageViewHeightConstraint.constant = size + additionalImageViewWidthConstraint.constant = size + additionalImageViewHeightConstraint.constant = size additionalImageView.isHidden = false additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey) } else { @@ -98,9 +113,14 @@ public final class ProfilePictureView : UIView { imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey)) imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant imageView.layer.cornerRadius = size / 2 + additionalImageView.layer.cornerRadius = size / 2 imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit if isRSSFeed { - imageView.image = (size == 45) ? #imageLiteral(resourceName: "SessionWhite24") : #imageLiteral(resourceName: "SessionWhite40") + switch size { + case Values.smallProfilePictureSize..