KMVerificationMessageViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. type == KMUserScenarioTypeDmg_type19 ||
  205. type == KMUserScenarioTypeDmg_type34) {
  206. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  207. } else if (type == KMUserScenarioTypeDmg_type11 ||
  208. type == KMUserScenarioTypeDmg_type22 ||
  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. type == KMUserScenarioTypeDmg_type19 ||
  467. type == KMUserScenarioTypeDmg_type34) {
  468. [[KMProductCompareWC shared] setOrientation:YES];
  469. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  470. [[KMProductCompareWC shared] showWindow:nil];
  471. } else {
  472. [[KMMemberInfo shared] advancedFunctionUsage];
  473. }
  474. }
  475. - (IBAction)officeButtonAction:(id)sender {
  476. }
  477. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  478. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  479. NSString *temp = nil;
  480. for (NSUInteger i = 0; i <string.length; i++) {
  481. temp = [string substringWithRange:NSMakeRange(i, 1)];
  482. if ([self isPureInt:temp]) {
  483. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  484. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  485. }
  486. }
  487. return attributedString;
  488. }
  489. - (BOOL)isPureInt:(NSString *)string {
  490. NSScanner *scan = [NSScanner scannerWithString:string];
  491. int value;
  492. return [scan scanInt:&value] && [scan isAtEnd];
  493. }
  494. - (IBAction)AIButtonAction:(NSButton *)sender {
  495. __block typeof(self) blockSelf = self;
  496. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  497. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  498. //
  499. // }];
  500. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  501. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  502. //#if VERSION_DMG
  503. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  504. // [embeddedWC showWindow:nil];
  505. // [[embeddedWC window] center];
  506. //#else
  507. //
  508. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  509. //#endif
  510. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  511. // };
  512. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  513. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  514. // verifyVC.callback = ^{
  515. //
  516. // };
  517. // [verifyVC showWindow:nil];
  518. // };
  519. //
  520. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  521. // if (!blockSelf.guideWindowVC) {
  522. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  523. // blockSelf.guideWindowVC = guideWindowVC;
  524. // }
  525. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  526. // [blockSelf.guideWindowVC showWindow:nil];
  527. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  528. // [blockSelf.guideWindowVC.window orderFront:nil];
  529. // };
  530. //
  531. // NSPopover *popover = [[NSPopover alloc] init];
  532. // popover.contentViewController = controller;
  533. // popover.animates = YES;
  534. // popover.behavior = NSPopoverBehaviorTransient;
  535. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  536. [[KMFreeGetAIWC shared] showWindow:nil];
  537. }
  538. - (IBAction)userButtonAction:(NSButton *)sender {
  539. if ([KMMemberInfo shared].isLogin) {
  540. [self personalCenterAction:sender];
  541. } else {
  542. [KMLoginWindowsController.shared showWindow:nil];
  543. }
  544. }
  545. - (IBAction)personalCenterAction:(NSButton *)sender {
  546. [KMUserInfoViewController refreshTokenUserInfoWithCallback:^(BOOL success,KMMemberCenterResult*resDic) {
  547. if(success) {
  548. if([KMMemberInfo shared].isLogin == YES) {
  549. // 用户头像点击事件
  550. self.userMenu = [[NSMenu alloc] init];
  551. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  552. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  553. item.target = self;
  554. item.representedObject = userInfo;
  555. item.view = userInfo.view;
  556. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  557. }
  558. } else {
  559. NSInteger code = resDic.code;
  560. if(code == 304) {
  561. [[KMLoginWindowsController shared] showWindow:nil];
  562. }
  563. }
  564. }];
  565. }
  566. - (IBAction)signUpAction:(NSButton *)sender {
  567. [KMLoginWindowsController.shared showWindow:nil];
  568. }
  569. #pragma mark - NSNotification Methods
  570. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  571. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  572. [self reloadData];
  573. });
  574. }
  575. - (void)IAPResultReceived:(NSNotification *)notification {
  576. dispatch_async(dispatch_get_main_queue(), ^{
  577. [self reloadData];
  578. });
  579. }
  580. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  581. dispatch_async(dispatch_get_main_queue(), ^{
  582. [self reloadData];
  583. });
  584. }
  585. - (void)IAPRestoreFinish:(NSNotification *)notification {
  586. dispatch_async(dispatch_get_main_queue(), ^{
  587. [self reloadData];
  588. });
  589. }
  590. #pragma mark - Event
  591. - (void)mouseEntered:(NSEvent *)event {
  592. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  593. ActivityStatusTrial == [VerificationManager manager].status) {
  594. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  595. if (!self.popover.isShown) {
  596. [self buttonAction:self.button];
  597. }
  598. }
  599. }
  600. - (void)mouseExited:(NSEvent *)event {
  601. [super mouseExited:event];
  602. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  603. }
  604. - (void)popoverDidClose:(NSNotification *)notification {
  605. self.stopPopOverHide = NO;
  606. }
  607. - (void)popoverShowNoti:(NSNotification *)noti {
  608. if (self.popover) {
  609. [self.popover close];
  610. self.stopPopOverHide = NO;
  611. }
  612. }
  613. - (void)loginSuccessNotification:(NSNotification *)noti {
  614. dispatch_async(dispatch_get_main_queue(), ^{
  615. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  616. [self reloadData];
  617. });
  618. }
  619. - (void)logoutSuccessNotification:(NSNotification *)noti {
  620. dispatch_async(dispatch_get_main_queue(), ^{
  621. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  622. [self reloadData];
  623. });
  624. }
  625. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  626. if (self.userMenu != nil) {
  627. [self personalCenterAction:_userButton];
  628. }
  629. }
  630. - (void)closeMenu:(NSNotification *)noti {
  631. if (self.userMenu != nil) {
  632. [self.userMenu cancelTracking];
  633. self.userMenu = nil;
  634. }
  635. }
  636. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  637. dispatch_async(dispatch_get_main_queue(), ^{
  638. [self reloadData];
  639. });
  640. }
  641. - (void)popOverCloseAction {
  642. if (self.stopPopOverHide == NO) {
  643. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  644. ActivityStatusTrial == [VerificationManager manager].status) {
  645. if (self.popover.isShown) {
  646. [self.popover close];
  647. self.stopPopOverHide = NO;
  648. }
  649. }
  650. }
  651. }
  652. @end