KMVerificationMessageViewController.m 29 KB

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