Photo editor fixes

This commit is contained in:
Ilya Laktyushin 2020-06-08 13:30:18 +03:00
parent f529ec0793
commit e7b181e12a
8 changed files with 71 additions and 26 deletions

View File

@ -543,7 +543,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f;
- (TGPhotoEditorTab)availableTabs
{
TGPhotoEditorTab result = TGPhotoEditorPaintTab | TGPhotoEditorEraserTab | TGPhotoEditorTextTab;
if (_enableStickers) {
if (_enableStickers && _stickersContext != nil) {
result |= TGPhotoEditorStickerTab;
}
return result;

View File

@ -601,15 +601,35 @@ const CGFloat TGPhotoTextSelectionViewHandleSide = 30.0f;
[super showCGGlyphs:glyphs positions:positions count:glyphCount font:font matrix:textMatrix attributes:attributes inContext:context];
}
- (void)prepare {
_path = nil;
[self.rectArray removeAllObjects];
[self enumerateLineFragmentsForGlyphRange:NSMakeRange(0, self.textStorage.string) usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
bool ignoreRange = false;
NSRange characterRange = [self characterRangeForGlyphRange:glyphRange actualGlyphRange:nil];
NSString *substring = [[self.textStorage string] substringWithRange:characterRange];
if ([substring stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]].length == 0) {
ignoreRange = true;
}
if (!ignoreRange) {
CGRect newRect = CGRectMake(usedRect.origin.x - self.frameWidthInset, usedRect.origin.y, usedRect.size.width + self.frameWidthInset * 2, usedRect.size.height);
NSValue *value = [NSValue valueWithCGRect:newRect];
[self.rectArray addObject:value];
}
}];
[self preProccess];
}
- (void)drawBackgroundForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)origin {
[super drawBackgroundForGlyphRange:glyphsToShow atPoint:origin];
// [super drawBackgroundForGlyphRange:glyphsToShow atPoint:origin];
if (self.frameColor != nil) {
NSRange range = [self characterRangeForGlyphRange:glyphsToShow actualGlyphRange:NULL];
NSRange glyphRange = [self glyphRangeForCharacterRange:range actualCharacterRange:NULL];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, origin.x, origin.y);
@ -618,22 +638,23 @@ const CGFloat TGPhotoTextSelectionViewHandleSide = 30.0f;
CGContextSetFillColorWithColor(context, self.frameColor.CGColor);
CGContextSetStrokeColorWithColor(context, self.frameColor.CGColor);
_path = nil;
[self.rectArray removeAllObjects];
[self enumerateLineFragmentsForGlyphRange:glyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
bool ignoreRange = false;
NSString *substring = [[self.textStorage string] substringWithRange:glyphRange];
if ([substring stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]].length == 0) {
ignoreRange = true;
}
if (!ignoreRange) {
CGRect newRect = CGRectMake(usedRect.origin.x - self.frameWidthInset, usedRect.origin.y, usedRect.size.width + self.frameWidthInset * 2, usedRect.size.height);
NSValue *value = [NSValue valueWithCGRect:newRect];
[self.rectArray addObject:value];
}
}];
[self prepare];
// _path = nil;
// [self.rectArray removeAllObjects];
//
// [self enumerateLineFragmentsForGlyphRange:glyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer * _Nonnull textContainer, NSRange glyphRange, BOOL * _Nonnull stop) {
// bool ignoreRange = false;
// NSString *substring = [[self.textStorage string] substringWithRange:glyphRange];
// if ([substring stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]].length == 0) {
// ignoreRange = true;
// }
//
// if (!ignoreRange) {
// CGRect newRect = CGRectMake(usedRect.origin.x - self.frameWidthInset, usedRect.origin.y, usedRect.size.width + self.frameWidthInset * 2, usedRect.size.height);
// NSValue *value = [NSValue valueWithCGRect:newRect];
// [self.rectArray addObject:value];
// }
// }];
[self preProccess];

View File

