diff options
author | Vitaly Takmazov | 2018-11-12 14:39:31 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-12 14:39:31 +0300 |
commit | b6dc38e5f6bb7a1b820cd23d761484610212c11d (patch) | |
tree | 2a2df5f2cf57df73a6b12f86c21607ae26294bad | |
parent | 4dbf1bdf6ce14800bb4e67b6d0ee8bb782564f0f (diff) |
Entities
-rw-r--r-- | Juick.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | Juick/Model/Entity.h | 19 | ||||
-rw-r--r-- | Juick/Model/Entity.m | 13 | ||||
-rw-r--r-- | Juick/Model/Message.h | 2 | ||||
-rw-r--r-- | Juick/Model/Message.m | 1 | ||||
-rw-r--r-- | Juick/Supporting Files/Juick-Info.plist | 2 | ||||
-rw-r--r-- | Juick/Views/MessageCell.m | 43 | ||||
-rw-r--r-- | JuickPush/Info.plist | 2 |
8 files changed, 85 insertions, 3 deletions
diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 8072ad2..7500fb5 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 706F9651FDACFE30A8DDC1DF /* libPods-Juick.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 22EE2B61A53B73723D255877 /* libPods-Juick.a */; }; + 772B4E6C2199811E0029706E /* Entity.m in Sources */ = {isa = PBXBuildFile; fileRef = 772B4E6B2199811E0029706E /* Entity.m */; }; 77317BAC181BBE8500D60005 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAB181BBE8500D60005 /* Foundation.framework */; }; 77317BAE181BBE8500D60005 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAD181BBE8500D60005 /* CoreGraphics.framework */; }; 77317BB0181BBE8500D60005 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAF181BBE8500D60005 /* UIKit.framework */; }; @@ -85,6 +86,8 @@ /* Begin PBXFileReference section */ 22EE2B61A53B73723D255877 /* libPods-Juick.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Juick.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 770A428F1E8881CB000B206A /* DeviceRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceRegistration.h; sourceTree = "<group>"; }; + 772B4E6A2199811E0029706E /* Entity.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Entity.h; sourceTree = "<group>"; }; + 772B4E6B2199811E0029706E /* Entity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Entity.m; sourceTree = "<group>"; }; 77317BA8181BBE8500D60005 /* Juick.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Juick.app; sourceTree = BUILT_PRODUCTS_DIR; }; 77317BAB181BBE8500D60005 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 77317BAD181BBE8500D60005 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -287,6 +290,8 @@ 774528C11F930C06004D110B /* Attachment.m */, 773E639B204BD0F2008B8F8D /* Chat.h */, 773E639C204BD0F2008B8F8D /* Chat.m */, + 772B4E6A2199811E0029706E /* Entity.h */, + 772B4E6B2199811E0029706E /* Entity.m */, ); path = Model; sourceTree = "<group>"; @@ -550,6 +555,7 @@ 773E639D204BD0F2008B8F8D /* Chat.m in Sources */, 77B8DCD62093FC03000DBB04 /* BlogViewController.m in Sources */, 773E639A204BCE6D008B8F8D /* DialogsViewController.m in Sources */, + 772B4E6C2199811E0029706E /* Entity.m in Sources */, 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */, 77317BC2181BBE8500D60005 /* MessagesViewController.m in Sources */, 77B099A6189D57F000A84F59 /* User.m in Sources */, diff --git a/Juick/Model/Entity.h b/Juick/Model/Entity.h new file mode 100644 index 0000000..13142f1 --- /dev/null +++ b/Juick/Model/Entity.h @@ -0,0 +1,19 @@ +// +// Entity.h +// Juick +// +// Created by Vitaly Takmazov on 12/11/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@interface Entity : NSObject + +@property NSString *type; +@property NSString *text; +@property NSString *link; +@property NSNumber *start; +@property NSNumber *end; + +@end diff --git a/Juick/Model/Entity.m b/Juick/Model/Entity.m new file mode 100644 index 0000000..ac53a1f --- /dev/null +++ b/Juick/Model/Entity.m @@ -0,0 +1,13 @@ +// +// Entity.m +// Juick +// +// Created by Vitaly Takmazov on 12/11/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +#import "Entity.h" + +@implementation Entity + +@end diff --git a/Juick/Model/Message.h b/Juick/Model/Message.h index 5eab279..45b14fa 100644 --- a/Juick/Model/Message.h +++ b/Juick/Model/Message.h @@ -9,6 +9,7 @@ #import <Foundation/Foundation.h> #import "User.h" #import "Attachment.h" +#import "Entity.h" @interface Message : NSObject @@ -17,6 +18,7 @@ @property User *user; @property NSString *text; @property NSArray<NSString *> *tags; +@property NSArray<Entity *> *entities; @property NSString *timestamp; @property NSString *attach; @property NSString *repliesBy; diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m index d4d6a88..2a4090a 100644 --- a/Juick/Model/Message.m +++ b/Juick/Model/Message.m @@ -15,6 +15,7 @@ return @{@"text" : @"body", @"mid" : @"mid", @"rid" : @"rid", + @"entities": @"entities", @"attach" : @"photo.small", @"repliesCount": @"replies", @"repliesBy": @"repliesby"}; diff --git a/Juick/Supporting Files/Juick-Info.plist b/Juick/Supporting Files/Juick-Info.plist index 2e2031f..75e1360 100644 --- a/Juick/Supporting Files/Juick-Info.plist +++ b/Juick/Supporting Files/Juick-Info.plist @@ -21,7 +21,7 @@ <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> - <string>80</string> + <string>81</string> <key>ITSAppUsesNonExemptEncryption</key> <false/> <key>LSApplicationCategoryType</key> diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m index 851e097..99fb296 100644 --- a/Juick/Views/MessageCell.m +++ b/Juick/Views/MessageCell.m @@ -9,6 +9,7 @@ #import "MessageCell.h" #import "ColorScheme.h" #import "APIClient.h" +#import "Entity.h" @implementation MessageCell @@ -70,7 +71,47 @@ } else { self.summary.text = nil; } - self.text.text = [msg.text stringByDecodingHTMLEntities]; + self.text.attributedText = nil; + if (msg.text) { + NSMutableAttributedString *txt = [[NSMutableAttributedString alloc] initWithString:[msg.text stringByDecodingHTMLEntities] attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]}]; + [txt beginEditing]; + for (NSDictionary *entity in msg.entities) { + NSUInteger start = [[entity objectForKey:@"start"] unsignedIntegerValue]; + NSUInteger end = [[entity objectForKey:@"end"] unsignedIntegerValue]; + NSRange currentRange = NSMakeRange(start, end - start); + [txt addAttribute:@"displayText" value:[entity objectForKey:@"text"] range:currentRange]; + if ([[entity objectForKey:@"type"] isEqualToString:@"a"]) { + [txt addAttribute:NSLinkAttributeName value:[entity objectForKey:@"url"] range:currentRange]; + } + if ([[entity objectForKey:@"type"] isEqualToString:@"q"]) { + [txt addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:currentRange]; + } + if ([[entity objectForKey:@"type"] isEqualToString:@"u"]) { + [txt addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:currentRange]; + } + UIFontDescriptor* fontDescriptor = [UIFontDescriptor + preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; + if ([[entity objectForKey:@"type"] isEqualToString:@"b"]) { + UIFontDescriptor* boldFontDescriptor = [fontDescriptor + fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; + UIFont* boldFont = [UIFont fontWithDescriptor:boldFontDescriptor size: 0.0]; + [txt addAttribute:NSFontAttributeName value:boldFont range:currentRange]; + } + if ([[entity objectForKey:@"type"] isEqualToString:@"i"]) { + UIFontDescriptor* italicFontDescriptor = [fontDescriptor + fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic]; + UIFont* italicFont = [UIFont fontWithDescriptor:italicFontDescriptor size: 0.0]; + [txt addAttribute:NSFontAttributeName value:italicFont range:currentRange]; + } + } + [txt enumerateAttribute:@"displayText" inRange:NSMakeRange(0, [txt length]) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { + if (value) { + [txt replaceCharactersInRange:range withString:value]; + } + }]; + [txt endEditing]; + self.text.attributedText = txt; + } [self.tags removeAllTags]; if ([msg.tags count] > 0) { [msg.tags enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { diff --git a/JuickPush/Info.plist b/JuickPush/Info.plist index eafc25d..7e04d54 100644 --- a/JuickPush/Info.plist +++ b/JuickPush/Info.plist @@ -19,7 +19,7 @@ <key>CFBundleShortVersionString</key> <string>1.0</string> <key>CFBundleVersion</key> - <string>80</string> + <string>81</string> <key>NSExtension</key> <dict> <key>NSExtensionPointIdentifier</key> |