KMVerificationMessageViewController.m 32 KB

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