KMVerificationMessageViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  252. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  253. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  254. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  255. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  256. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  257. __weak typeof(self)weakSelf = self;
  258. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  259. if (image != nil) {
  260. weakSelf.bgImg.image = image;
  261. }
  262. }];
  263. }
  264. }
  265. self.bgImg.hidden = NO;
  266. self.button.hidden = NO;
  267. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  268. CGRect rect = self.button.frame;
  269. self.bgImg.frame = rect;
  270. totalWidth+=CGRectGetWidth(self.button.bounds);
  271. totalWidth+=4;
  272. }
  273. #else
  274. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  275. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  276. self.aiContendView.hidden = NO;
  277. totalWidth+=aiWidth;
  278. totalWidth+=4;
  279. }
  280. }
  281. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  282. if (type == KMUserScenarioTypeLite_type1 ||
  283. type == KMUserScenarioTypeLite_type3 ||
  284. type == KMUserScenarioTypeLite_type5 ||
  285. type == KMUserScenarioTypeLite_type7 ||
  286. type == KMUserScenarioTypeLite_type9 ||
  287. type == KMUserScenarioTypeLite_type11 ||
  288. type == KMUserScenarioTypePro_type1 ||
  289. type == KMUserScenarioTypePro_type3 ||
  290. type == KMUserScenarioTypePro_type4) {
  291. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  292. #if !VERSION_DMG
  293. if(KMMemberInfo.shared.isLogin == NO) {
  294. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  295. } else {
  296. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  297. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  298. } else {
  299. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  300. }
  301. }
  302. #else
  303. #endif
  304. } else if (type == KMUserScenarioTypeLite_type3 ) {
  305. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  306. } else if (type == KMUserScenarioTypeLite_type5) {
  307. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  308. } else if (type == KMUserScenarioTypeLite_type7) {
  309. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  310. } else if (type == KMUserScenarioTypeLite_type9) {
  311. if([KMMemberInfo shared].vip_status == 2) {
  312. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  313. } else if ([KMMemberInfo shared].vip_status == 4) {
  314. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  315. } else {
  316. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  317. }
  318. } else if (type == KMUserScenarioTypeLite_type11) {
  319. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  320. } else if (type == KMUserScenarioTypePro_type3) {
  321. if([KMMemberInfo shared].vip_status == 2) {
  322. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  323. } else {
  324. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  325. }
  326. }
  327. #if !VERSION_FREE
  328. BOOL isNoSupportMemberUpgrade = YES;
  329. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  330. isNoSupportMemberUpgrade = NO;
  331. }
  332. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  333. [self.officeButton setTitleColor:[NSColor whiteColor]];
  334. self.officeButton.hidden = NO;
  335. self.officeImg.hidden = NO;
  336. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  337. CGRect officeRect = self.officeButton.frame;
  338. self.officeImg.frame = officeRect;
  339. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  340. totalWidth+=4;
  341. } else {
  342. self.officeButton.hidden = YES;
  343. self.officeImg.hidden = YES;
  344. }
  345. #else
  346. self.officeButton.hidden = YES;
  347. self.officeImg.hidden = YES;
  348. #endif
  349. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  350. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  351. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  352. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  353. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  354. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  355. __weak typeof(self)weakSelf = self;
  356. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  357. if (image != nil) {
  358. weakSelf.bgImg.image = image;
  359. }
  360. }];
  361. }
  362. }
  363. [self.button setTitleColor:[NSColor whiteColor]];
  364. self.bgImg.hidden = NO;
  365. self.button.hidden = NO;
  366. BOOL isOldSubscribed = NO;
  367. #if VERSION_FREE
  368. #if !VERSION_DMG
  369. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  370. #endif
  371. #endif
  372. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  373. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  374. if(type == KMUserScenarioTypeLite_type9 ||
  375. type == KMUserScenarioTypeLite_type10 ||
  376. type == KMUserScenarioTypeLite_type11) {
  377. if([KMMemberInfo shared].isLogin == NO) { //未登录
  378. self.button.hidden = YES;
  379. self.bgImg.hidden = YES;
  380. } else {
  381. if(isOldSubscribed) { //老版本付费功能是订阅包
  382. self.button.hidden = YES;
  383. self.bgImg.hidden = YES;
  384. } else {
  385. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  386. self.button.hidden = YES;
  387. self.bgImg.hidden = YES;
  388. }
  389. }
  390. }
  391. }
  392. buttonWidth = CGRectGetMaxX(self.button.frame);
  393. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  394. if (fabs(buttonWidth-btnRect.size.width)>50) {
  395. buttonWidth = btnRect.size.width + 10;
  396. }
  397. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  398. CGRect rect = self.button.frame;
  399. self.bgImg.frame = rect;
  400. totalWidth+=CGRectGetWidth(self.button.bounds);
  401. totalWidth+=4;
  402. } else if (type == KMUserScenarioTypeLite_type12 ||
  403. type == KMUserScenarioTypeLite_type13 ||
  404. type == KMUserScenarioTypeLite_type2 ||
  405. type == KMUserScenarioTypeLite_type4 ||
  406. type == KMUserScenarioTypeLite_type6 ||
  407. type == KMUserScenarioTypeLite_type8 ||
  408. type == KMUserScenarioTypePro_type2 ||
  409. type == KMUserScenarioTypePro_type5) {
  410. self.button.hidden = YES;
  411. self.bgImg.hidden = YES;
  412. #if !VERSION_FREE
  413. BOOL isNoSupportMemberUpgrade = YES;
  414. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  415. isNoSupportMemberUpgrade = NO;
  416. }
  417. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  418. [self.officeButton setTitleColor:[NSColor whiteColor]];
  419. self.officeButton.hidden = NO;
  420. self.officeImg.hidden = NO;
  421. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  422. CGRect officeRect = self.officeButton.frame;
  423. self.officeImg.frame = officeRect;
  424. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  425. totalWidth+=4;
  426. } else {
  427. self.officeButton.hidden = YES;
  428. self.officeImg.hidden = YES;
  429. }
  430. #else
  431. self.officeButton.hidden = YES;
  432. self.officeImg.hidden = YES;
  433. #endif
  434. }
  435. #endif
  436. if ([KMMemberInfo shared].isLogin) {
  437. self.userButton.hidden = NO;
  438. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  439. totalWidth += userImageWidth;
  440. totalWidth += 8;
  441. } else {
  442. self.signUpView.hidden = NO;
  443. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  444. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  445. }
  446. 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);
  447. }
  448. #pragma mark - Button Actions
  449. - (IBAction)secondTrialAction:(NSButton *)sender {
  450. if ([VerificationManager manager].secondTrialEnabled) {
  451. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  452. [vc showWindow:nil];
  453. } else {
  454. [[KMProductCompareWC shared] setOrientation:NO];
  455. [[KMProductCompareWC shared] showWindow:nil];
  456. }
  457. }
  458. - (IBAction)buttonAction:(id)sender {
  459. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  460. if (type == KMUserScenarioTypeDmg_type4 ||
  461. type == KMUserScenarioTypeDmg_type19 ||
  462. type == KMUserScenarioTypeDmg_type34) {
  463. [[KMProductCompareWC shared] setOrientation:YES];
  464. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  465. [[KMProductCompareWC shared] showWindow:nil];
  466. } else {
  467. [[KMMemberInfo shared] advancedFunctionUsage];
  468. }
  469. }
  470. - (IBAction)officeButtonAction:(id)sender {
  471. }
  472. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  473. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  474. NSString *temp = nil;
  475. for (NSUInteger i = 0; i <string.length; i++) {
  476. temp = [string substringWithRange:NSMakeRange(i, 1)];
  477. if ([self isPureInt:temp]) {
  478. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  479. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  480. }
  481. }
  482. return attributedString;
  483. }
  484. - (BOOL)isPureInt:(NSString *)string {
  485. NSScanner *scan = [NSScanner scannerWithString:string];
  486. int value;
  487. return [scan scanInt:&value] && [scan isAtEnd];
  488. }
  489. - (IBAction)AIButtonAction:(NSButton *)sender {
  490. __block typeof(self) blockSelf = self;
  491. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit"}];
  492. // [[AIInfoManager defaultManager] fetchAIInfoWithComplention:^(NSDictionary *info, NSError *error) {
  493. //
  494. // }];
  495. // AIUserInfoController *controller = [[AIUserInfoController alloc] init];
  496. // controller.purchaseHandle = ^(AIUserInfoController * _Nonnull vc) {
  497. //#if VERSION_DMG
  498. // KMPurchaseEmbeddedWindowController *embeddedWC = [KMPurchaseEmbeddedWindowController currentFirstTrialWC:@"com.brother.pdfreaderpro.ai.product_1"];
  499. // [embeddedWC showWindow:nil];
  500. // [[embeddedWC window] center];
  501. //#else
  502. //
  503. // [[AIPurchaseWindowController currentWC] showWindow:nil];
  504. //#endif
  505. // [[FMTrackEventManager defaultManager] trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn":@"Btn_Tbr_AICredit_BuyNow"}];
  506. // };
  507. // controller.enterLicenseHandle = ^(AIUserInfoController * _Nonnull vc) {
  508. // KMVerificationWindowController *verifyVC = [KMVerificationWindowController verificationWithType:KMVerificationTypeActivateAIInfo];
  509. // verifyVC.callback = ^{
  510. //
  511. // };
  512. // [verifyVC showWindow:nil];
  513. // };
  514. //
  515. // controller.guideHandle = ^(AIUserInfoController * _Nonnull vc) {
  516. // if (!blockSelf.guideWindowVC) {
  517. // KMFunctionGuideWindowController *guideWindowVC = [[KMFunctionGuideWindowController alloc] initWithWindowNibName:@"KMFunctionGuideWindowController"];
  518. // blockSelf.guideWindowVC = guideWindowVC;
  519. // }
  520. // ((KMFunctionGuideWindowController *)(blockSelf.guideWindowVC)).type = KMGuideInfoTypeFunctionMulti;
  521. // [blockSelf.guideWindowVC showWindow:nil];
  522. // [KMFunctionGuideWindowController setDidShowFor:KMGuideInfoTypeFunctionMultiAIGuide];
  523. // [blockSelf.guideWindowVC.window orderFront:nil];
  524. // };
  525. //
  526. // NSPopover *popover = [[NSPopover alloc] init];
  527. // popover.contentViewController = controller;
  528. // popover.animates = YES;
  529. // popover.behavior = NSPopoverBehaviorTransient;
  530. // [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
  531. [[KMFreeGetAIWC shared] showWindow:nil];
  532. }
  533. - (IBAction)userButtonAction:(NSButton *)sender {
  534. if ([KMMemberInfo shared].isLogin) {
  535. [self personalCenterAction:sender];
  536. } else {
  537. [KMLoginWindowsController.shared showWindow:nil];
  538. }
  539. }
  540. - (IBAction)personalCenterAction:(NSButton *)sender {
  541. [KMUserInfoViewController refreshTokenUserInfoWithCallback:^(BOOL success,KMMemberCenterResult*resDic) {
  542. if(success) {
  543. if([KMMemberInfo shared].isLogin == YES) {
  544. // 用户头像点击事件
  545. self.userMenu = [[NSMenu alloc] init];
  546. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  547. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  548. item.target = self;
  549. item.representedObject = userInfo;
  550. item.view = userInfo.view;
  551. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  552. }
  553. } else {
  554. NSInteger code = resDic.code;
  555. if(code == 304) {
  556. [[KMLoginWindowsController shared] showWindow:nil];
  557. }
  558. }
  559. }];
  560. }
  561. - (IBAction)signUpAction:(NSButton *)sender {
  562. [KMLoginWindowsController.shared showWindow:nil];
  563. }
  564. #pragma mark - NSNotification Methods
  565. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  566. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  567. [self reloadData];
  568. });
  569. }
  570. - (void)IAPResultReceived:(NSNotification *)notification {
  571. dispatch_async(dispatch_get_main_queue(), ^{
  572. [self reloadData];
  573. });
  574. }
  575. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  576. dispatch_async(dispatch_get_main_queue(), ^{
  577. [self reloadData];
  578. });
  579. }
  580. - (void)IAPRestoreFinish:(NSNotification *)notification {
  581. dispatch_async(dispatch_get_main_queue(), ^{
  582. [self reloadData];
  583. });
  584. }
  585. #pragma mark - Event
  586. - (void)mouseEntered:(NSEvent *)event {
  587. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  588. ActivityStatusTrial == [VerificationManager manager].status) {
  589. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  590. if (!self.popover.isShown) {
  591. [self buttonAction:self.button];
  592. }
  593. }
  594. }
  595. - (void)mouseExited:(NSEvent *)event {
  596. [super mouseExited:event];
  597. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  598. }
  599. - (void)popoverDidClose:(NSNotification *)notification {
  600. self.stopPopOverHide = NO;
  601. }
  602. - (void)popoverShowNoti:(NSNotification *)noti {
  603. if (self.popover) {
  604. [self.popover close];
  605. self.stopPopOverHide = NO;
  606. }
  607. }
  608. - (void)loginSuccessNotification:(NSNotification *)noti {
  609. dispatch_async(dispatch_get_main_queue(), ^{
  610. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  611. [self reloadData];
  612. });
  613. }
  614. - (void)logoutSuccessNotification:(NSNotification *)noti {
  615. dispatch_async(dispatch_get_main_queue(), ^{
  616. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  617. [self reloadData];
  618. });
  619. }
  620. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  621. if (self.userMenu != nil) {
  622. [self personalCenterAction:_userButton];
  623. }
  624. }
  625. - (void)closeMenu:(NSNotification *)noti {
  626. if (self.userMenu != nil) {
  627. [self.userMenu cancelTracking];
  628. self.userMenu = nil;
  629. }
  630. }
  631. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  632. dispatch_async(dispatch_get_main_queue(), ^{
  633. [self reloadData];
  634. });
  635. }
  636. - (void)popOverCloseAction {
  637. if (self.stopPopOverHide == NO) {
  638. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  639. ActivityStatusTrial == [VerificationManager manager].status) {
  640. if (self.popover.isShown) {
  641. [self.popover close];
  642. self.stopPopOverHide = NO;
  643. }
  644. }
  645. }
  646. }
  647. @end