123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- //
- // KMVerificationMessageViewController.m
- // PDF Reader Pro Edition
- //
- // Created by 王帅 on 2018/5/9.
- //
- #import "KMVerificationMessageViewController.h"
- #import <PDF_Reader_Pro-Swift.h>
- #import "VerificationManager.h"
- #import "AIInfoManager.h"
- #import "KMVerificationWindowController.h"
- #import "KMUnlockAlertViewController.h"
- #define kbottomGap 0
- @interface KMVerificationMessageViewController ()<
- NSPopoverDelegate>
- @property (nonatomic, assign) IBOutlet NSTextField *label;
- @property (nonatomic, assign) IBOutlet NSButton *button;
- @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
- @property (assign) IBOutlet NSView *labelContentView;
- @property (assign) IBOutlet NSImageView *bgImg;
- @property (assign) IBOutlet NSView *aiContendView;
- @property (assign) IBOutlet NSImageView *aiIconImg;
- @property (assign) IBOutlet NSTextField *aiLabel;
- @property (weak) IBOutlet NSButton *userButton;
- @property (assign) IBOutlet NSView *signUpView;
- @property (assign) IBOutlet NSImageView *signUpImg;
- @property (assign) IBOutlet NSTextField *signUpLabel;
- @property (nonatomic, retain) NSTrackingArea *trackingArea;
- @property (nonatomic, retain) NSPopover *popover;
- @property (nonatomic, assign) BOOL isPopoverShow;
- @property (nonatomic, assign) BOOL checkValue;
- @property (nonatomic, assign) BOOL stopPopOverHide;
- @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
- @property (nonatomic, retain) NSMenu *userMenu;
- @end
- @implementation KMVerificationMessageViewController
- #pragma mark Init Methods
- - (instancetype)init {
- if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
- #if VERSION_DMG
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(deviceActivateStatusChangeNotification:)
- name:kDeviceActivateStatusChangeNotification
- object:nil];
- #else
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
-
- #endif
- }
- return self;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- if (self.trackingArea) {
- [self.button removeTrackingArea:self.trackingArea];
- }
-
- }
- #pragma mark Setter Methods
- - (void)loadView {
- [super loadView];
-
- // Do view setup here.
- self.button.wantsLayer = YES;
- self.button.layer.masksToBounds = YES;
- self.button.layer.cornerRadius = 4.0;
- self.button.font = [NSFont SFProTextSemiboldFont:11];
- self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
- [self.button setAlignment:NSTextAlignmentCenter];
-
- self.secondTrialBtn.wantsLayer = YES;
- self.secondTrialBtn.layer.masksToBounds = YES;
- self.secondTrialBtn.layer.cornerRadius = 4.0;
- self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
- self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
- [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
-
- NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
- #if VERSION_DMG
- tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Upgrade to Permanent License with one time purchase", nil), NSLocalizedString(@"Complete the purchase in your web browser to get a license", nil)];
- #else
- tTips = [NSString stringWithFormat:@"%@\n%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil), NSLocalizedString(@"Choose your favorite payment and enjoy flexible upgrades.", nil)];
- #endif
- self.button.toolTip = tTips;
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- [self.button setTitleColor:[NSColor whiteColor]];
- [self.button setAlignment:NSTextAlignmentCenter];
-
- self.secondTrialBtn.toolTip = tTips;
- self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
- [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
- [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
- self.secondTrialBtn.hidden = YES;
-
- self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
-
- self.bgImg.wantsLayer = YES;
- self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
- self.bgImg.layer.masksToBounds = YES;
- self.bgImg.layer.cornerRadius = 4.;
- self.bgImg.hidden = YES;
-
- self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
- self.aiLabel.textColor = [NSColor whiteColor];
-
- [self reloadData];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
- }
- - (void)reloadData {
- self.label.textColor = [NSColor blackColor];
- self.label.hidden = NO;
- BOOL isFree = NO;
- self.secondTrialBtn.hidden = YES;
- self.bgImg.hidden = YES;
-
- if (self.frameUpdateHandle) {
- self.frameUpdateHandle(self.view.frame);
- }
-
- CGFloat totalWidth = 8;
- self.button.hidden = YES;
- self.label.hidden = YES;
- self.secondTrialBtn.hidden = YES;
- self.labelContentView.hidden = YES;
- self.bgImg.hidden = YES;
- self.aiContendView.hidden = YES;
- self.userButton.hidden = YES;
- self.signUpView.hidden = YES;
- self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
- [self.signUpLabel sizeToFit];
- CGFloat signUpWidth = self.signUpLabel.frame.size.width;
- signUpWidth += 4;
- signUpWidth += 8;
- signUpWidth += 8;
- signUpWidth += 12;
- self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
- CGRect signUplabelRect = self.signUpLabel.frame;
- signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
- self.signUpLabel.frame = signUplabelRect;
- self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
- [self.button setTitleColor:[NSColor whiteColor]];
-
- self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free to receive 1 year of AI", @"MemberCenterLocalizable", nil);
- [self.aiLabel sizeToFit];
- CGFloat aiWidth = self.aiLabel.frame.size.width;
- aiWidth += 4;
- aiWidth += 16;
- aiWidth += 16;
- self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
- self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
- CGRect ailabelRect = self.aiLabel.frame;
- ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
- self.aiLabel.frame = ailabelRect;
- // totalWidth+=aiWidth;
- // totalWidth+=4;
- // self.aiContendView.hidden = NO;
- CGFloat userImageWidth = 24;
- if ([KMMemberInfo shared].isLogin) {
- self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
- } else {
- self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
- }
- CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
- NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
- if (fabs(buttonWidth-btnRect.size.width)>50) {
- buttonWidth = btnRect.size.width + 10;
- }
- if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
- if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
- self.aiContendView.hidden = NO;
- totalWidth+=aiWidth;
- totalWidth+=4;
- }
- }
- if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
- if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
-
- if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
- if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
- KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
- NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
-
- NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
- __weak typeof(self)weakSelf = self;
- weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
- weakSelf.bgImg.image = image;
- }];
- }
- }
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Renew now", nil)];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
- if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
- KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
- NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
-
- NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
- __weak typeof(self)weakSelf = self;
- weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
- weakSelf.bgImg.image = image;
- }];
- }
- }
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Renew now", nil)];
- }
- [self.button setTitleColor:[NSColor whiteColor]];
- self.bgImg.hidden = NO;
- self.button.hidden = NO;
- if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
- if ([IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.isTrialPeriod) {
- self.bgImg.hidden = YES;
- self.button.hidden = YES;
- }
- }
-
- KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
- // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
- //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
- if(type == KMUserScenarioTypeLite_type9 ||
- type == KMUserScenarioTypeLite_type10 ||
- type == KMUserScenarioTypeLite_type11 ||
- type == KMUserScenarioTypeLite_type12 ||
- type == KMUserScenarioTypeLite_type13 ||
- type == KMUserScenarioTypePro_type1 ||
- type == KMUserScenarioTypePro_type2 ||
- type == KMUserScenarioTypePro_type3 ||
- type == KMUserScenarioTypePro_type4 ||
- type == KMUserScenarioTypePro_type5) {
- if ([KMMemberInfo shared].isLogin == NO || ([KMMemberInfo shared].isMemberAllFunction == NO && [KMMemberInfo shared].isLogin == YES)) {
- self.button.hidden = YES;
- self.bgImg.hidden = YES;
- }
- }
- self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
- CGRect rect = self.button.frame;
- self.bgImg.frame = rect;
- totalWidth+=CGRectGetWidth(self.button.bounds);
- totalWidth+=4;
- }
- if ([KMMemberInfo shared].isLogin) {
- self.userButton.hidden = NO;
- self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
- totalWidth += userImageWidth;
- totalWidth += 8;
- } else {
- if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
- if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
- KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
- NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
-
- NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
- __weak typeof(self)weakSelf = self;
- weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
- weakSelf.bgImg.image = image;
- }];
- }
- }
-
- self.signUpView.hidden = NO;
- self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
- totalWidth+=CGRectGetWidth(self.signUpView.bounds);
- }
-
- if (self.view.superview) {
- self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
- } else {
- // if (self.button.hidden) {
- // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
- // } else {
- // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
- // }
- self.view.frame = CGRectMake(MAX(0, CGRectGetWidth(self.view.superview.frame)-totalWidth - 8), (CGRectGetHeight(self.view.superview.frame)-CGRectGetHeight(self.view.frame))/2., totalWidth, self.view.frame.size.height);
- }
- }
- #pragma mark - Button Actions
- - (IBAction)secondTrialAction:(NSButton *)sender {
- if ([VerificationManager manager].secondTrialEnabled) {
- KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
- [vc showWindow:nil];
- } else {
- [[KMProductCompareWC shared] setOrientation:NO];
- [[KMProductCompareWC shared] showWindow:nil];
- }
- }
- - (IBAction)buttonAction:(id)sender {
- if ([KMMemberInfo shared].isLogin) {
- [[KMProductCompareWC shared] setOrientation:YES];
- if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
- }
- [[KMProductCompareWC shared] showWindow:nil];
- } else {
- [KMLoginWindowsController.shared openWindow:^(BOOL success) {
- if (success) {
- [[KMProductCompareWC shared] setOrientation:YES];
- if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
- [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
- } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
- }
- [[KMProductCompareWC shared] showWindow:nil];
- }
- }];
- }
- }
- - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
- NSString *temp = nil;
- for (NSUInteger i = 0; i <string.length; i++) {
- temp = [string substringWithRange:NSMakeRange(i, 1)];
- if ([self isPureInt:temp]) {
- [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
- color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
- }
- }
- return attributedString;
- }
- - (BOOL)isPureInt:(NSString *)string {
- NSScanner *scan = [NSScanner scannerWithString:string];
- int value;
- return [scan scanInt:&value] && [scan isAtEnd];
- }
- - (IBAction)AIButtonAction:(NSButton *)sender {
- __block typeof(self) blockSelf = self;
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
- // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
- //
- // }];
- // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
- // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
- //#if VERSION_DMG
- // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
- // [embeddedWC showWindow:nil];
- // [[embeddedWC window] center];
- //#else
- //
- // [[AIPurchaseWindowController currentWC] showWindow:nil];
- //#endif
- // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
- // };
- // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
- // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
- // verifyVC.callback = ^{
- //
- // };
- // [verifyVC showWindow:nil];
- // };
- //
- // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
- // if (!blockSelf.guideWindowVC) {
- // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
- // blockSelf.guideWindowVC = guideWindowVC;
- // }
- // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
- // [blockSelf.guideWindowVC showWindow:nil];
- // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
- // [blockSelf.guideWindowVC.window orderFront:nil];
- // };
- //
- // NSPopover *popover = [[NSPopover alloc] init];
- // popover.contentViewController = controller;
- // popover.animates = YES;
- // popover.behavior = NSPopoverBehaviorTransient;
- // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
- [[KMFreeGetAIWC shared] showWindow:nil];
- }
- - (IBAction)userButtonAction:(NSButton *)sender {
- if ([KMMemberInfo shared].isLogin) {
- [self personalCenterAction:sender];
- } else {
- [KMLoginWindowsController.shared showWindow:nil];
- }
- }
- - (IBAction)personalCenterAction:(NSButton *)sender {
- // 用户头像点击事件
- self.userMenu = [[NSMenu alloc] init];
- KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
- NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
- item.target = self;
- item.representedObject = userInfo;
- item.view = userInfo.view;
- [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
- }
- - (IBAction)signUpAction:(NSButton *)sender {
- [KMLoginWindowsController.shared showWindow:nil];
- }
- #pragma mark - NSNotification Methods
- - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPResultReceived:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPPurchaseSuccess:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)IAPRestoreFinish:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- #pragma mark - Event
- - (void)mouseEntered:(NSEvent *)event {
- if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- ActivityStatusTrial == [VerificationManager manager].status) {
- [[self class] cancelPreviousPerformRequestsWithTarget:self];
- if (!self.popover.isShown) {
- [self buttonAction:self.button];
- }
- }
- }
- - (void)mouseExited:(NSEvent *)event {
- [super mouseExited:event];
-
- [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
- }
- - (void)popoverDidClose:(NSNotification *)notification {
- self.stopPopOverHide = NO;
- }
-
- - (void)popoverShowNoti:(NSNotification *)noti {
- if (self.popover) {
- [self.popover close];
- self.stopPopOverHide = NO;
- }
- }
- - (void)loginSuccessNotification:(NSNotification *)noti {
- _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
- [self reloadData];
- }
- - (void)logoutSuccessNotification:(NSNotification *)noti {
- _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
- [self reloadData];
- }
- - (void)expandPersonalCenterNotification:(NSNotification *)noti {
- if (self.userMenu != nil) {
- [self personalCenterAction:_userButton];
- }
- }
- - (void)closeMenu:(NSNotification *)noti {
- if (self.userMenu != nil) {
- [self.userMenu cancelTracking];
- self.userMenu = nil;
- }
- }
- - (void)popOverCloseAction {
- if (self.stopPopOverHide == NO) {
- if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
- ActivityStatusTrial == [VerificationManager manager].status) {
- if (self.popover.isShown) {
- [self.popover close];
- self.stopPopOverHide = NO;
- }
- }
- }
- }
- @end
|