KMVerificationMessageViewController.m 34 KB

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