KMVerificationMessageViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. //
  2. // KMVerificationMessageViewController.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by 王帅 on 2018/5/9.
  6. //
  7. #import "KMVerificationMessageViewController.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. #import "VerificationManager.h"
  10. #import "AIInfoManager.h"
  11. #import "KMVerificationWindowController.h"
  12. #import "KMUnlockAlertViewController.h"
  13. #define kbottomGap 0
  14. @interface KMVerificationMessageViewController ()<
  15. NSPopoverDelegate>
  16. @property (nonatomic, assign) IBOutlet NSTextField *label;
  17. @property (nonatomic, assign) IBOutlet NSButton *button;
  18. @property (nonatomic, assign) IBOutlet NSButton *secondTrialBtn;
  19. @property (assign) IBOutlet NSView *labelContentView;
  20. @property (assign) IBOutlet NSImageView *bgImg;
  21. @property (assign) IBOutlet NSView *aiContendView;
  22. @property (assign) IBOutlet NSImageView *aiIconImg;
  23. @property (assign) IBOutlet NSTextField *aiLabel;
  24. @property (weak) IBOutlet NSButton *userButton;
  25. @property (assign) IBOutlet NSView *signUpView;
  26. @property (assign) IBOutlet NSImageView *signUpImg;
  27. @property (assign) IBOutlet NSTextField *signUpLabel;
  28. @property (nonatomic, retain) NSTrackingArea *trackingArea;
  29. @property (nonatomic, retain) NSPopover *popover;
  30. @property (nonatomic, assign) BOOL isPopoverShow;
  31. @property (nonatomic, assign) BOOL checkValue;
  32. @property (nonatomic, assign) BOOL stopPopOverHide;
  33. @property (nonatomic, retain) KMUnlockAlertViewController *testVC;
  34. @property (nonatomic, retain) NSMenu *userMenu;
  35. @end
  36. @implementation KMVerificationMessageViewController
  37. #pragma mark Init Methods
  38. - (instancetype)init {
  39. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  40. #if VERSION_DMG
  41. [[NSNotificationCenter defaultCenter] addObserver:self
  42. selector:@selector(deviceActivateStatusChangeNotification:)
  43. name:kDeviceActivateStatusChangeNotification
  44. object:nil];
  45. #else
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  49. #endif
  50. }
  51. return self;
  52. }
  53. - (void)dealloc {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self];
  55. if (self.trackingArea) {
  56. [self.button removeTrackingArea:self.trackingArea];
  57. }
  58. }
  59. #pragma mark Setter Methods
  60. - (void)loadView {
  61. [super loadView];
  62. // Do view setup here.
  63. self.button.wantsLayer = YES;
  64. self.button.layer.masksToBounds = YES;
  65. self.button.layer.cornerRadius = 4.0;
  66. self.button.font = [NSFont SFProTextSemiboldFont:11];
  67. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  68. [self.button setAlignment:NSTextAlignmentCenter];
  69. self.secondTrialBtn.wantsLayer = YES;
  70. self.secondTrialBtn.layer.masksToBounds = YES;
  71. self.secondTrialBtn.layer.cornerRadius = 4.0;
  72. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  73. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  74. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  75. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  76. #if VERSION_DMG
  77. 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)];
  78. #else
  79. 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)];
  80. #endif
  81. self.button.toolTip = tTips;
  82. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  83. [self.button setTitleColor:[NSColor whiteColor]];
  84. [self.button setAlignment:NSTextAlignmentCenter];
  85. self.secondTrialBtn.toolTip = tTips;
  86. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  87. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  88. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  89. self.secondTrialBtn.hidden = YES;
  90. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = YES;
  91. self.bgImg.wantsLayer = YES;
  92. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  93. self.bgImg.layer.masksToBounds = YES;
  94. self.bgImg.layer.cornerRadius = 4.;
  95. self.bgImg.hidden = YES;
  96. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  97. self.aiLabel.textColor = [NSColor whiteColor];
  98. [self reloadData];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  100. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  101. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  102. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  104. }
  105. - (void)reloadData {
  106. self.label.textColor = [NSColor blackColor];
  107. self.label.hidden = NO;
  108. BOOL isFree = NO;
  109. self.secondTrialBtn.hidden = YES;
  110. self.bgImg.hidden = YES;
  111. if (self.frameUpdateHandle) {
  112. self.frameUpdateHandle(self.view.frame);
  113. }
  114. CGFloat totalWidth = 8;
  115. self.button.hidden = YES;
  116. self.label.hidden = YES;
  117. self.secondTrialBtn.hidden = YES;
  118. self.labelContentView.hidden = YES;
  119. self.bgImg.hidden = YES;
  120. self.aiContendView.hidden = YES;
  121. self.userButton.hidden = YES;
  122. self.signUpView.hidden = YES;
  123. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  124. [self.signUpLabel sizeToFit];
  125. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  126. signUpWidth += 4;
  127. signUpWidth += 8;
  128. signUpWidth += 8;
  129. signUpWidth += 12;
  130. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  131. CGRect signUplabelRect = self.signUpLabel.frame;
  132. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  133. self.signUpLabel.frame = signUplabelRect;
  134. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  135. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  136. [self.button setTitleColor:[NSColor whiteColor]];
  137. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free to receive 1 year of AI", @"MemberCenterLocalizable", nil);
  138. [self.aiLabel sizeToFit];
  139. CGFloat aiWidth = self.aiLabel.frame.size.width;
  140. aiWidth += 4;
  141. aiWidth += 16;
  142. aiWidth += 16;
  143. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  144. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  145. CGRect ailabelRect = self.aiLabel.frame;
  146. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  147. self.aiLabel.frame = ailabelRect;
  148. // totalWidth+=aiWidth;
  149. // totalWidth+=4;
  150. // self.aiContendView.hidden = NO;
  151. CGFloat userImageWidth = 24;
  152. if ([KMMemberInfo shared].isLogin) {
  153. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  154. } else {
  155. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  156. }
  157. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  158. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  159. if (fabs(buttonWidth-btnRect.size.width)>50) {
  160. buttonWidth = btnRect.size.width + 10;
  161. }
  162. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  163. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  164. self.aiContendView.hidden = NO;
  165. totalWidth+=aiWidth;
  166. totalWidth+=4;
  167. }
  168. }
  169. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1 ||
  170. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  171. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  172. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  173. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  174. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13 ||
  175. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  176. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  177. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  178. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  179. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  180. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  181. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  182. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  183. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  184. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  185. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  186. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  187. __weak typeof(self)weakSelf = self;
  188. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  189. weakSelf.bgImg.image = image;
  190. }];
  191. }
  192. }
  193. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ) {
  194. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  195. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  196. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  197. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  198. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  199. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  200. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  201. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  202. if([KMMemberInfo shared].vip_status == 2) {
  203. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  204. } else if ([KMMemberInfo shared].vip_status == 4) {
  205. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  206. } else {
  207. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  208. }
  209. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  210. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  211. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  212. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  213. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  214. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  215. __weak typeof(self)weakSelf = self;
  216. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  217. weakSelf.bgImg.image = image;
  218. }];
  219. }
  220. }
  221. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7) {
  222. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  223. }
  224. [self.button setTitleColor:[NSColor whiteColor]];
  225. self.bgImg.hidden = NO;
  226. self.button.hidden = NO;
  227. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  228. if ([IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.isTrialPeriod) {
  229. self.bgImg.hidden = YES;
  230. self.button.hidden = YES;
  231. }
  232. }
  233. BOOL isOldSubscribed = NO;
  234. #if VERSION_FREE
  235. #if !VERSION_DMG
  236. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  237. #endif
  238. #endif
  239. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  240. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  241. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  242. if(type == KMUserScenarioTypeLite_type9 ||
  243. type == KMUserScenarioTypeLite_type10 ||
  244. type == KMUserScenarioTypeLite_type11 ||
  245. type == KMUserScenarioTypeLite_type12 ||
  246. type == KMUserScenarioTypePro_type1 ||
  247. type == KMUserScenarioTypePro_type2 ||
  248. type == KMUserScenarioTypePro_type3 ||
  249. type == KMUserScenarioTypePro_type4 ||
  250. type == KMUserScenarioTypePro_type5) {
  251. if ([KMMemberInfo shared].isLogin == NO || ((KMMemberInfo.shared.vip_status == 1 || KMMemberInfo.shared.vip_status == 4) && [KMMemberInfo shared].isLogin == YES && isOldSubscribed)) {
  252. self.button.hidden = YES;
  253. self.bgImg.hidden = YES;
  254. }
  255. } else if(type == KMUserScenarioTypeLite_type13) {
  256. self.button.hidden = YES;
  257. self.bgImg.hidden = YES;
  258. }
  259. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  260. CGRect rect = self.button.frame;
  261. self.bgImg.frame = rect;
  262. totalWidth+=CGRectGetWidth(self.button.bounds);
  263. totalWidth+=4;
  264. }
  265. if ([KMMemberInfo shared].isLogin) {
  266. self.userButton.hidden = NO;
  267. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  268. totalWidth += userImageWidth;
  269. totalWidth += 8;
  270. } else {
  271. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  272. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  273. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  274. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  275. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  276. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  277. __weak typeof(self)weakSelf = self;
  278. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  279. weakSelf.bgImg.image = image;
  280. }];
  281. }
  282. }
  283. self.signUpView.hidden = NO;
  284. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  285. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  286. }
  287. if (self.view.superview) {
  288. 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);
  289. } else {
  290. // if (self.button.hidden) {
  291. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  292. // } else {
  293. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  294. // }
  295. 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);
  296. }
  297. }
  298. #pragma mark - Button Actions
  299. - (IBAction)secondTrialAction:(NSButton *)sender {
  300. if ([VerificationManager manager].secondTrialEnabled) {
  301. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  302. [vc showWindow:nil];
  303. } else {
  304. [[KMProductCompareWC shared] setOrientation:NO];
  305. [[KMProductCompareWC shared] showWindow:nil];
  306. }
  307. }
  308. - (IBAction)buttonAction:(id)sender {
  309. if ([KMMemberInfo shared].isLogin) {
  310. [[KMProductCompareWC shared] setOrientation:YES];
  311. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  312. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  313. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  314. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  315. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  316. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  317. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  318. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  319. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  320. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  321. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  322. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  323. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  324. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  325. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  326. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  327. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  328. }
  329. [[KMProductCompareWC shared] showWindow:nil];
  330. } else {
  331. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  332. if (success) {
  333. [[KMProductCompareWC shared] setOrientation:YES];
  334. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  335. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  336. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  337. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  338. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  339. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  340. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  341. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  342. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  343. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  344. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  345. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  346. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  347. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  348. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  349. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  350. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  351. }
  352. [[KMProductCompareWC shared] showWindow:nil];
  353. }
  354. }];
  355. }
  356. }
  357. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  358. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  359. NSString *temp = nil;
  360. for (NSUInteger i = 0; i <string.length; i++) {
  361. temp = [string substringWithRange:NSMakeRange(i, 1)];
  362. if ([self isPureInt:temp]) {
  363. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  364. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  365. }
  366. }
  367. return attributedString;
  368. }
  369. - (BOOL)isPureInt:(NSString *)string {
  370. NSScanner *scan = [NSScanner scannerWithString:string];
  371. int value;
  372. return [scan scanInt:&value] && [scan isAtEnd];
  373. }
  374. - (IBAction)AIButtonAction:(NSButton *)sender {
  375. __block typeof(self) blockSelf = self;
  376. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  377. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  378. //
  379. // }];
  380. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  381. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  382. //#if VERSION_DMG
  383. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  384. // [embeddedWC showWindow:nil];
  385. // [[embeddedWC window] center];
  386. //#else
  387. //
  388. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  389. //#endif
  390. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  391. // };
  392. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  393. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  394. // verifyVC.callback = ^{
  395. //
  396. // };
  397. // [verifyVC showWindow:nil];
  398. // };
  399. //
  400. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  401. // if (!blockSelf.guideWindowVC) {
  402. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  403. // blockSelf.guideWindowVC = guideWindowVC;
  404. // }
  405. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  406. // [blockSelf.guideWindowVC showWindow:nil];
  407. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  408. // [blockSelf.guideWindowVC.window orderFront:nil];
  409. // };
  410. //
  411. // NSPopover *popover = [[NSPopover alloc] init];
  412. // popover.contentViewController = controller;
  413. // popover.animates = YES;
  414. // popover.behavior = NSPopoverBehaviorTransient;
  415. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  416. [[KMFreeGetAIWC shared] showWindow:nil];
  417. }
  418. - (IBAction)userButtonAction:(NSButton *)sender {
  419. if ([KMMemberInfo shared].isLogin) {
  420. [self personalCenterAction:sender];
  421. } else {
  422. [KMLoginWindowsController.shared showWindow:nil];
  423. }
  424. }
  425. - (IBAction)personalCenterAction:(NSButton *)sender {
  426. // 用户头像点击事件
  427. self.userMenu = [[NSMenu alloc] init];
  428. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  429. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  430. item.target = self;
  431. item.representedObject = userInfo;
  432. item.view = userInfo.view;
  433. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  434. }
  435. - (IBAction)signUpAction:(NSButton *)sender {
  436. [KMLoginWindowsController.shared showWindow:nil];
  437. }
  438. #pragma mark - NSNotification Methods
  439. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  440. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  441. [self reloadData];
  442. });
  443. }
  444. - (void)IAPResultReceived:(NSNotification *)notification {
  445. dispatch_async(dispatch_get_main_queue(), ^{
  446. [self reloadData];
  447. });
  448. }
  449. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  450. dispatch_async(dispatch_get_main_queue(), ^{
  451. [self reloadData];
  452. });
  453. }
  454. - (void)IAPRestoreFinish:(NSNotification *)notification {
  455. dispatch_async(dispatch_get_main_queue(), ^{
  456. [self reloadData];
  457. });
  458. }
  459. #pragma mark - Event
  460. - (void)mouseEntered:(NSEvent *)event {
  461. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  462. ActivityStatusTrial == [VerificationManager manager].status) {
  463. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  464. if (!self.popover.isShown) {
  465. [self buttonAction:self.button];
  466. }
  467. }
  468. }
  469. - (void)mouseExited:(NSEvent *)event {
  470. [super mouseExited:event];
  471. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  472. }
  473. - (void)popoverDidClose:(NSNotification *)notification {
  474. self.stopPopOverHide = NO;
  475. }
  476. - (void)popoverShowNoti:(NSNotification *)noti {
  477. if (self.popover) {
  478. [self.popover close];
  479. self.stopPopOverHide = NO;
  480. }
  481. }
  482. - (void)loginSuccessNotification:(NSNotification *)noti {
  483. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  484. [self reloadData];
  485. }
  486. - (void)logoutSuccessNotification:(NSNotification *)noti {
  487. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  488. [self reloadData];
  489. }
  490. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  491. if (self.userMenu != nil) {
  492. [self personalCenterAction:_userButton];
  493. }
  494. }
  495. - (void)closeMenu:(NSNotification *)noti {
  496. if (self.userMenu != nil) {
  497. [self.userMenu cancelTracking];
  498. self.userMenu = nil;
  499. }
  500. }
  501. - (void)popOverCloseAction {
  502. if (self.stopPopOverHide == NO) {
  503. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  504. ActivityStatusTrial == [VerificationManager manager].status) {
  505. if (self.popover.isShown) {
  506. [self.popover close];
  507. self.stopPopOverHide = NO;
  508. }
  509. }
  510. }
  511. }
  512. @end