mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-28 14:59:44 +00:00
Merge commit '39381dd1895dc77ced7b31b4bb6aa6047c0907d2'
This commit is contained in:
@@ -522,6 +522,8 @@
|
||||
D04269121F586E430037ECE8 /* TGVideoCameraPipeline.m in Sources */ = {isa = PBXBuildFile; fileRef = D04269101F586E430037ECE8 /* TGVideoCameraPipeline.m */; };
|
||||
D04269151F586EC80037ECE8 /* TGVideoMessageCaptureController.h in Headers */ = {isa = PBXBuildFile; fileRef = D04269131F586EC80037ECE8 /* TGVideoMessageCaptureController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D04269161F586EC80037ECE8 /* TGVideoMessageCaptureController.m in Sources */ = {isa = PBXBuildFile; fileRef = D04269141F586EC80037ECE8 /* TGVideoMessageCaptureController.m */; };
|
||||
D07ABBA8202A193A003671DE /* TGWallpaperController.m in Sources */ = {isa = PBXBuildFile; fileRef = D07ABBA6202A1939003671DE /* TGWallpaperController.m */; };
|
||||
D07ABBA9202A193A003671DE /* TGWallpaperController.h in Headers */ = {isa = PBXBuildFile; fileRef = D07ABBA7202A1939003671DE /* TGWallpaperController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D07BC6CF1F2A18B700ED97AA /* TGCameraMainPhoneView.h in Headers */ = {isa = PBXBuildFile; fileRef = D07BC6C91F2A18B700ED97AA /* TGCameraMainPhoneView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D07BC6D01F2A18B700ED97AA /* TGCameraMainPhoneView.m in Sources */ = {isa = PBXBuildFile; fileRef = D07BC6CA1F2A18B700ED97AA /* TGCameraMainPhoneView.m */; };
|
||||
D07BC6D11F2A18B700ED97AA /* TGCameraMainTabletView.h in Headers */ = {isa = PBXBuildFile; fileRef = D07BC6CB1F2A18B700ED97AA /* TGCameraMainTabletView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -1692,6 +1694,8 @@
|
||||
D04269101F586E430037ECE8 /* TGVideoCameraPipeline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TGVideoCameraPipeline.m; sourceTree = "<group>"; };
|
||||
D04269131F586EC80037ECE8 /* TGVideoMessageCaptureController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGVideoMessageCaptureController.h; sourceTree = "<group>"; };
|
||||
D04269141F586EC80037ECE8 /* TGVideoMessageCaptureController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TGVideoMessageCaptureController.m; sourceTree = "<group>"; };
|
||||
D07ABBA6202A1939003671DE /* TGWallpaperController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TGWallpaperController.m; sourceTree = "<group>"; };
|
||||
D07ABBA7202A1939003671DE /* TGWallpaperController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGWallpaperController.h; sourceTree = "<group>"; };
|
||||
D07BC6C91F2A18B700ED97AA /* TGCameraMainPhoneView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGCameraMainPhoneView.h; sourceTree = "<group>"; };
|
||||
D07BC6CA1F2A18B700ED97AA /* TGCameraMainPhoneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TGCameraMainPhoneView.m; sourceTree = "<group>"; };
|
||||
D07BC6CB1F2A18B700ED97AA /* TGCameraMainTabletView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGCameraMainTabletView.h; sourceTree = "<group>"; };
|
||||
@@ -3675,6 +3679,8 @@
|
||||
D07BCB2A1F2B65C400ED97AA /* Wallpapers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D07ABBA7202A1939003671DE /* TGWallpaperController.h */,
|
||||
D07ABBA6202A1939003671DE /* TGWallpaperController.m */,
|
||||
D07BCB2B1F2B65F100ED97AA /* TGBuiltinWallpaperInfo.h */,
|
||||
D07BCB2C1F2B65F100ED97AA /* TGBuiltinWallpaperInfo.m */,
|
||||
D07BCB2D1F2B65F100ED97AA /* TGColorWallpaperInfo.h */,
|
||||
@@ -4091,6 +4097,7 @@
|
||||
D07BC85C1F2A2DBD00ED97AA /* TGMenuSheetItemView.h in Headers */,
|
||||
D07BC8721F2A2F6500ED97AA /* TGInputTextTag.h in Headers */,
|
||||
D07BCB721F2B6A5600ED97AA /* TGEmbedVKPlayerView.h in Headers */,
|
||||
D07ABBA9202A193A003671DE /* TGWallpaperController.h in Headers */,
|
||||
D07BC81C1F2A2C0B00ED97AA /* PGPhotoLookupFilterPass.h in Headers */,
|
||||
D07BCACC1F2B4E7300ED97AA /* TGMediaAvatarMenuMixin.h in Headers */,
|
||||
D01778CB1F200BAC0044446D /* TGRTLScreenEdgePanGestureRecognizer.h in Headers */,
|
||||
@@ -4584,6 +4591,7 @@
|
||||
D07BC6F41F2A19A700ED97AA /* TGCameraModeControl.m in Sources */,
|
||||
D017782C1F1F961D0044446D /* TGBotReplyMarkupButton.m in Sources */,
|
||||
D07BCAB81F2B4DE200ED97AA /* TGAttachmentCarouselItemView.m in Sources */,
|
||||
D07ABBA8202A193A003671DE /* TGWallpaperController.m in Sources */,
|
||||
D026605B1F34A7F8000E2DC5 /* TGLocationMapModeControl.m in Sources */,
|
||||
D01777771F1F92570044446D /* RMPhoneFormat.m in Sources */,
|
||||
D07BCA221F2A9A5300ED97AA /* TGCheckButtonView.m in Sources */,
|
||||
|
||||
@@ -313,3 +313,6 @@ FOUNDATION_EXPORT const unsigned char LegacyComponentsVersionString[];
|
||||
#import <LegacyComponents/TGColorWallpaperInfo.h>
|
||||
#import <LegacyComponents/TGCustomImageWallpaperInfo.h>
|
||||
#import <LegacyComponents/TGClipboardMenu.h>
|
||||
#import <LegacyComponents/TGImagePickerController.h>
|
||||
#import <LegacyComponents/TGLegacyCameraController.h>
|
||||
#import <LegacyComponents/TGWallpaperController.h>
|
||||
|
||||
@@ -80,7 +80,11 @@
|
||||
CGPathRelease(path);
|
||||
CGContextStrokePath(context);
|
||||
|
||||
NSDictionary *attributes = @{ NSFontAttributeName: [TGFont roundedFontOfSize:14.0f], NSForegroundColorAttributeName: _color };
|
||||
UIFont *font = [TGFont roundedFontOfSize:14.0f];
|
||||
if (font == nil) {
|
||||
font = [UIFont systemFontOfSize:14.0];
|
||||
}
|
||||
NSDictionary *attributes = @{ NSFontAttributeName: font, NSForegroundColorAttributeName: _color };
|
||||
CGSize size = iosMajorVersion() >= 7 ? [_string sizeWithAttributes:attributes] : [_string sizeWithFont:attributes[NSFontAttributeName]];
|
||||
if (iosMajorVersion() >= 7)
|
||||
{
|
||||
@@ -89,7 +93,7 @@
|
||||
else
|
||||
{
|
||||
CGContextSetFillColorWithColor(context, _color.CGColor);
|
||||
[_string drawAtPoint:CGPointMake((allRect.size.width - size.width) / 2.0f, floor((allRect.size.height - size.height) / 2.0f)) forWidth:FLT_MAX withFont:[TGFont roundedFontOfSize:14.0f] lineBreakMode:NSLineBreakByWordWrapping];
|
||||
[_string drawAtPoint:CGPointMake((allRect.size.width - size.width) / 2.0f, floor((allRect.size.height - size.height) / 2.0f)) forWidth:FLT_MAX withFont:font lineBreakMode:NSLineBreakByWordWrapping];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -891,6 +891,9 @@
|
||||
{
|
||||
if (_intent == TGMediaAssetsControllerSendFileIntent)
|
||||
return nil;
|
||||
if (self.requestSearchController == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (iosMajorVersion() < 7)
|
||||
{
|
||||
|
||||
@@ -320,8 +320,11 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius
|
||||
|
||||
_outerCircleView = [[UIImageView alloc] initWithImage:[self outerCircleImage:self.pallete != nil ? self.pallete.buttonColor : TGAccentColor()]];
|
||||
_outerCircleView.alpha = 0.0f;
|
||||
_outerCircleView.tag = 0x01f2bca;
|
||||
[[_presentation view] addSubview:_outerCircleView];
|
||||
|
||||
[_outerCircleView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(outerCircleTapGesture:)]];
|
||||
|
||||
_innerIconView = [[UIImageView alloc] initWithImage:_icon];
|
||||
|
||||
_innerIconWrapperView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
|
||||
@@ -422,6 +425,16 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius
|
||||
}];
|
||||
}
|
||||
[self displayLink].paused = false;
|
||||
|
||||
if (_locked) {
|
||||
[self animateLock];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)outerCircleTapGesture:(UITapGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
[self _commitCompleted];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)animateOut {
|
||||
@@ -756,6 +769,10 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius
|
||||
return true;
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
return [super hitTest:point withEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -1300,7 +1300,7 @@ static CGFloat transformRotation(CGAffineTransform transform)
|
||||
|
||||
- (NSUInteger)currentItemIndex
|
||||
{
|
||||
return _model.items.count == 0 ? 0 : (NSUInteger)[self currentItemFuzzyIndex];
|
||||
return _model.items.count == 0 ? 0 : (NSUInteger)([self currentItemFuzzyIndex]);
|
||||
}
|
||||
|
||||
- (CGFloat)currentItemFuzzyIndex
|
||||
@@ -1308,6 +1308,10 @@ static CGFloat transformRotation(CGAffineTransform transform)
|
||||
if (_model.items.count == 0)
|
||||
return 0.0f;
|
||||
|
||||
if (_view.scrollView.bounds.size.width <= FLT_EPSILON) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return CGFloor((_view.scrollView.bounds.origin.x + _view.scrollView.bounds.size.width / 2.0f) / _view.scrollView.bounds.size.width);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,11 +130,13 @@ static const CGFloat swipeDistanceThreshold = 128.0f;
|
||||
_scrollViewContainer.frame = bounds;
|
||||
_overlayContainerView.frame = bounds;
|
||||
|
||||
CGRect scrollViewFrame = CGRectMake(-_itemPadding, _scrollViewVerticalOffset, frame.size.width + _itemPadding * 2.0f, frame.size.height);
|
||||
if (!CGRectEqualToRect(_scrollView.frame, scrollViewFrame))
|
||||
{
|
||||
NSInteger currentItemIndex = (NSInteger)(CGFloor((_scrollView.bounds.origin.x + _scrollView.bounds.size.width / 2.0f) / _scrollView.bounds.size.width));
|
||||
[_scrollView setFrameAndBoundsInTransaction:scrollViewFrame bounds:CGRectMake(currentItemIndex * scrollViewFrame.size.width, 0.0f, scrollViewFrame.size.width, scrollViewFrame.size.height)];
|
||||
if (_scrollView != nil) {
|
||||
CGRect scrollViewFrame = CGRectMake(-_itemPadding, _scrollViewVerticalOffset, frame.size.width + _itemPadding * 2.0f, frame.size.height);
|
||||
if (!CGRectEqualToRect(_scrollView.frame, scrollViewFrame))
|
||||
{
|
||||
NSInteger currentItemIndex = (NSInteger)(CGFloor((_scrollView.bounds.origin.x + _scrollView.bounds.size.width / 2.0f) / _scrollView.bounds.size.width));
|
||||
[_scrollView setFrameAndBoundsInTransaction:scrollViewFrame bounds:CGRectMake(currentItemIndex * scrollViewFrame.size.width, 0.0f, scrollViewFrame.size.width, scrollViewFrame.size.height)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -227,8 +227,10 @@
|
||||
[super setHidden:true];
|
||||
}
|
||||
|
||||
_managedIsHidden = hidden;
|
||||
[_manager setHidden:hidden window:self];
|
||||
if (_managedIsHidden != hidden) {
|
||||
_managedIsHidden = hidden;
|
||||
[_manager setHidden:hidden window:self];
|
||||
}
|
||||
} else {
|
||||
[super setHidden:hidden];
|
||||
|
||||
|
||||
@@ -192,6 +192,10 @@ typedef enum
|
||||
[_thumbnailsDisposable dispose];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:_didEnterBackgroundObserver];
|
||||
[_activityDisposable dispose];
|
||||
id<SDisposable> currentAudioSession = _currentAudioSession;
|
||||
[_queue dispatch:^{
|
||||
[currentAudioSession dispose];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (NSURL *)tempOutputPath
|
||||
|
||||
29
LegacyComponents/TGWallpaperController.h
Normal file
29
LegacyComponents/TGWallpaperController.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#import <LegacyComponents/TGViewController.h>
|
||||
#import <LegacyComponents/LegacyComponentsContext.h>
|
||||
#import <LegacyComponents/ASWatcher.h>
|
||||
|
||||
@class TGWallpaperInfo;
|
||||
@class TGWallpaperController;
|
||||
@class TGPresentation;
|
||||
|
||||
@protocol TGWallpaperControllerDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
- (void)wallpaperController:(TGWallpaperController *)wallpaperController didSelectWallpaperWithInfo:(TGWallpaperInfo *)wallpaperInfo;
|
||||
|
||||
@end
|
||||
|
||||
@interface TGWallpaperController : TGViewController <ASWatcher>
|
||||
|
||||
@property (nonatomic, strong) ASHandle *actionHandle;
|
||||
|
||||
@property (nonatomic, weak) id<TGWallpaperControllerDelegate> delegate;
|
||||
@property (nonatomic) bool enableWallpaperAdjustment;
|
||||
@property (nonatomic, strong) TGPresentation *presentation;
|
||||
|
||||
@property (nonatomic, copy) void (^customDismiss)();
|
||||
|
||||
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context wallpaperInfo:(TGWallpaperInfo *)wallpaperInfo thumbnailImage:(UIImage *)thumbnailImage;
|
||||
|
||||
@end
|
||||
376
LegacyComponents/TGWallpaperController.m
Normal file
376
LegacyComponents/TGWallpaperController.m
Normal file
@@ -0,0 +1,376 @@
|
||||
#import "TGWallpaperController.h"
|
||||
|
||||
#import <LegacyComponents/LegacyComponents.h>
|
||||
#import "LegacyComponentsInternal.h"
|
||||
|
||||
#import "TGModernButton.h"
|
||||
#import <LegacyComponents/TGRemoteImageView.h>
|
||||
|
||||
#import <LegacyComponents/TGWallpaperInfo.h>
|
||||
#import <LegacyComponents/TGCustomImageWallpaperInfo.h>
|
||||
|
||||
//#import "TGDefaultPresentationPallete.h"
|
||||
|
||||
#import "TGRemoteImageView.h"
|
||||
|
||||
@interface TGWallpaperController () <UIScrollViewDelegate>
|
||||
{
|
||||
TGWallpaperInfo *_wallpaperInfo;
|
||||
UIImage *_thumbnailImage;
|
||||
TGRemoteImageView *_imageView;
|
||||
|
||||
CGSize _adjustingImageSize;
|
||||
CGFloat _adjustingImageScale;
|
||||
UIScrollView *_scrollView;
|
||||
|
||||
TGModernButton *_setButton;
|
||||
|
||||
UIView *_panelView;
|
||||
|
||||
TGModernButton *_cancelButton;
|
||||
|
||||
UIView *_separatorView;
|
||||
UIView *_bottomView;
|
||||
|
||||
id<LegacyComponentsContext> _context;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TGWallpaperController
|
||||
|
||||
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context wallpaperInfo:(TGWallpaperInfo *)wallpaperInfo thumbnailImage:(UIImage *)thumbnailImage
|
||||
{
|
||||
self = [super initWithContext:context];
|
||||
if (self != nil)
|
||||
{
|
||||
_actionHandle = [[ASHandle alloc] initWithDelegate:self releaseOnMainThread:true];
|
||||
|
||||
_wallpaperInfo = wallpaperInfo;
|
||||
_thumbnailImage = thumbnailImage;
|
||||
|
||||
[self setTitleText:TGLocalized(@"Wallpaper.Wallpaper")];
|
||||
|
||||
self.automaticallyManageScrollViewInsets = false;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
if (self.navigationController == nil && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
|
||||
{
|
||||
[_context animateApplicationStatusBarAppearance:TGStatusBarAppearanceAnimationSlideUp delay:0.0 duration:0.5 completion:^
|
||||
{
|
||||
[_context setApplicationStatusBarAlpha:0.0f];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
if (self.navigationController == nil && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
|
||||
{
|
||||
[_context setApplicationStatusBarAlpha:1.0f];
|
||||
[_context animateApplicationStatusBarAppearance:TGStatusBarAppearanceAnimationSlideDown duration:iosMajorVersion() >= 7 ? 0.23 : 0.3 completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
[super loadView];
|
||||
|
||||
self.view.clipsToBounds = true;
|
||||
self.view.backgroundColor = [UIColor blackColor];
|
||||
|
||||
CGSize screenSize = self.view.bounds.size;
|
||||
|
||||
_imageView = [[TGRemoteImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, screenSize.width, screenSize.height)];
|
||||
|
||||
bool imageLoading = false;
|
||||
|
||||
UIImage *immediateImage = [_wallpaperInfo image];
|
||||
if (immediateImage != nil)
|
||||
[_imageView loadImage:immediateImage];
|
||||
else
|
||||
{
|
||||
_imageView.useCache = false;
|
||||
_imageView.contentHints = TGRemoteImageContentHintLoadFromDiskSynchronously;
|
||||
_imageView.fadeTransition = true;
|
||||
_imageView.fadeTransitionDuration = 0.3;
|
||||
|
||||
imageLoading = true;
|
||||
|
||||
ASHandle *actionHandle = _actionHandle;
|
||||
[_imageView setProgressHandler:^(TGRemoteImageView *imageView, float progress)
|
||||
{
|
||||
if (ABS(progress - 1.0f) < FLT_EPSILON && [imageView currentImage] != nil)
|
||||
{
|
||||
[actionHandle requestAction:@"imageLoaded" options:nil];
|
||||
}
|
||||
}];
|
||||
[_imageView loadImage:[_wallpaperInfo fullscreenUrl] filter:nil placeholder:_thumbnailImage];
|
||||
}
|
||||
|
||||
if (_enableWallpaperAdjustment && immediateImage != nil)
|
||||
{
|
||||
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, screenSize.width, screenSize.height)];
|
||||
[self.view addSubview:_scrollView];
|
||||
|
||||
_scrollView.showsHorizontalScrollIndicator = false;
|
||||
_scrollView.showsVerticalScrollIndicator = false;
|
||||
_scrollView.delegate = self;
|
||||
|
||||
_adjustingImageScale = immediateImage.scale;
|
||||
_adjustingImageSize = CGSizeMake(immediateImage.size.width / _adjustingImageScale, immediateImage.size.height / _adjustingImageScale);
|
||||
|
||||
_imageView.frame = CGRectMake(0, 0, _adjustingImageSize.width, _adjustingImageSize.height);
|
||||
_imageView.contentMode = UIViewContentModeScaleToFill;
|
||||
[_scrollView addSubview:_imageView];
|
||||
|
||||
[self _adjustScrollView];
|
||||
_scrollView.zoomScale = _scrollView.minimumZoomScale;
|
||||
|
||||
CGSize contentSize = _scrollView.contentSize;
|
||||
CGSize viewSize = _scrollView.frame.size;
|
||||
_scrollView.contentOffset = CGPointMake(MAX(0, CGFloor((contentSize.width - viewSize.width) / 2)), MAX(0, CGFloor((contentSize.height - viewSize.height) / 2)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self.view addSubview:_imageView];
|
||||
}
|
||||
|
||||
_panelView = [[UIView alloc] initWithFrame:CGRectMake(0, screenSize.height - 49, screenSize.width, 49)];
|
||||
|
||||
if (iosMajorVersion() >= 7 && [TGViewController isWidescreen])
|
||||
{
|
||||
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:_panelView.bounds];
|
||||
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
[_panelView addSubview:toolbar];
|
||||
}
|
||||
else
|
||||
{
|
||||
TGNavigationBarPallete *pallete = [[LegacyComponentsGlobals provider] navigationBarPallete];
|
||||
_panelView.backgroundColor = pallete.backgroundColor;
|
||||
_panelView.backgroundColor = [UIColor grayColor];
|
||||
}
|
||||
|
||||
[self.view addSubview:_panelView];
|
||||
|
||||
CGFloat separatorWidth = TGScreenPixel;
|
||||
|
||||
TGNavigationBarPallete *pallete = [[LegacyComponentsGlobals provider] navigationBarPallete];
|
||||
|
||||
_cancelButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0, 0, CGFloor(_panelView.frame.size.width / 2) - separatorWidth, _panelView.frame.size.height)];
|
||||
_cancelButton.backgroundColor = [UIColor clearColor];
|
||||
//_cancelButton.highlightBackgroundColor = self.presentation.pallete.selectionColor;
|
||||
[_cancelButton addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_cancelButton setTitle:TGLocalized(@"Common.Cancel") forState:UIControlStateNormal];
|
||||
_cancelButton.titleLabel.font = TGSystemFontOfSize(17);
|
||||
[_cancelButton setTitleColor:pallete.titleColor];
|
||||
[_cancelButton setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
|
||||
[_panelView addSubview:_cancelButton];
|
||||
|
||||
_setButton = [[TGModernButton alloc] initWithFrame:CGRectMake(_cancelButton.frame.origin.x + _cancelButton.frame.size.width + separatorWidth, 0, CGFloor(_panelView.frame.size.width / 2), _panelView.frame.size.height)];
|
||||
_setButton.backgroundColor = [UIColor clearColor];
|
||||
//_setButton.highlightBackgroundColor = self.presentation.pallete.selectionColor;
|
||||
_setButton.enabled = !imageLoading;
|
||||
[_setButton addTarget:self action:@selector(doneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_setButton setTitle:TGLocalized(@"Wallpaper.Set") forState:UIControlStateNormal];
|
||||
_setButton.titleLabel.font = TGSystemFontOfSize(17);
|
||||
[_setButton setTitleColor:pallete.titleColor];
|
||||
//[_setButton setTitleColor:[self.presentation.pallete.textColor colorWithAlphaComponent:0.4f] forState:UIControlStateDisabled];
|
||||
[_setButton setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
|
||||
[_panelView addSubview:_setButton];
|
||||
|
||||
_separatorView = [[UIView alloc] initWithFrame:CGRectMake(CGFloor(_panelView.frame.size.width / 2) - separatorWidth, 0, separatorWidth, 49.0f)];
|
||||
_separatorView.backgroundColor = pallete.separatorColor;
|
||||
[_panelView addSubview:_separatorView];
|
||||
|
||||
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 49.0f, _panelView.frame.size.width, separatorWidth)];
|
||||
_bottomView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||
_bottomView.backgroundColor = pallete.separatorColor;
|
||||
[_panelView addSubview:_bottomView];
|
||||
}
|
||||
|
||||
- (void)layoutControllerForSize:(CGSize)size duration:(NSTimeInterval)duration {
|
||||
[super layoutControllerForSize:size duration:duration];
|
||||
|
||||
CGSize screenSize = self.view.bounds.size;
|
||||
|
||||
_imageView.frame = CGRectMake(0.0f, 0.0f, screenSize.width, screenSize.height);
|
||||
|
||||
UIImage *immediateImage = [_wallpaperInfo image];
|
||||
if (_enableWallpaperAdjustment && immediateImage != nil)
|
||||
{
|
||||
_scrollView.frame = CGRectMake(0.0f, 0.0f, screenSize.width, screenSize.height);
|
||||
|
||||
_scrollView.showsHorizontalScrollIndicator = false;
|
||||
_scrollView.showsVerticalScrollIndicator = false;
|
||||
_scrollView.delegate = self;
|
||||
|
||||
_adjustingImageScale = immediateImage.scale;
|
||||
_adjustingImageSize = CGSizeMake(immediateImage.size.width / _adjustingImageScale, immediateImage.size.height / _adjustingImageScale);
|
||||
|
||||
_imageView.frame = CGRectMake(0, 0, _adjustingImageSize.width, _adjustingImageSize.height);
|
||||
_imageView.contentMode = UIViewContentModeScaleToFill;
|
||||
|
||||
[self _adjustScrollView];
|
||||
_scrollView.zoomScale = _scrollView.minimumZoomScale;
|
||||
|
||||
CGSize contentSize = _scrollView.contentSize;
|
||||
CGSize viewSize = _scrollView.frame.size;
|
||||
_scrollView.contentOffset = CGPointMake(MAX(0, CGFloor((contentSize.width - viewSize.width) / 2)), MAX(0, CGFloor((contentSize.height - viewSize.height) / 2)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
|
||||
_panelView.frame = CGRectMake(0, screenSize.height - 49.0f - self.controllerSafeAreaInset.bottom, screenSize.width, 49.0f + self.controllerSafeAreaInset.bottom);
|
||||
|
||||
CGFloat separatorWidth = TGScreenPixel;
|
||||
|
||||
_cancelButton.frame = CGRectMake(0, 0, CGFloor(_panelView.frame.size.width / 2) - separatorWidth, 49.0f);
|
||||
|
||||
_setButton.frame = CGRectMake(_cancelButton.frame.origin.x + _cancelButton.frame.size.width + separatorWidth, 0, CGFloor(_panelView.frame.size.width / 2), 49.0f);
|
||||
|
||||
_separatorView.frame = CGRectMake(CGFloor(_panelView.frame.size.width / 2) - separatorWidth, 0, separatorWidth, 49.0f);
|
||||
}
|
||||
|
||||
- (void)controllerInsetUpdated:(UIEdgeInsets)previousInset
|
||||
{
|
||||
[super controllerInsetUpdated:previousInset];
|
||||
|
||||
_panelView.frame = CGRectMake(0, self.view.bounds.size.height - 49.0f - self.controllerSafeAreaInset.bottom, self.view.bounds.size.width, 49.0f + self.controllerSafeAreaInset.bottom);
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate
|
||||
{
|
||||
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
return UIInterfaceOrientationMaskPortrait;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)scrollViewDidZoom:(UIScrollView *)__unused scrollView
|
||||
{
|
||||
[self _adjustScrollView];
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndZooming:(UIScrollView *)__unused scrollView withView:(UIView *)__unused view atScale:(CGFloat)__unused scale
|
||||
{
|
||||
[self _adjustScrollView];
|
||||
}
|
||||
|
||||
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)__unused scrollView
|
||||
{
|
||||
return _imageView;
|
||||
}
|
||||
|
||||
- (void)_adjustScrollView
|
||||
{
|
||||
CGSize imageSize = _adjustingImageSize;
|
||||
CGFloat imageScale = _adjustingImageScale;
|
||||
imageSize.width /= imageScale;
|
||||
imageSize.height /= imageScale;
|
||||
|
||||
CGFloat scaleWidth = _scrollView.frame.size.width / imageSize.width;
|
||||
CGFloat scaleHeight = _scrollView.frame.size.height / imageSize.height;
|
||||
CGFloat minScale = MAX(scaleWidth, scaleHeight);
|
||||
|
||||
if (_scrollView.minimumZoomScale != minScale)
|
||||
_scrollView.minimumZoomScale = minScale;
|
||||
if (_scrollView.maximumZoomScale != minScale * 3.0f)
|
||||
_scrollView.maximumZoomScale = minScale * 3.0f;
|
||||
|
||||
CGSize boundsSize = _scrollView.bounds.size;
|
||||
CGRect contentsFrame = _imageView.frame;
|
||||
|
||||
if (boundsSize.width > contentsFrame.size.width)
|
||||
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
|
||||
else
|
||||
contentsFrame.origin.x = 0;
|
||||
|
||||
if (boundsSize.height > contentsFrame.size.height)
|
||||
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
|
||||
else
|
||||
contentsFrame.origin.y = 0;
|
||||
|
||||
_imageView.frame = contentsFrame;
|
||||
}
|
||||
|
||||
#pragma mark
|
||||
|
||||
- (void)cancelButtonPressed
|
||||
{
|
||||
if (_customDismiss) {
|
||||
_customDismiss();
|
||||
} else {
|
||||
if (self.navigationController != nil)
|
||||
[self.navigationController popViewControllerAnimated:true];
|
||||
else
|
||||
[self.presentingViewController dismissViewControllerAnimated:true completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)doneButtonPressed
|
||||
{
|
||||
UIImage *currentImage = [_imageView currentImage];
|
||||
if (currentImage != nil)
|
||||
{
|
||||
TGWallpaperInfo *selectedWallpaperInfo = _wallpaperInfo;
|
||||
|
||||
if (_enableWallpaperAdjustment)
|
||||
{
|
||||
CGSize screenSize = self.view.bounds.size;
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
screenSize.width *= screenScale;
|
||||
screenSize.height *= screenScale;
|
||||
|
||||
CGFloat screenSide = MAX(screenSize.width, screenSize.height);
|
||||
|
||||
CGFloat scale = 1.0f / _scrollView.zoomScale;
|
||||
|
||||
CGRect visibleRect;
|
||||
visibleRect.origin.x = _scrollView.contentOffset.x * scale;
|
||||
visibleRect.origin.y = _scrollView.contentOffset.y * scale;
|
||||
visibleRect.size.width = _scrollView.bounds.size.width * scale;
|
||||
visibleRect.size.height = _scrollView.bounds.size.height * scale;
|
||||
|
||||
UIImage *croppedImage = TGFixOrientationAndCrop(currentImage, visibleRect, TGFitSize(visibleRect.size, CGSizeMake(screenSide, screenSide)));
|
||||
if (croppedImage != nil)
|
||||
selectedWallpaperInfo = [[TGCustomImageWallpaperInfo alloc] initWithImage:croppedImage];
|
||||
}
|
||||
|
||||
id<TGWallpaperControllerDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(wallpaperController:didSelectWallpaperWithInfo:)])
|
||||
[delegate wallpaperController:self didSelectWallpaperWithInfo:selectedWallpaperInfo];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)actionStageActionRequested:(NSString *)action options:(id)__unused options
|
||||
{
|
||||
if ([action isEqualToString:@"imageLoaded"])
|
||||
{
|
||||
_setButton.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user