mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-13 06:46:16 +10:00
use & save roundMini / roundNano
This commit is contained in:
@@ -167,6 +167,27 @@ class AvatarCache {
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
avatarCompletion.completion(avatar)
|
||||
}
|
||||
|
||||
let realm = Realm()
|
||||
|
||||
if let avatarObject = avatarWithAvatarURLString(avatarURLString, inRealm: realm) {
|
||||
switch avatarCompletion.radius {
|
||||
case YepConfig.ConversationCell.avatarSize * 0.5:
|
||||
if avatarObject.roundMini.length == 0 {
|
||||
realm.write {
|
||||
avatarObject.roundMini = UIImageJPEGRepresentation(avatar, 0.9)
|
||||
}
|
||||
}
|
||||
case YepConfig.chatCellAvatarSize() * 0.5:
|
||||
if avatarObject.roundNano.length == 0 {
|
||||
realm.write {
|
||||
avatarObject.roundNano = UIImageJPEGRepresentation(avatar, 0.9)
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +335,30 @@ class AvatarCache {
|
||||
|
||||
} else {
|
||||
|
||||
// 再看看是否已有裁剪后的圆图
|
||||
|
||||
if let avatar = avatarWithAvatarURLString(avatarURLString, inRealm: Realm()) {
|
||||
|
||||
switch radius {
|
||||
case YepConfig.ConversationCell.avatarSize * 0.5:
|
||||
if avatar.roundMini.length > 0 {
|
||||
if let image = UIImage(data: avatar.roundMini) {
|
||||
completeWithImage(image, avatarURLString: avatarURLString)
|
||||
return
|
||||
}
|
||||
}
|
||||
case YepConfig.chatCellAvatarSize() * 0.5:
|
||||
if avatar.roundNano.length > 0 {
|
||||
if let image = UIImage(data: avatar.roundNano) {
|
||||
completeWithImage(image, avatarURLString: avatarURLString)
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let oldAvatarURLString = user.avatar?.avatarURLString
|
||||
|
||||
dispatch_async(self.cacheQueue) {
|
||||
|
||||
Reference in New Issue
Block a user