KMVerificationMessageViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. #if !VERSION_DMG
  181. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) {
  182. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  183. } else {
  184. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  185. }
  186. #else
  187. #endif
  188. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  189. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  190. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  191. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  192. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  193. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  194. __weak typeof(self)weakSelf = self;
  195. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  196. weakSelf.bgImg.image = image;
  197. }];
  198. }
  199. }
  200. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ) {
  201. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  202. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11) {
  203. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  204. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  205. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  206. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  207. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3 ||
  208. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  209. if([KMMemberInfo shared].vip_status == 2) {
  210. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  211. } else if ([KMMemberInfo shared].vip_status == 4) {
  212. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  213. } else {
  214. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  215. }
  216. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  217. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  218. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  219. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  220. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  221. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  222. __weak typeof(self)weakSelf = self;
  223. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  224. weakSelf.bgImg.image = image;
  225. }];
  226. }
  227. }
  228. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7) {
  229. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  230. }
  231. [self.button setTitleColor:[NSColor whiteColor]];
  232. self.bgImg.hidden = NO;
  233. self.button.hidden = NO;
  234. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  235. if ([IAPProductsManager defaultManager].fourDevicesAllAccessPackNew12months_lite.isTrialPeriod) {
  236. self.bgImg.hidden = YES;
  237. self.button.hidden = YES;
  238. }
  239. }
  240. BOOL isOldSubscribed = NO;
  241. #if VERSION_FREE
  242. #if !VERSION_DMG
  243. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  244. #endif
  245. #endif
  246. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  247. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  248. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  249. if(type == KMUserScenarioTypeLite_type9 ||
  250. type == KMUserScenarioTypeLite_type10 ||
  251. type == KMUserScenarioTypeLite_type11 ||
  252. type == KMUserScenarioTypeLite_type12 ||
  253. type == KMUserScenarioTypePro_type1 ||
  254. type == KMUserScenarioTypePro_type2 ||
  255. type == KMUserScenarioTypePro_type3 ||
  256. type == KMUserScenarioTypePro_type4 ||
  257. type == KMUserScenarioTypePro_type5) {
  258. if ([KMMemberInfo shared].isLogin == NO || ((KMMemberInfo.shared.vip_status == 1 || KMMemberInfo.shared.vip_status == 4) && [KMMemberInfo shared].isLogin == YES && isOldSubscribed)) {
  259. self.button.hidden = YES;
  260. self.bgImg.hidden = YES;
  261. }
  262. } else if(type == KMUserScenarioTypeLite_type13) {
  263. self.button.hidden = YES;
  264. self.bgImg.hidden = YES;
  265. }
  266. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  267. CGRect rect = self.button.frame;
  268. self.bgImg.frame = rect;
  269. totalWidth+=CGRectGetWidth(self.button.bounds);
  270. totalWidth+=4;
  271. }
  272. if ([KMMemberInfo shared].isLogin) {
  273. self.userButton.hidden = NO;
  274. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  275. totalWidth += userImageWidth;
  276. totalWidth += 8;
  277. } else {
  278. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  279. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  280. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  281. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  282. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  283. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  284. __weak typeof(self)weakSelf = self;
  285. weakSelf.bgImg.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  286. weakSelf.bgImg.image = image;
  287. }];
  288. }
  289. }
  290. self.signUpView.hidden = NO;
  291. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  292. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  293. }
  294. if (self.view.superview) {
  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. } else {
  297. // if (self.button.hidden) {
  298. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.aiLabel.frame) + 20 ,self.view.frame.size.height);
  299. // } else {
  300. // self.view.frame = CGRectMake(0,0, CGRectGetMaxX(self.button.frame) ,self.view.frame.size.height);
  301. // }
  302. 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);
  303. }
  304. }
  305. #pragma mark - Button Actions
  306. - (IBAction)secondTrialAction:(NSButton *)sender {
  307. if ([VerificationManager manager].secondTrialEnabled) {
  308. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  309. [vc showWindow:nil];
  310. } else {
  311. [[KMProductCompareWC shared] setOrientation:NO];
  312. [[KMProductCompareWC shared] showWindow:nil];
  313. }
  314. }
  315. - (IBAction)buttonAction:(id)sender {
  316. if ([KMMemberInfo shared].isLogin) {
  317. [[KMProductCompareWC shared] setOrientation:YES];
  318. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  319. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  320. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  321. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  322. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  323. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  324. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  325. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  326. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  327. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  328. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  329. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  330. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  331. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  332. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  333. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  334. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  335. }
  336. [[KMProductCompareWC shared] showWindow:nil];
  337. } else {
  338. [KMLoginWindowsController.shared openWindow:^(BOOL success) {
  339. if (success) {
  340. [[KMProductCompareWC shared] setOrientation:YES];
  341. if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type1) {
  342. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  343. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type3 ||
  344. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type7 ||
  345. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type8) {
  346. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  347. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type4 ||
  348. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type5 ||
  349. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type9 ||
  350. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type11 ||
  351. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypeLite_type13) {
  352. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_MacWindows];
  353. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type1 ||
  354. [KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type4) {
  355. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Advanced];
  356. } else if ([KMMemberInfo shared].userScenarioType == KMUserScenarioTypePro_type3) {
  357. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  358. }
  359. [[KMProductCompareWC shared] showWindow:nil];
  360. }
  361. }];
  362. }
  363. }
  364. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  365. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  366. NSString *temp = nil;
  367. for (NSUInteger i = 0; i <string.length; i++) {
  368. temp = [string substringWithRange:NSMakeRange(i, 1)];
  369. if ([self isPureInt:temp]) {
  370. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  371. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  372. }
  373. }
  374. return attributedString;
  375. }
  376. - (BOOL)isPureInt:(NSString *)string {
  377. NSScanner *scan = [NSScanner scannerWithString:string];
  378. int value;
  379. return [scan scanInt:&value] && [scan isAtEnd];
  380. }
  381. - (IBAction)AIButtonAction:(NSButton *)sender {
  382. __block typeof(self) blockSelf = self;
  383. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  384. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  385. //
  386. // }];
  387. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  388. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  389. //#if VERSION_DMG
  390. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  391. // [embeddedWC showWindow:nil];
  392. // [[embeddedWC window] center];
  393. //#else
  394. //
  395. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  396. //#endif
  397. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  398. // };
  399. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  400. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  401. // verifyVC.callback = ^{
  402. //
  403. // };
  404. // [verifyVC showWindow:nil];
  405. // };
  406. //
  407. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  408. // if (!blockSelf.guideWindowVC) {
  409. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  410. // blockSelf.guideWindowVC = guideWindowVC;
  411. // }
  412. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  413. // [blockSelf.guideWindowVC showWindow:nil];
  414. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  415. // [blockSelf.guideWindowVC.window orderFront:nil];
  416. // };
  417. //
  418. // NSPopover *popover = [[NSPopover alloc] init];
  419. // popover.contentViewController = controller;
  420. // popover.animates = YES;
  421. // popover.behavior = NSPopoverBehaviorTransient;
  422. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  423. [[KMFreeGetAIWC shared] showWindow:nil];
  424. }
  425. - (IBAction)userButtonAction:(NSButton *)sender {
  426. if ([KMMemberInfo shared].isLogin) {
  427. [self personalCenterAction:sender];
  428. } else {
  429. [KMLoginWindowsController.shared showWindow:nil];
  430. }
  431. }
  432. - (IBAction)personalCenterAction:(NSButton *)sender {
  433. // 用户头像点击事件
  434. self.userMenu = [[NSMenu alloc] init];
  435. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  436. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  437. item.target = self;
  438. item.representedObject = userInfo;
  439. item.view = userInfo.view;
  440. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  441. }
  442. - (IBAction)signUpAction:(NSButton *)sender {
  443. [KMLoginWindowsController.shared showWindow:nil];
  444. }
  445. #pragma mark - NSNotification Methods
  446. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  447. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  448. [self reloadData];
  449. });
  450. }
  451. - (void)IAPResultReceived:(NSNotification *)notification {
  452. dispatch_async(dispatch_get_main_queue(), ^{
  453. [self reloadData];
  454. });
  455. }
  456. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  457. dispatch_async(dispatch_get_main_queue(), ^{
  458. [self reloadData];
  459. });
  460. }
  461. - (void)IAPRestoreFinish:(NSNotification *)notification {
  462. dispatch_async(dispatch_get_main_queue(), ^{
  463. [self reloadData];
  464. });
  465. }
  466. #pragma mark - Event
  467. - (void)mouseEntered:(NSEvent *)event {
  468. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  469. ActivityStatusTrial == [VerificationManager manager].status) {
  470. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  471. if (!self.popover.isShown) {
  472. [self buttonAction:self.button];
  473. }
  474. }
  475. }
  476. - (void)mouseExited:(NSEvent *)event {
  477. [super mouseExited:event];
  478. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  479. }
  480. - (void)popoverDidClose:(NSNotification *)notification {
  481. self.stopPopOverHide = NO;
  482. }
  483. - (void)popoverShowNoti:(NSNotification *)noti {
  484. if (self.popover) {
  485. [self.popover close];
  486. self.stopPopOverHide = NO;
  487. }
  488. }
  489. - (void)loginSuccessNotification:(NSNotification *)noti {
  490. _userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  491. [self reloadData];
  492. }
  493. - (void)logoutSuccessNotification:(NSNotification *)noti {
  494. _userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  495. [self reloadData];
  496. }
  497. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  498. if (self.userMenu != nil) {
  499. [self personalCenterAction:_userButton];
  500. }
  501. }
  502. - (void)closeMenu:(NSNotification *)noti {
  503. if (self.userMenu != nil) {
  504. [self.userMenu cancelTracking];
  505. self.userMenu = nil;
  506. }
  507. }
  508. - (void)popOverCloseAction {
  509. if (self.stopPopOverHide == NO) {
  510. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  511. ActivityStatusTrial == [VerificationManager manager].status) {
  512. if (self.popover.isShown) {
  513. [self.popover close];
  514. self.stopPopOverHide = NO;
  515. }
  516. }
  517. }
  518. }
  519. @end