12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352 |
- //
- // 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"
- #import "KMMessageModel.h"
- #import "KMMessageItemView.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 (weak) IBOutlet NSButton *officeButton;
- @property (assign) IBOutlet NSImageView *officeImg;
- @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;
- // 远程按钮 最大宽度限制 100
- @property (nonatomic, assign) CGFloat remoteButtonMaxWidth;
- @property (nonatomic, strong) NSMutableArray *datas;
- @property (nonatomic, strong) KMMessageDiscountItemView *userGiftView;
- @property (nonatomic, strong) KMMessageDiscountItemView *discountItemView;
- @end
- @implementation KMVerificationMessageViewController
- #pragma mark Init Methods
- - (instancetype)init {
- if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
- self.remoteButtonMaxWidth = 200;
-
- #if VERSION_DMG
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(deviceActivateStatusChangeNotification:)
- name:kDeviceActivateStatusChangeNotification
- object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(deviceActivateStatusChangeNotification:)
- name:KMIAPSubscriptionLoadedNotification
- object:nil];
- #else
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPProductLoaded:) name:KMIAPProductLoadedNotification object:nil];
- [[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
-
- _datas = [NSMutableArray arrayWithCapacity:4];
- }
- 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.userButton.font = [NSFont SFProTextSemiboldFont:11];
-
- 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 = @"";
- #else
- tTips = [NSString stringWithFormat:@"%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", 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 = NO;
-
- 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.signUpView.wantsLayer = true;
- self.signUpView.layer.cornerRadius = 4;
-
- self.userGiftView = [[KMMessageDiscountItemView alloc] init];
- self.userGiftView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
- [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
- self.userGiftView.radius = 4;
- self.userGiftView.titleLabel.font = [NSFont SFProTextBoldFont:11];
- self.userGiftView.titleLabel.textColor = NSColor.whiteColor;
- self.userGiftView.hidden = true;
- self.userGiftView.leftImageView.image = [NSImage imageNamed:@"NewUserGift"];
- self.userGiftView.kTarget = self;
- self.userGiftView.kAction = @selector(userGiftAction:);
-
- _discountItemView = [[KMMessageDiscountItemView alloc] init];
- _discountItemView.gradientColors = @[[NSColor colorWithRed:248/255.0 green:150/255.0 blue:90/255.0 alpha:1.0],
- [NSColor colorWithRed:253/255.0 green:113/255.0 blue:113/255.0 alpha:1.0]];
- _discountItemView.radius = 4;
- _discountItemView.titleLabel.font = [NSFont SFProTextBoldFont:11];
- _discountItemView.titleLabel.textColor = NSColor.whiteColor;
- _discountItemView.hidden = true;
- _discountItemView.leftImageView.image = [NSImage imageNamed:@"KMImageNameCancelSubscribeDiscount"];
- _discountItemView.kTarget = self;
- _discountItemView.kAction = @selector(discountAction:);
-
- [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];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberInfoChangeNotification:) name:KMMemberInfoChangeNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trailCancelStateDidChange:) name:@"KMTrailCancelStateDidChangeNotificationName" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(advertisementDidLoaded:) name:@"KMAdvertisementDidLoadedNotification" object:nil];
- }
- // MARK: - Private Methods
- - (NSString *)_getAppStoreFreeVersionBuyNowTitle {
- return [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Purchase without Login", nil)];
- }
- - (NSString *)_getDiscountTitle {
- #if VERSION_DMG
- if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"$60"];
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥360"];
- }
- #else
-
- BOOL showCNY = false;
- #if VERSION_FREE
- NSString *localeId = [IAPProductsManager defaultManager].allAccessPackPermanent_lite.product.priceLocale.localeIdentifier;
- if ([localeId containsString:@"zh_CN"] || [localeId containsString:@"zh_TW"] || [localeId containsString:@"zh-TW"]) {
- showCNY = true;
- }
- #endif
-
- if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
- if (showCNY == false) {
- // if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"USD 60"];
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥360"];
- }
- } else {
- if ([[KMMemberInfo shared] isFreeAccount]) {
- if (showCNY == false) {
- // if ([NSLocalizedString(@"USD", "") isEqualToString:@"USD"]) {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"USD 30"];
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"%@ Coupons", @""), @"¥180"];
- }
- } else {
- return @"";
- }
- }
- #endif
- }
- - (CGFloat)_calTextWidth:(NSString *)textString font:(NSFont *)font {
- NSMutableDictionary *attri = [NSMutableDictionary dictionary];
- if (font != nil) {
- [attri setObject:font forKey:NSFontAttributeName];
- }
- NSRect rect = [textString boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attri];
- return rect.size.width;
- }
- // 是否定向跳转比较表
- - (BOOL)_isNowGotoPurcahseTable {
- #if VERSION_FREE
- #if VERSION_DMG
- return false;
- #else
- // AppStore 免费版 有特定需求
- // 无本机权益 true,否则 false
- return IAPProductsManager.defaultManager.isAvailableAllFunction == false;
- #endif
- #else
- return false;
- #endif
- }
- - (CGFloat)_dealDiscountViewWithMessageType:(KMMessageType)messageType {
- KMMessageModel *newUserGiftModel = nil;
- KMMessageModel *discountModel = nil;
- for (KMMessageModel *model in self.datas) {
- if (model.type == KMMessageTypeNewUserGift) {
- newUserGiftModel = model;
- }
- if (model.type == KMMessageTypeDiscount) {
- discountModel = model;
- }
- }
-
- CGFloat discountWidth = 0;
- if (newUserGiftModel != nil && newUserGiftModel.show) {
- if (self.userGiftView.superview == nil) {
- [self.view addSubview:self.userGiftView positioned:NSWindowAbove relativeTo:self.button];
- }
-
- [self.userGiftView mas_remakeConstraints:^(MASConstraintMaker *make) {
- if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
- make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);;
- } else {
- make.trailing.equalTo(self.button);
- }
- make.top.mas_equalTo(0);
- make.width.mas_equalTo(newUserGiftModel.viewWidth);
- make.height.equalTo(self.view);
- }];
-
- discountWidth = newUserGiftModel.viewWidth + 4;
- self.userGiftView.hidden = false;
- self.userGiftView.titleLabel.stringValue = newUserGiftModel.titleText;
- } else if (discountModel != nil && discountModel.show) {
- if (self.discountItemView.superview == nil) {
- [self.view addSubview:self.discountItemView positioned:NSWindowAbove relativeTo:self.button];
- }
- [self.discountItemView mas_remakeConstraints:^(MASConstraintMaker *make) {
- if (messageType == KMMessageTypeFreeTrail || messageType == KMMessageTypePurchaseWithoutLogin) {
- make.trailing.equalTo(self.button.mas_leading).mas_offset(-4);
- } else {
- make.trailing.equalTo(self.button);
- }
- make.top.mas_equalTo(0);
- make.width.mas_equalTo(discountModel.viewWidth);
- make.height.equalTo(self.view);
- }];
-
- discountWidth = discountModel.viewWidth + 4;
- self.discountItemView.hidden = false;
- _discountItemView.titleLabel.stringValue = discountModel.titleText;
- }
- return discountWidth;
- }
- - (KMMessageModel *)_createDiscountModelWithType:(KMMessageType)type {
- NSString *titleText = @"";
- if (type == KMMessageTypeNewUserGift) {
- titleText = NSLocalizedString(@"Welcome Gifts", @"");
- } else if (type == KMMessageTypeDiscount) {
- titleText = [self _getDiscountTitle];
- }
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- CGFloat width = [self _calTextWidth:calTitleText font:nil];
-
- KMMessageModel *model = [[KMMessageModel alloc] init];
- model.type = type;
- model.show = true;
- model.titleText = titleText;
- model.viewWidth = width + 10;
-
- return model;
- }
- - (void)_trackButtonEvent {
- if (self.button.tag == KMMessageTypePurchaseWithoutLogin) {
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_PurchasewithoutLogin"}];
- #endif
- #endif
- } else if (self.button.tag == KMMessageTypeFreeTrail) {
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_FreeTrial"}];
- }
- }
- - (CGFloat)dealSignUpView {
- self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
- self.signUpLabel.font = [NSFont SFProTextSemiboldFont:11];
- [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;
-
- return signUpWidth;
- }
- - (void)reloadData {
- [self.datas removeAllObjects];
- // [self.userGiftView removeFromSuperview];
- self.userGiftView.hidden = true;
- self.discountItemView.hidden = true;
-
- self.label.textColor = [NSColor blackColor];
- self.label.hidden = NO;
- self.secondTrialBtn.hidden = YES;
-
- CGFloat totalWidth = 8;
- self.button.hidden = NO;
- self.officeButton.hidden = NO;
- self.bgImg.hidden = NO;
- self.officeImg.hidden = NO;
- self.label.hidden = YES;
- self.secondTrialBtn.hidden = YES;
- self.labelContentView.hidden = YES;
- self.aiContendView.hidden = YES;
- self.userButton.hidden = YES;
- self.signUpView.hidden = YES;
- CGFloat signUpWidth = [self dealSignUpView];
- self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
- [self.button setTitleColor:[NSColor whiteColor]];
- self.button.tag = KMMessageTypeNone;
- self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
- self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office", nil)];
- [self.officeButton setTitleColor:[NSColor whiteColor]];
- self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"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;
- // buttonWidth += 10;
- // }
-
- CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
- NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
- if (fabs(officeWidth-officeRect.size.width)>50) {
- officeWidth = officeRect.size.width + 10;
- }
-
- #if VERSION_DMG
- self.button.hidden = YES;
- self.officeButton.hidden = YES;
- self.bgImg.hidden = YES;
- self.officeImg.hidden = YES;
- if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
- self.aiContendView.hidden = NO;
- totalWidth+=aiWidth;
- totalWidth+=4;
- }
- KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
- KMMessageType messageType = KMMessageTypeNone;
- if (type == KMUserScenarioTypeDmg_type1 ||
- type == KMUserScenarioTypeDmg_type2 ||
- type == KMUserScenarioTypeDmg_type3 ||
- type == KMUserScenarioTypeDmg_type5 ||
- type == KMUserScenarioTypeDmg_type6 ||
- type == KMUserScenarioTypeDmg_type7 ||
- type == KMUserScenarioTypeDmg_type28 ||
- type == KMUserScenarioTypeDmg_type29 ||
- type == KMUserScenarioTypeDmg_type30 ||
- type == KMUserScenarioTypeDmg_type43 ||
- type == KMUserScenarioTypeDmg_type44 ||
- type == KMUserScenarioTypeDmg_type45) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- } else if (type == KMUserScenarioTypeDmg_type4 ) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
- messageType = KMMessageTypeFreeTrail;
- self.button.tag = KMMessageTypeFreeTrail;
- } else if (type == KMUserScenarioTypeDmg_type11 ||
- type == KMUserScenarioTypeDmg_type19 ||
- type == KMUserScenarioTypeDmg_type22 ||
- type == KMUserScenarioTypeDmg_type34 ||
- type == KMUserScenarioTypeDmg_type37 ) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeBuyNow;
- } else if (type == KMUserScenarioTypeDmg_type18 ||
- type == KMUserScenarioTypeDmg_type33 ||
- type == KMUserScenarioTypeDmg_type48) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeRenew;
- }
-
- if (type == KMUserScenarioTypeDmg_type2 ||
- type == KMUserScenarioTypeDmg_type19 ||
- type == KMUserScenarioTypeDmg_type20 ||
- type == KMUserScenarioTypeDmg_type21 ||
- type == KMUserScenarioTypeDmg_type22 ||
- type == KMUserScenarioTypeDmg_type30 ||
- type == KMUserScenarioTypeDmg_type31 ||
- type == KMUserScenarioTypeDmg_type32 ||
- type == KMUserScenarioTypeDmg_type33) {
- [self.officeButton setTitleColor:[NSColor whiteColor]];
- self.officeButton.hidden = NO;
- self.officeImg.hidden = NO;
- self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
- CGRect officeRect = self.officeButton.frame;
- self.officeImg.frame = officeRect;
- totalWidth+=CGRectGetWidth(self.officeButton.bounds);
- totalWidth+=4;
- }
- if (type == KMUserScenarioTypeDmg_type1 ||
- type == KMUserScenarioTypeDmg_type2 ||
- type == KMUserScenarioTypeDmg_type3 ||
- type == KMUserScenarioTypeDmg_type4 ||
- type == KMUserScenarioTypeDmg_type5 ||
- type == KMUserScenarioTypeDmg_type6 ||
- type == KMUserScenarioTypeDmg_type7 ||
- type == KMUserScenarioTypeDmg_type11 ||
- type == KMUserScenarioTypeDmg_type18 ||
- type == KMUserScenarioTypeDmg_type19 ||
- type == KMUserScenarioTypeDmg_type22 ||
- type == KMUserScenarioTypeDmg_type28 ||
- type == KMUserScenarioTypeDmg_type29 ||
- type == KMUserScenarioTypeDmg_type30 ||
- type == KMUserScenarioTypeDmg_type33 ||
- type == KMUserScenarioTypeDmg_type34 ||
- type == KMUserScenarioTypeDmg_type37 ||
- type == KMUserScenarioTypeDmg_type43 ||
- type == KMUserScenarioTypeDmg_type44 ||
- type == KMUserScenarioTypeDmg_type45 ||
- type == KMUserScenarioTypeDmg_type48 ||
-
- type == KMUserScenarioTypeDmg_type13) {
- [self.button setTitleColor:[NSColor whiteColor]];
-
- KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
- if (advertiseItem != nil && advertiseItem.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;
- NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
- if (image != nil) {
- weakSelf.bgImg.image = image;
- }
- }];
- } else {
- KMMemberInfo *member = [KMMemberInfo shared];
- KMNewUserGiftManager *man = [KMNewUserGiftManager default];
- if ([man needShow] && [member isLogin] == false && member.isMemberAllFunction == false) { // 未登陆的新用户
- NSString *titleText = NSLocalizedString(@"Welcome Gifts", @"");
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
- } else {
- if ([man needShow] && [member isFreeAccount]) {
- NSString *titleText = [self _getDiscountTitle];
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
-
- } else if (([member isMemberAllFunction] == false || type == KMUserScenarioTypeDmg_type13) && [[KMCheckInManager default] trailCancel]) {
- NSString *titleText = [self _getDiscountTitle];
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- }
- }
-
- CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
- totalWidth += discountWidth;
- }
-
- if (type != KMUserScenarioTypeDmg_type13 || self.datas.count > 0) {
- buttonWidth = CGRectGetWidth(self.button.frame);
- NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
- buttonWidth = btnRect.size.width + 10;
-
- self.bgImg.hidden = NO;
- self.button.hidden = NO;
- 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;
- }
- }
- #else
- if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
- #if VERSION_FREE
- if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
- self.aiContendView.hidden = NO;
- totalWidth+=aiWidth;
- totalWidth+=4;
- }
- #else
- if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
- self.aiContendView.hidden = NO;
- totalWidth+=aiWidth;
- totalWidth+=4;
- }
- #endif
- }
- KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
- BOOL buttonHiddenFlag = false;
- KMMessageType messageType = KMMessageTypeNone;
- if (type == KMUserScenarioTypeLite_type1 ||
- type == KMUserScenarioTypeLite_type3 ||
- type == KMUserScenarioTypeLite_type5 ||
- type == KMUserScenarioTypeLite_type7 ||
- type == KMUserScenarioTypeLite_type9 ||
- type == KMUserScenarioTypeLite_type11 ||
- type == KMUserScenarioTypePro_type1 ||
- type == KMUserScenarioTypePro_type3 ||
- type == KMUserScenarioTypePro_type4 || type == KMUserScenarioTypeLite_type8) {
- if (type == KMUserScenarioTypeLite_type1) { //免费用户
- #if !VERSION_DMG
- if(KMMemberInfo.shared.isLogin == NO) {
- #if VERSION_FREE
- if (IAPProductsManager.defaultManager.isAvailableAllFunction) {
- if (IAPProductsManager.defaultManager.isAvailableAdvancedPDFToOffice) {
- BOOL advanceFreeTrailing = [IAPReceiptTool isFreeTrailingWithModel:[IAPProductsManager defaultManager].receiptModel withProductId:[IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.product.productIdentifier];
- if (advanceFreeTrailing && [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- } else {
- self.button.title = @"";
- buttonHiddenFlag = true;
- }
- } else {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- }
- } else {
- self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
-
- if ([[KMNewUserGiftManager default] needShow]) {
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeNewUserGift]];
- } else if ([[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- }
-
- messageType = KMMessageTypePurchaseWithoutLogin;
- self.button.tag = KMMessageTypePurchaseWithoutLogin;
- }
- #else
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- #endif
- } else {
- if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeBuyNow;
- } else {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
- messageType = KMMessageTypeFreeTrail;
- self.button.tag = KMMessageTypeFreeTrail;
- }
-
- KMMemberInfo *member = [KMMemberInfo shared];
- KMNewUserGiftManager *man = [KMNewUserGiftManager default];
- if ([man needShow] && [member isFreeAccount]) {
- NSString *titleText = [self _getDiscountTitle];
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- } else if (man.progressState != KMProgressStateNone && member.isMemberAllFunction == false && [[KMCheckInManager default] trailCancel]) {
- NSString *titleText = [self _getDiscountTitle];
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- }
- }
- #else
- #endif
- } else if (type == KMUserScenarioTypeLite_type3 ) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeBuyNow;
- } else if (type == KMUserScenarioTypeLite_type5) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- } else if (type == KMUserScenarioTypeLite_type7) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeRenew;
- } else if (type == KMUserScenarioTypeLite_type8) {
- KMMemberInfo *member = [KMMemberInfo shared];
- KMNewUserGiftManager *man = [KMNewUserGiftManager default];
- if (man.progressState != KMProgressStateNone && [[KMCheckInManager default] trailCancel]) {
- NSString *titleText = [self _getDiscountTitle];
- NSString *calTitleText = [NSString stringWithFormat:@" %@",titleText];
- if (messageType != KMMessageTypeFreeTrail) {
- self.button.stringValue = calTitleText;
- }
-
- [self.datas addObject:[self _createDiscountModelWithType:KMMessageTypeDiscount]];
- }
- if (self.datas.count > 1) {
-
- } else {
- self.button.title = @"";
- buttonHiddenFlag = true;
- }
- } else if (type == KMUserScenarioTypeLite_type9) {
- if([KMMemberInfo shared].vip_status == 2) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeRenew;
- } else if ([KMMemberInfo shared].vip_status == 4) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeBuyNow;
- } else {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- }
- } else if (type == KMUserScenarioTypeLite_type11) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- } else if (type == KMUserScenarioTypePro_type3) {
- if([KMMemberInfo shared].vip_status == 2) {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
- messageType = KMMessageTypeRenew;
- } else {
- self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
- messageType = KMMessageTypeUpgrade;
- }
- }
- #if !VERSION_FREE
- BOOL isNoSupportMemberUpgrade = YES;
- if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
- isNoSupportMemberUpgrade = NO;
- }
-
- if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
- [self.officeButton setTitleColor:[NSColor whiteColor]];
- self.officeButton.hidden = NO;
- self.officeImg.hidden = NO;
- self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
- CGRect officeRect = self.officeButton.frame;
- self.officeImg.frame = officeRect;
- totalWidth+=CGRectGetWidth(self.officeButton.bounds);
- totalWidth+=4;
- } else {
- self.officeButton.hidden = YES;
- self.officeImg.hidden = YES;
- }
- #else
- self.officeButton.hidden = YES;
- self.officeImg.hidden = YES;
- #endif
-
- KMAdvertisementItem *advertiseItem = KMAdvertisementManager.manager.info.topRightInfoContent;
- if (advertiseItem != nil && advertiseItem.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;
- NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
- if (image != nil) {
- weakSelf.bgImg.image = image;
- }
- }];
- } else {
- CGFloat discountWidth = [self _dealDiscountViewWithMessageType:messageType];
- totalWidth += discountWidth;
- }
-
- [self.button setTitleColor:[NSColor whiteColor]];
- self.bgImg.hidden = NO;
- self.button.hidden = NO;
-
- BOOL isOldSubscribed = NO;
- #if VERSION_FREE
- #if !VERSION_DMG
- isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
- #endif
- #endif
- // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
- //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
- if(type == KMUserScenarioTypeLite_type9 ||
- type == KMUserScenarioTypeLite_type10 ||
- type == KMUserScenarioTypeLite_type11) {
- if([KMMemberInfo shared].isLogin == NO) { //未登录
- self.button.hidden = YES;
- self.bgImg.hidden = YES;
- } else {
- if(isOldSubscribed) { //老版本付费功能是订阅包
- self.button.hidden = YES;
- self.bgImg.hidden = YES;
- } else {
- if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
- self.button.hidden = YES;
- self.bgImg.hidden = YES;
- }
- }
- }
- }
-
- #if VERSION_FREE
- #if !VERSION_DMG
- if (buttonHiddenFlag) {
- self.bgImg.hidden = YES;
- self.button.hidden = YES;
- }
- #endif
- #endif
-
- buttonWidth = CGRectGetWidth(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;
- // buttonWidth += 10;
- // }
- if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
- if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
- buttonWidth += 10;
- buttonWidth = MIN(buttonWidth, self.remoteButtonMaxWidth);
- }
- }
- 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;
- } else if (type == KMUserScenarioTypeLite_type12 ||
- type == KMUserScenarioTypeLite_type13 ||
- type == KMUserScenarioTypeLite_type2 ||
- type == KMUserScenarioTypeLite_type4 ||
- type == KMUserScenarioTypeLite_type6 ||
- type == KMUserScenarioTypeLite_type8 ||
- type == KMUserScenarioTypePro_type2 ||
- type == KMUserScenarioTypePro_type5) {
- self.button.hidden = YES;
- self.bgImg.hidden = YES;
-
- #if !VERSION_FREE
- BOOL isNoSupportMemberUpgrade = YES;
- if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
- isNoSupportMemberUpgrade = NO;
- }
-
- if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
- [self.officeButton setTitleColor:[NSColor whiteColor]];
- self.officeButton.hidden = NO;
- self.officeImg.hidden = NO;
- self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
- CGRect officeRect = self.officeButton.frame;
- self.officeImg.frame = officeRect;
- totalWidth+=CGRectGetWidth(self.officeButton.bounds);
- totalWidth+=4;
- } else {
- self.officeButton.hidden = YES;
- self.officeImg.hidden = YES;
- }
- #else
- self.officeButton.hidden = YES;
- self.officeImg.hidden = YES;
- #endif
- }
- #endif
-
- if ([KMMemberInfo shared].isLogin) {
- self.userButton.hidden = NO;
- self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
- totalWidth += userImageWidth;
- totalWidth += 8;
- } else {
- self.signUpView.hidden = NO;
- self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
- totalWidth+=CGRectGetWidth(self.signUpView.bounds);
- }
-
- 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);
-
- if (self.frameUpdateHandle) {
- self.frameUpdateHandle(self.view.frame);
- }
- }
- #pragma mark - Button Actions
- - (IBAction)secondTrialAction:(NSButton *)sender {
- if ([VerificationManager manager].secondTrialEnabled) {
- KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
- [vc showWindow:nil];
- } else {
- [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
- }
- }
- - (IBAction)buttonAction:(id)sender {
- if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
- if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Sale"}];
- #endif
- #endif
- if ([KMMemberInfo shared].isLogin) {
- if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
- [[KMProductCompareWC shared] setOrientation:YES];
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
- #else
- // AppStore 免费版本
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- #endif
- #else
- // AppStore 付费版
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
- #endif
- [[KMProductCompareWC shared] showWindow:nil];
- } else {
- [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
- }
- } else {
- if ([self _isNowGotoPurcahseTable]) {
- KMProductCompareWC *winC = [KMProductCompareWC shared];
- // 定向跳转
- winC.orientation = true;
- // App Store 免费版 基础比较表
- winC.orientationType = KMCompareTableTypeLite_Base;
- [winC showWindow:nil];
- } else {
- [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
- if (success) {
- if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
- [[KMProductCompareWC shared] setOrientation:YES];
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
- #else
- // AppStore 免费版本
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- #endif
- #else
- // AppStore 付费版
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
- #endif
- [[KMProductCompareWC shared] showWindow:nil];
- } else {
- [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
- }
- }
- }];
- }
- }
- } else {
- [self _trackButtonEvent];
-
- KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
- if (type == KMUserScenarioTypeDmg_type4) {
- if ([KMMemberInfo shared].isLogin) {
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- // [[KMProductCompareWC shared] showWindow:nil];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- } else {
- [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
- if (success) {
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- // [[KMProductCompareWC shared] showWindow:nil];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- }
- }];
- }
- } else {
- if ([self _isNowGotoPurcahseTable] &&
- ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
- [self _doNowGotoPurcahseTable];
- } else {
- if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- } else {
- [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
- }
- }
- }
- }
- } else {
- [self _trackButtonEvent];
-
- KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
- if (type == KMUserScenarioTypeDmg_type4) {
- if ([KMMemberInfo shared].isLogin) {
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- // [[KMProductCompareWC shared] showWindow:nil];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- } else {
- [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
- if (success) {
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- // [[KMProductCompareWC shared] showWindow:nil];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- }
- }];
- }
- } else {
- if ([self _isNowGotoPurcahseTable] && ![KMMemberInfo shared].isLogin) { //本机(Apple ID)无权益,且未未登录时,直接跳购买
- [self _doNowGotoPurcahseTable];
- } else {
- if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
- [[KMProductCompareWC shared] setOrientation:YES];
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- } else {
- [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
- }
- }
- }
- }
- }
- - (void)_doNowGotoPurcahseTable {
- KMProductCompareWC *winC = [KMProductCompareWC shared];
- // 定向跳转
- winC.orientation = true;
- // App Store 免费版 基础比较表
- winC.orientationType = KMCompareTableTypeLite_Base;
- if ([[KMMemberInfo shared] isLogin] && self.button.tag == KMMessageTypeFreeTrail) { // 免费试用
- [winC openWindowWithDiscountType:KMDiscountTypeFreeTrail];
- } else if (self.userGiftView.isHidden == false) { // 新手礼
- KMMessageModel *model = nil;
- for (KMMessageModel *m in self.datas) {
- if (m.type == KMMessageTypeNewUserGift) {
- model = m;
- break;
- }
- }
- if (model != nil) { // 检查数据
- if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
- [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
- } else {
- [winC showWindow:nil];
- }
- } else {
- [winC showWindow:nil];
- }
- } else if (self.discountItemView.isHidden == false) { // 优惠卷 (新手礼 & 试用退订)
- KMMessageModel *model = nil;
- for (KMMessageModel *m in self.datas) {
- if (m.type == KMMessageTypeDiscount) {
- model = m;
- }
- }
- if (model != nil) { // 检查数据
- if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) { // 检查条件
- [winC openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
- } else if ([[KMNewUserGiftManager default] needShow]) { // 检查条件
- [winC openWindowWithDiscountType:KMDiscountTypeNewUserGift];
- } else {
- [winC showWindow:nil];
- }
- } else {
- [winC showWindow:nil];
- }
- } else {
- [winC showWindow:nil];
- }
- }
- - (IBAction)officeButtonAction:(id)sender {
- #if VERSION_FREE
- #if VERSION_DMG
- DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
- [embeddedWC showWindow:nil];
- [embeddedWC.window center];
- #endif
- #else
- if ([KMMemberInfo shared].isLogin) {
- [[KMMemberInfo shared] productCompareShow];
- } else {
- [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
- if (success) {
- [[KMMemberInfo shared] productCompareShow];
- }
- }];
- }
- #endif
- }
- - (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 {
- if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
- [[KMMemberPromptWC shared] showWindow:sender];
- [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
- } else {
- #if VERSION_FREE
- #if VERSION_DMG
- KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
- [winC showWindow:nil];
- [winC.window center];
- #else
- [[KMFreeGetAIWC shared] showWindow:nil];
- #endif
- #else
- [[KMFreeGetAIWC shared] showWindow:nil];
- #endif
- }
- }
- - (IBAction)userButtonAction:(NSButton *)sender {
- if ([KMMemberInfo shared].isLogin) {
- [self personalCenterAction:sender];
- } else {
- [KMLoginWindowsController.shared showWindow:nil];
- }
- }
- - (BOOL)isConnectionAvailable {
- BOOL isExistenceNetwork = YES;
- Reachability *reach = [Reachability reachabilityWithHostname:@"www.apple.com"];
- switch ([reach currentReachabilityStatus]) {
- case NotReachable:
- isExistenceNetwork = NO;
- //NSLog(@"notReachable");
- break;
- case ReachableViaWiFi:
- isExistenceNetwork = YES;
- //NSLog(@"WIFI");
- break;
- case ReachableViaWWAN:
- isExistenceNetwork = YES;
- //NSLog(@"3G");
- break;
- }
- if (NotReachable == [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
- return NO;
- }
- return YES;
- }
- - (IBAction)personalCenterAction:(NSButton *)sender {
- if (![self isConnectionAvailable]) {
- NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
- defaultButton:NSLocalizedString(@"OK", nil)
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
- [alert runModal];
- return;
- }
-
- // 用户头像点击事件
- 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 {
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
- #endif
- #endif
-
- [KMLoginWindowsController.shared showWindow:nil];
- }
- - (void)userGiftAction:(id)sender {
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_WelcomGift"}];
-
- [[KMNewUserGiftWindowController shared] openWindow];
- }
- - (void)discountAction:(id)sender {
- [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Conpon"}];
-
- #if VERSION_FREE
- if ([[KMCheckInManager default] trailCancel] || [[KMCheckInManager default] advancedYearSubscribeTrailCancelForLocal]) {
- [[KMProductCompareWC shared] setOrientation:true];
- #if VERSION_DMG
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
- #else
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- #endif
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeAdvancedYearSubscribeTrialingCancel];
- } else {
- [[KMProductCompareWC shared] setOrientation:true];
- #if VERSION_DMG
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
- #else
- [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
- #endif
- [[KMProductCompareWC shared] openWindowWithDiscountType:KMDiscountTypeNewUserGift];
- }
- #endif
- }
- #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)IAPProductLoaded:(NSNotification *)notification {
- dispatch_async(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];
-
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- [[KMProductCompareWC shared] closeAction];
- #endif
- #endif
- });
- }
- - (void)IAPRestoreFinish:(NSNotification *)notification {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)trailCancelStateDidChange:(NSNotification *)noti {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)advertisementDidLoaded:(NSNotification *)noti {
- 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 {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
- [self reloadData];
- });
- }
- - (void)logoutSuccessNotification:(NSNotification *)noti {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- self.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)subscriptionLoadedNotification:(NSNotification *)noti {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (void)memberInfoChangeNotification:(NSNotification *)noti {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadData];
- });
- }
- - (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
|