@ -833,7 +833,7 @@ typedef enum
_didPlayToEndObserver = [[TGObserverProxy alloc] initWithTarget:self targetSelector:@selector(playerItemDidPlayToEndTime:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
_videoView = [[TGModernGalleryVideoView alloc] initWithFrame: CGRectInset(_previewView.frame, -1.0, -1.0) player:_player];
_videoView = [[TGModernGalleryVideoView alloc] initWithFrame: CGRectInset(_previewView.frame, -3.0, -3.0) player:_player];
[_previewView.superview insertSubview:_videoView belowSubview:_previewView];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(unmutePressed)];

View File

@ -24,6 +24,7 @@ private enum RequestEditMessageInternalError {
public enum RequestEditMessageError {
case generic
case restricted
case textTooLong
}
public func requestEditMessage(account: Account, messageId: MessageId, text: String, media: RequestEditMessageMedia, entities: TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false, scheduleTime: Int32? = nil) -> Signal<RequestEditMessageResult, RequestEditMessageError> {
@ -173,6 +174,8 @@ private func requestEditMessageInternal(postbox: Postbox, network: Network, stat
|> mapError { error -> RequestEditMessageInternalError in
if error.errorDescription.hasPrefix("FILEREF_INVALID") || error.errorDescription.hasPrefix("FILE_REFERENCE_") {
return .invalidReference
} else if error.errorDescription.hasSuffix("_TOO_LONG") {
return .error(.textTooLong)
} else if error.errorDescription.hasPrefix("CHAT_SEND_") && error.errorDescription.hasSuffix("_FORBIDDEN") {
return .error(.restricted)
}

View File

@ -1923,8 +1923,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
break
}
}
let signal = requestEditMessage(account: strongSelf.context.account, messageId: messageId, text: message.text, media: .keep, entities: entities, disableUrlPreview: false, scheduleTime: time)
strongSelf.editMessageDisposable.set((signal |> deliverOnMainQueue).start(next: { result in
strongSelf.editMessageDisposable.set((requestEditMessage(account: strongSelf.context.account, messageId: messageId, text: message.text, media: .keep, entities: entities, disableUrlPreview: false, scheduleTime: time) |> deliverOnMainQueue).start(next: { result in
}, error: { error in
}))
}
@ -4983,7 +4982,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let text: String
switch error {
case .generic:
case .generic, .textTooLong:
text = strongSelf.presentationData.strings.Channel_EditMessageErrorGeneric
case .restricted:
text = strongSelf.presentationData.strings.Group_ErrorSendRestrictedMedia

View File

@ -313,10 +313,23 @@ private func galleryItems(account: Account, results: [ChatContextResult], curren
return (galleryItems, focusItem)
}
func presentLegacyWebSearchGallery(context: AccountContext, peer: Peer?, presentationData: PresentationData, results: [ChatContextResult], current: ChatContextResult, selectionContext: TGMediaSelectionContext?, editingContext: TGMediaEditingContext, updateHiddenMedia: @escaping (String?) -> Void, initialLayout: ContainerViewLayout?, transitionHostView: @escaping () -> UIView?, transitionView: @escaping (ChatContextResult) -> UIView?, completed: @escaping (ChatContextResult) -> Void, present: (ViewController, Any?) -> Void) {
func presentLegacyWebSearchGallery(context: AccountContext, peer: Peer?, presentationData: PresentationData, results: [ChatContextResult], current: ChatContextResult, selectionContext: TGMediaSelectionContext?, editingContext: TGMediaEditingContext, updateHiddenMedia: @escaping (String?) -> Void, initialLayout: ContainerViewLayout?, transitionHostView: @escaping () -> UIView?, transitionView: @escaping (ChatContextResult) -> UIView?, completed: @escaping (ChatContextResult) -> Void, presentStickers: ((@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?)?, present: (ViewController, Any?) -> Void) {
let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme, initialLayout: nil)
legacyController.statusBar.statusBarStyle = presentationData.theme.rootController.statusBarStyle.style
let paintStickersContext = LegacyPaintStickersContext(context: context)
paintStickersContext.presentStickersController = { completion in
if let presentStickers = presentStickers {
return presentStickers({ file, animated, view, rect in
let coder = PostboxEncoder()
coder.encodeRootObject(file)
completion?(coder.makeData(), animated, view, rect)
})
} else {
return nil
}
}
let controller = TGModernGalleryController(context: legacyController.context)!
controller.asyncTransitionIn = true
legacyController.bind(controller: controller)
@ -324,6 +337,7 @@ func presentLegacyWebSearchGallery(context: AccountContext, peer: Peer?, present
let (items, focusItem) = galleryItems(account: context.account, results: results, current: current, selectionContext: selectionContext, editingContext: editingContext)
let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: false, allowCaptionEntities: true, hasTimer: false, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: false, hasCamera: false, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder))!
model.stickersContext = paintStickersContext
if let peer = peer {
model.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id)
}

View File

@ -149,6 +149,12 @@ public final class WebSearchController: ViewController {
private var navigationContentNode: WebSearchNavigationContentNode?
var presentStickers: ((@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?)? {
didSet {
self.controllerNode.presentStickers = self.presentStickers
}
}
public init(context: AccountContext, peer: Peer?, configuration: SearchBotsConfiguration, mode: WebSearchControllerMode) {
self.context = context
self.mode = mode

View File

@ -178,6 +178,8 @@ class WebSearchControllerNode: ASDisplayNode {
var cancel: (() -> Void)?
var dismissInput: (() -> Void)?
var presentStickers: ((@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?)?
init(context: AccountContext, presentationData: PresentationData, controllerInteraction: WebSearchControllerInteraction, peer: Peer?, mode: WebSearchMode) {
self.context = context
self.theme = presentationData.theme
@ -703,7 +705,7 @@ class WebSearchControllerNode: ASDisplayNode {
strongSelf.controllerInteraction.sendSelected(results, result)
strongSelf.cancel?()
}
}, present: present)
}, presentStickers: self.presentStickers, present: present)
}
} else {
if let results = self.currentProcessedResults?.results {