KMVerificationMessageViewController.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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. // 远程按钮 最大宽度限制 100
  38. @property (nonatomic, assign) CGFloat remoteButtonMaxWidth;
  39. @end
  40. @implementation KMVerificationMessageViewController
  41. #pragma mark Init Methods
  42. - (instancetype)init {
  43. if (self = [super initWithNibName:@"KMVerificationMessageViewController" bundle:nil]) {
  44. self.remoteButtonMaxWidth = 200;
  45. #if VERSION_DMG
  46. [[NSNotificationCenter defaultCenter] addObserver:self
  47. selector:@selector(deviceActivateStatusChangeNotification:)
  48. name:kDeviceActivateStatusChangeNotification
  49. object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self
  51. selector:@selector(deviceActivateStatusChangeNotification:)
  52. name:KMIAPSubscriptionLoadedNotification
  53. object:nil];
  54. #else
  55. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPResultReceived:) name:KMIAPSubscriptionLoadedNotification object:nil];
  56. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPPurchaseSuccess:) name:KMIAPProductPurchasedNotification object:nil];
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(IAPRestoreFinish:) name:KMIAPProductRestoreFinishedNotification object:nil];
  58. #endif
  59. }
  60. return self;
  61. }
  62. - (void)dealloc {
  63. [[NSNotificationCenter defaultCenter] removeObserver:self];
  64. if (self.trackingArea) {
  65. [self.button removeTrackingArea:self.trackingArea];
  66. }
  67. }
  68. #pragma mark Setter Methods
  69. - (void)loadView {
  70. [super loadView];
  71. // Do view setup here.
  72. self.button.wantsLayer = YES;
  73. self.button.layer.masksToBounds = YES;
  74. self.button.layer.cornerRadius = 4.0;
  75. self.button.font = [NSFont SFProTextSemiboldFont:11];
  76. self.button.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  77. [self.button setAlignment:NSTextAlignmentCenter];
  78. self.userButton.font = [NSFont SFProTextSemiboldFont:11];
  79. self.secondTrialBtn.wantsLayer = YES;
  80. self.secondTrialBtn.layer.masksToBounds = YES;
  81. self.secondTrialBtn.layer.cornerRadius = 4.0;
  82. self.secondTrialBtn.font = [NSFont SFProTextSemiboldFont:11];
  83. self.secondTrialBtn.layer.backgroundColor = [NSColor colorWithDeviceRed:121.0/255.0 green:196.0/255.0 blue:66.0/255.0 alpha:1.0].CGColor;
  84. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  85. NSString *tTips = NSLocalizedString(@"Upgrade to Pro", nil);
  86. #if VERSION_DMG
  87. tTips = @"";
  88. #else
  89. tTips = [NSString stringWithFormat:@"%@", NSLocalizedString(@"Subscribe to All Access Pack to enjoy more expanded features.", nil)];
  90. #endif
  91. self.button.toolTip = tTips;
  92. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  93. [self.button setTitleColor:[NSColor whiteColor]];
  94. [self.button setAlignment:NSTextAlignmentCenter];
  95. self.secondTrialBtn.toolTip = tTips;
  96. self.secondTrialBtn.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  97. [self.secondTrialBtn setTitleColor:[NSColor whiteColor]];
  98. [self.secondTrialBtn setAlignment:NSTextAlignmentCenter];
  99. self.secondTrialBtn.hidden = YES;
  100. self.labelContentView.hidden = self.bgImg.hidden = self.button.hidden = NO;
  101. self.bgImg.wantsLayer = YES;
  102. self.bgImg.image = [NSImage imageNamed:@"Upgarde_bg_icon"];
  103. self.bgImg.layer.masksToBounds = YES;
  104. self.bgImg.layer.cornerRadius = 4.;
  105. self.bgImg.hidden = YES;
  106. self.aiLabel.font = [NSFont SFProTextSemiboldFont:11];
  107. self.aiLabel.textColor = [NSColor whiteColor];
  108. [self reloadData];
  109. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popoverShowNoti:) name:@"KMVerificationMessagePopShowNoti" object:nil];
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessNotification:) name:@"MemberCenterLoginSuccess" object:nil];
  111. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccessNotification:) name:@"MemberCenterLogoutSuccess" object:nil];
  112. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(expandPersonalCenterNotification:) name:@"ExpandPersonalCenter" object:nil];
  113. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeMenu:) name:@"CloseMenuNotification" object:nil];
  114. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberInfoChangeNotification:) name:KMMemberInfoChangeNotification object:nil];
  115. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionLoadedNotification:) name:KMIAPSubscriptionLoadedNotification object:nil];
  116. }
  117. // MARK: - Private Methods
  118. - (NSString *)_getAppStoreFreeVersionBuyNowTitle {
  119. return [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Purchase without Login", nil)];
  120. }
  121. // 是否定向跳转比较表
  122. - (BOOL)_isNowGotoPurcahseTable {
  123. #if VERSION_FREE
  124. #if VERSION_DMG
  125. return false;
  126. #else
  127. // AppStore 免费版 有特定需求
  128. // 无本机权益 true,否则 false
  129. return IAPProductsManager.defaultManager.isAvailableAllFunction == false;
  130. #endif
  131. #else
  132. return false;
  133. #endif
  134. }
  135. - (void)reloadData {
  136. self.label.textColor = [NSColor blackColor];
  137. self.label.hidden = NO;
  138. self.secondTrialBtn.hidden = YES;
  139. if (self.frameUpdateHandle) {
  140. self.frameUpdateHandle(self.view.frame);
  141. }
  142. CGFloat totalWidth = 8;
  143. self.button.hidden = NO;
  144. self.officeButton.hidden = NO;
  145. self.bgImg.hidden = NO;
  146. self.officeImg.hidden = NO;
  147. self.label.hidden = YES;
  148. self.secondTrialBtn.hidden = YES;
  149. self.labelContentView.hidden = YES;
  150. self.aiContendView.hidden = YES;
  151. self.userButton.hidden = YES;
  152. self.signUpView.hidden = YES;
  153. self.signUpLabel.stringValue = NSLocalizedStringFromTable(@"Sign in", @"MemberCenterLocalizable", nil);
  154. self.signUpLabel.font = [NSFont SFProTextSemiboldFont:11];
  155. [self.signUpLabel sizeToFit];
  156. CGFloat signUpWidth = self.signUpLabel.frame.size.width;
  157. signUpWidth += 4;
  158. signUpWidth += 8;
  159. signUpWidth += 8;
  160. signUpWidth += 12;
  161. self.signUpImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-6, 12, 12);
  162. CGRect signUplabelRect = self.signUpLabel.frame;
  163. signUplabelRect.origin.x = CGRectGetMaxX(self.signUpImg.frame) + 4;
  164. self.signUpLabel.frame = signUplabelRect;
  165. self.button.layer.backgroundColor = [NSColor clearColor].CGColor;
  166. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
  167. [self.button setTitleColor:[NSColor whiteColor]];
  168. self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
  169. self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office", nil)];
  170. [self.officeButton setTitleColor:[NSColor whiteColor]];
  171. self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
  172. [self.aiLabel sizeToFit];
  173. CGFloat aiWidth = self.aiLabel.frame.size.width;
  174. aiWidth += 4;
  175. aiWidth += 16;
  176. aiWidth += 16;
  177. self.aiIconImg.frame = CGRectMake(8, CGRectGetHeight(self.view.frame)/2.-8, 16, 16);
  178. self.aiContendView.frame = CGRectMake(totalWidth, 0, aiWidth, self.view.frame.size.height);
  179. CGRect ailabelRect = self.aiLabel.frame;
  180. ailabelRect.origin.x = CGRectGetMaxX(self.aiIconImg.frame) + 4;
  181. self.aiLabel.frame = ailabelRect;
  182. // totalWidth+=aiWidth;
  183. // totalWidth+=4;
  184. // self.aiContendView.hidden = NO;
  185. CGFloat userImageWidth = 24;
  186. if ([KMMemberInfo shared].isLogin) {
  187. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  188. } else {
  189. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  190. }
  191. CGFloat buttonWidth = CGRectGetMaxX(self.button.frame);
  192. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  193. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  194. buttonWidth = btnRect.size.width + 10;
  195. // buttonWidth += 10;
  196. // }
  197. CGFloat officeWidth = CGRectGetMaxX(self.officeButton.frame);
  198. NSRect officeRect = [self.officeButton.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.officeButton.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  199. if (fabs(officeWidth-officeRect.size.width)>50) {
  200. officeWidth = officeRect.size.width + 10;
  201. }
  202. #if VERSION_DMG
  203. self.button.hidden = YES;
  204. self.officeButton.hidden = YES;
  205. self.bgImg.hidden = YES;
  206. self.officeImg.hidden = YES;
  207. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  208. self.aiContendView.hidden = NO;
  209. totalWidth+=aiWidth;
  210. totalWidth+=4;
  211. }
  212. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  213. if (type == KMUserScenarioTypeDmg_type1 ||
  214. type == KMUserScenarioTypeDmg_type2 ||
  215. type == KMUserScenarioTypeDmg_type3 ||
  216. type == KMUserScenarioTypeDmg_type5 ||
  217. type == KMUserScenarioTypeDmg_type6 ||
  218. type == KMUserScenarioTypeDmg_type7 ||
  219. type == KMUserScenarioTypeDmg_type28 ||
  220. type == KMUserScenarioTypeDmg_type29 ||
  221. type == KMUserScenarioTypeDmg_type30 ||
  222. type == KMUserScenarioTypeDmg_type43 ||
  223. type == KMUserScenarioTypeDmg_type44 ||
  224. type == KMUserScenarioTypeDmg_type45) {
  225. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  226. } else if (type == KMUserScenarioTypeDmg_type4 ) {
  227. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  228. } else if (type == KMUserScenarioTypeDmg_type11 ||
  229. type == KMUserScenarioTypeDmg_type19 ||
  230. type == KMUserScenarioTypeDmg_type22 ||
  231. type == KMUserScenarioTypeDmg_type34 ||
  232. type == KMUserScenarioTypeDmg_type37 ) {
  233. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  234. } else if (type == KMUserScenarioTypeDmg_type18 ||
  235. type == KMUserScenarioTypeDmg_type33 ||
  236. type == KMUserScenarioTypeDmg_type48) {
  237. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  238. }
  239. if (type == KMUserScenarioTypeDmg_type2 ||
  240. type == KMUserScenarioTypeDmg_type19 ||
  241. type == KMUserScenarioTypeDmg_type20 ||
  242. type == KMUserScenarioTypeDmg_type21 ||
  243. type == KMUserScenarioTypeDmg_type22 ||
  244. type == KMUserScenarioTypeDmg_type30 ||
  245. type == KMUserScenarioTypeDmg_type31 ||
  246. type == KMUserScenarioTypeDmg_type32 ||
  247. type == KMUserScenarioTypeDmg_type33) {
  248. [self.officeButton setTitleColor:[NSColor whiteColor]];
  249. self.officeButton.hidden = NO;
  250. self.officeImg.hidden = NO;
  251. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  252. CGRect officeRect = self.officeButton.frame;
  253. self.officeImg.frame = officeRect;
  254. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  255. totalWidth+=4;
  256. }
  257. if (type == KMUserScenarioTypeDmg_type1 ||
  258. type == KMUserScenarioTypeDmg_type2 ||
  259. type == KMUserScenarioTypeDmg_type3 ||
  260. type == KMUserScenarioTypeDmg_type4 ||
  261. type == KMUserScenarioTypeDmg_type5 ||
  262. type == KMUserScenarioTypeDmg_type6 ||
  263. type == KMUserScenarioTypeDmg_type7 ||
  264. type == KMUserScenarioTypeDmg_type11 ||
  265. type == KMUserScenarioTypeDmg_type18 ||
  266. type == KMUserScenarioTypeDmg_type19 ||
  267. type == KMUserScenarioTypeDmg_type22 ||
  268. type == KMUserScenarioTypeDmg_type28 ||
  269. type == KMUserScenarioTypeDmg_type29 ||
  270. type == KMUserScenarioTypeDmg_type30 ||
  271. type == KMUserScenarioTypeDmg_type33 ||
  272. type == KMUserScenarioTypeDmg_type34 ||
  273. type == KMUserScenarioTypeDmg_type37 ||
  274. type == KMUserScenarioTypeDmg_type43 ||
  275. type == KMUserScenarioTypeDmg_type44 ||
  276. type == KMUserScenarioTypeDmg_type45 ||
  277. type == KMUserScenarioTypeDmg_type48) {
  278. [self.button setTitleColor:[NSColor whiteColor]];
  279. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  280. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  281. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  282. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  283. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  284. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  285. __weak typeof(self)weakSelf = self;
  286. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  287. if (image != nil) {
  288. weakSelf.bgImg.image = image;
  289. }
  290. }];
  291. }
  292. }
  293. self.bgImg.hidden = NO;
  294. self.button.hidden = NO;
  295. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  296. CGRect rect = self.button.frame;
  297. self.bgImg.frame = rect;
  298. totalWidth+=CGRectGetWidth(self.button.bounds);
  299. totalWidth+=4;
  300. }
  301. #else
  302. if ([[KMMemberInfo shared].isHaveAIDiscount isEqualToString:@"1"]) {
  303. #if VERSION_FREE
  304. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_lite.isTrialPeriod == false) {
  305. self.aiContendView.hidden = NO;
  306. totalWidth+=aiWidth;
  307. totalWidth+=4;
  308. }
  309. #else
  310. if(IAPProductsManager.defaultManager.aiAllAccessPack12month_pro.isTrialPeriod == false) {
  311. self.aiContendView.hidden = NO;
  312. totalWidth+=aiWidth;
  313. totalWidth+=4;
  314. }
  315. #endif
  316. }
  317. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  318. BOOL buttonHiddenFlag = false;
  319. if (type == KMUserScenarioTypeLite_type1 ||
  320. type == KMUserScenarioTypeLite_type3 ||
  321. type == KMUserScenarioTypeLite_type5 ||
  322. type == KMUserScenarioTypeLite_type7 ||
  323. type == KMUserScenarioTypeLite_type9 ||
  324. type == KMUserScenarioTypeLite_type11 ||
  325. type == KMUserScenarioTypePro_type1 ||
  326. type == KMUserScenarioTypePro_type3 ||
  327. type == KMUserScenarioTypePro_type4) {
  328. if (type == KMUserScenarioTypeLite_type1) { //免费用户
  329. #if !VERSION_DMG
  330. if(KMMemberInfo.shared.isLogin == NO) {
  331. #if VERSION_FREE
  332. if (IAPProductsManager.defaultManager.isAvailableAllFunction) {
  333. if (IAPProductsManager.defaultManager.isAvailableAdvancedPDFToOffice) {
  334. self.button.title = @"";
  335. buttonHiddenFlag = true;
  336. } else {
  337. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  338. }
  339. } else {
  340. self.button.title = [self _getAppStoreFreeVersionBuyNowTitle];
  341. }
  342. #else
  343. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  344. #endif
  345. } else {
  346. if(IAPProductsManager.defaultManager.fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == YES) { //是否有试用
  347. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  348. } else {
  349. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Free Trial", nil)];
  350. }
  351. }
  352. #else
  353. #endif
  354. } else if (type == KMUserScenarioTypeLite_type3 ) {
  355. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now", @"MemberCenterLocalizable", nil)];
  356. } else if (type == KMUserScenarioTypeLite_type5) {
  357. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  358. } else if (type == KMUserScenarioTypeLite_type7) {
  359. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now", @"MemberCenterLocalizable", nil)];
  360. } else if (type == KMUserScenarioTypeLite_type9) {
  361. if([KMMemberInfo shared].vip_status == 2) {
  362. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  363. } else if ([KMMemberInfo shared].vip_status == 4) {
  364. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Buy Now",@"MemberCenterLocalizable", nil)];
  365. } else {
  366. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  367. }
  368. } else if (type == KMUserScenarioTypeLite_type11) {
  369. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  370. } else if (type == KMUserScenarioTypePro_type3) {
  371. if([KMMemberInfo shared].vip_status == 2) {
  372. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
  373. } else {
  374. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
  375. }
  376. }
  377. #if !VERSION_FREE
  378. BOOL isNoSupportMemberUpgrade = YES;
  379. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  380. isNoSupportMemberUpgrade = NO;
  381. }
  382. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  383. [self.officeButton setTitleColor:[NSColor whiteColor]];
  384. self.officeButton.hidden = NO;
  385. self.officeImg.hidden = NO;
  386. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  387. CGRect officeRect = self.officeButton.frame;
  388. self.officeImg.frame = officeRect;
  389. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  390. totalWidth+=4;
  391. } else {
  392. self.officeButton.hidden = YES;
  393. self.officeImg.hidden = YES;
  394. }
  395. #else
  396. self.officeButton.hidden = YES;
  397. self.officeImg.hidden = YES;
  398. #endif
  399. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  400. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  401. KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject;
  402. NSString *name = [KMAdvertisementModelTransition transitionLanguageWithLangeuage:info.name];
  403. self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(name, nil)];
  404. NSURL *url = [NSURL URLWithString: [KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight: YES]];
  405. __weak typeof(self)weakSelf = self;
  406. NSImage * img = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage *image) {
  407. if (image != nil) {
  408. weakSelf.bgImg.image = image;
  409. }
  410. }];
  411. }
  412. }
  413. [self.button setTitleColor:[NSColor whiteColor]];
  414. self.bgImg.hidden = NO;
  415. self.button.hidden = NO;
  416. BOOL isOldSubscribed = NO;
  417. #if VERSION_FREE
  418. #if !VERSION_DMG
  419. isOldSubscribed = (IAPProductsManager.defaultManager.allAccessPack6months_lite.isSubscribed == YES || IAPProductsManager.defaultManager.allAccessPack12months_lite.isSubscribed == YES);
  420. #endif
  421. #endif
  422. // 单平台高级版永久 未登录时 也不显示升级(因为点了也得先登录),但是登录后的卡片里是有升级按钮的,可以升级成全平台高级版年订阅
  423. //原来是订阅的,不需要升级,因为目前不支持订阅升级订阅这种场景
  424. if(type == KMUserScenarioTypeLite_type9 ||
  425. type == KMUserScenarioTypeLite_type10 ||
  426. type == KMUserScenarioTypeLite_type11) {
  427. if([KMMemberInfo shared].isLogin == NO) { //未登录
  428. self.button.hidden = YES;
  429. self.bgImg.hidden = YES;
  430. } else {
  431. if(isOldSubscribed) { //老版本付费功能是订阅包
  432. self.button.hidden = YES;
  433. self.bgImg.hidden = YES;
  434. } else {
  435. if((KMMemberInfo.shared.vip_status == 1) && [KMMemberInfo.shared.vip_paymentModel isEqualToString:@"1"]) { //会员订阅中
  436. self.button.hidden = YES;
  437. self.bgImg.hidden = YES;
  438. }
  439. }
  440. }
  441. }
  442. #if VERSION_FREE
  443. #if !VERSION_DMG
  444. if (buttonHiddenFlag) {
  445. self.bgImg.hidden = YES;
  446. self.button.hidden = YES;
  447. }
  448. #endif
  449. #endif
  450. buttonWidth = CGRectGetWidth(self.button.frame);
  451. NSRect btnRect = [self.button.attributedTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, CGRectGetHeight(self.button.frame)) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
  452. // if (fabs(buttonWidth-btnRect.size.width)>50) {
  453. buttonWidth = btnRect.size.width + 10;
  454. // buttonWidth += 10;
  455. // }
  456. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  457. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  458. buttonWidth += 10;
  459. buttonWidth = MIN(buttonWidth, self.remoteButtonMaxWidth);
  460. }
  461. }
  462. self.button.frame = CGRectMake(totalWidth, kbottomGap, buttonWidth, self.view.frame.size.height -2 *kbottomGap);
  463. CGRect rect = self.button.frame;
  464. self.bgImg.frame = rect;
  465. totalWidth+=CGRectGetWidth(self.button.bounds);
  466. totalWidth+=4;
  467. } else if (type == KMUserScenarioTypeLite_type12 ||
  468. type == KMUserScenarioTypeLite_type13 ||
  469. type == KMUserScenarioTypeLite_type2 ||
  470. type == KMUserScenarioTypeLite_type4 ||
  471. type == KMUserScenarioTypeLite_type6 ||
  472. type == KMUserScenarioTypeLite_type8 ||
  473. type == KMUserScenarioTypePro_type2 ||
  474. type == KMUserScenarioTypePro_type5) {
  475. self.button.hidden = YES;
  476. self.bgImg.hidden = YES;
  477. #if !VERSION_FREE
  478. BOOL isNoSupportMemberUpgrade = YES;
  479. if ([KMMemberInfo shared].vip_status == 1) { //订阅+永久
  480. isNoSupportMemberUpgrade = NO;
  481. }
  482. if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice && isNoSupportMemberUpgrade) {
  483. [self.officeButton setTitleColor:[NSColor whiteColor]];
  484. self.officeButton.hidden = NO;
  485. self.officeImg.hidden = NO;
  486. self.officeButton.frame = CGRectMake(totalWidth, kbottomGap, officeWidth, self.view.frame.size.height -2 *kbottomGap);
  487. CGRect officeRect = self.officeButton.frame;
  488. self.officeImg.frame = officeRect;
  489. totalWidth+=CGRectGetWidth(self.officeButton.bounds);
  490. totalWidth+=4;
  491. } else {
  492. self.officeButton.hidden = YES;
  493. self.officeImg.hidden = YES;
  494. }
  495. #else
  496. self.officeButton.hidden = YES;
  497. self.officeImg.hidden = YES;
  498. #endif
  499. }
  500. #endif
  501. if ([KMMemberInfo shared].isLogin) {
  502. self.userButton.hidden = NO;
  503. self.userButton.frame = CGRectMake(totalWidth, 0, userImageWidth, userImageWidth);
  504. totalWidth += userImageWidth;
  505. totalWidth += 8;
  506. } else {
  507. self.signUpView.hidden = NO;
  508. self.signUpView.frame = CGRectMake(totalWidth, 0, signUpWidth, self.view.frame.size.height);
  509. totalWidth+=CGRectGetWidth(self.signUpView.bounds);
  510. }
  511. 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);
  512. }
  513. #pragma mark - Button Actions
  514. - (IBAction)secondTrialAction:(NSButton *)sender {
  515. if ([VerificationManager manager].secondTrialEnabled) {
  516. KMVerificationWindowController *vc = [KMVerificationWindowController verificationWithType:KMVerificationTypeRepeatTrialGuide];
  517. [vc showWindow:nil];
  518. } else {
  519. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  520. }
  521. }
  522. - (IBAction)buttonAction:(id)sender {
  523. if (KMAdvertisementManager.manager.info.topRightInfoContent != nil) {
  524. if (KMAdvertisementManager.manager.info.topRightInfoContent.content.firstObject != nil) {
  525. #if VERSION_FREE
  526. #if VERSION_DMG
  527. #else
  528. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Sale"}];
  529. #endif
  530. #endif
  531. if ([KMMemberInfo shared].isLogin) {
  532. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  533. [[KMProductCompareWC shared] setOrientation:YES];
  534. #if VERSION_FREE
  535. #if VERSION_DMG
  536. // DMG
  537. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  538. #else
  539. // AppStore 免费版本
  540. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  541. #endif
  542. #else
  543. // AppStore 付费版
  544. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  545. #endif
  546. [[KMProductCompareWC shared] showWindow:nil];
  547. } else {
  548. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  549. }
  550. } else {
  551. if ([self _isNowGotoPurcahseTable]) {
  552. KMProductCompareWC *winC = [KMProductCompareWC shared];
  553. // 定向跳转
  554. winC.orientation = true;
  555. // App Store 免费版 基础比较表
  556. winC.orientationType = KMCompareTableTypeLite_Base;
  557. [winC showWindow:nil];
  558. } else {
  559. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  560. if (success) {
  561. if ([[KMMemberInfo shared].vip_levels isEqualToString:@"1"]) {
  562. [[KMProductCompareWC shared] setOrientation:YES];
  563. #if VERSION_FREE
  564. #if VERSION_DMG
  565. // DMG
  566. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeDmg_Base];
  567. #else
  568. // AppStore 免费版本
  569. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeLite_Base];
  570. #endif
  571. #else
  572. // AppStore 付费版
  573. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypePro_Base];
  574. #endif
  575. [[KMProductCompareWC shared] showWindow:nil];
  576. } else {
  577. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeNone];
  578. }
  579. }
  580. }];
  581. }
  582. }
  583. } else {
  584. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  585. if (type == KMUserScenarioTypeDmg_type4) {
  586. if ([KMMemberInfo shared].isLogin) {
  587. [[KMProductCompareWC shared] setOrientation:YES];
  588. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  589. [[KMProductCompareWC shared] showWindow:nil];
  590. } else {
  591. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  592. if (success) {
  593. [[KMProductCompareWC shared] setOrientation:YES];
  594. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  595. [[KMProductCompareWC shared] showWindow:nil];
  596. }
  597. }];
  598. }
  599. } else {
  600. if ([self _isNowGotoPurcahseTable]) {
  601. #if VERSION_FREE
  602. #if VERSION_DMG
  603. #else
  604. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_PurchasewithoutLogin"}];
  605. #endif
  606. #endif
  607. KMProductCompareWC *winC = [KMProductCompareWC shared];
  608. // 定向跳转
  609. winC.orientation = true;
  610. // App Store 免费版 基础比较表
  611. winC.orientationType = KMCompareTableTypeLite_Base;
  612. [winC showWindow:nil];
  613. } else {
  614. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  615. }
  616. }
  617. }
  618. } else {
  619. KMUserScenarioType type = [KMMemberInfo shared].userScenarioType;
  620. if (type == KMUserScenarioTypeDmg_type4) {
  621. if ([KMMemberInfo shared].isLogin) {
  622. [[KMProductCompareWC shared] setOrientation:YES];
  623. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  624. [[KMProductCompareWC shared] showWindow:nil];
  625. } else {
  626. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  627. if (success) {
  628. [[KMProductCompareWC shared] setOrientation:YES];
  629. [[KMProductCompareWC shared] setOrientationType:KMCompareTableTypeTrial];
  630. [[KMProductCompareWC shared] showWindow:nil];
  631. }
  632. }];
  633. }
  634. } else {
  635. if ([self _isNowGotoPurcahseTable]) {
  636. #if VERSION_FREE
  637. #if VERSION_DMG
  638. #else
  639. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_PurchasewithoutLogin"}];
  640. #endif
  641. #endif
  642. KMProductCompareWC *winC = [KMProductCompareWC shared];
  643. // 定向跳转
  644. winC.orientation = true;
  645. // App Store 免费版 基础比较表
  646. winC.orientationType = KMCompareTableTypeLite_Base;
  647. [winC showWindow:nil];
  648. } else {
  649. [[KMMemberInfo shared] advancedFunctionUsageWithType:KMSubscribeWaterMarkTypeInvalid];
  650. }
  651. }
  652. }
  653. }
  654. - (IBAction)officeButtonAction:(id)sender {
  655. #if VERSION_FREE
  656. #if VERSION_DMG
  657. DMGEmbeddedOldWC *embeddedWC = [DMGEmbeddedOldWC currentFirstTrialWC:@"com.brother.pdfreaderpro.mac.product_2"];
  658. [embeddedWC showWindow:nil];
  659. [embeddedWC.window center];
  660. #endif
  661. #else
  662. if ([KMMemberInfo shared].isLogin) {
  663. [[KMMemberInfo shared] productCompareShow];
  664. } else {
  665. [[KMLoginWindowsController shared] openWindow:^(BOOL success) {
  666. if (success) {
  667. [[KMMemberInfo shared] productCompareShow];
  668. }
  669. }];
  670. }
  671. #endif
  672. }
  673. - (NSAttributedString *)numberConvertColor:(NSColor*)color String:(NSString *)string {
  674. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
  675. NSString *temp = nil;
  676. for (NSUInteger i = 0; i <string.length; i++) {
  677. temp = [string substringWithRange:NSMakeRange(i, 1)];
  678. if ([self isPureInt:temp]) {
  679. [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
  680. color, NSForegroundColorAttributeName, nil] range:NSMakeRange(i, 1)];
  681. }
  682. }
  683. return attributedString;
  684. }
  685. - (BOOL)isPureInt:(NSString *)string {
  686. NSScanner *scan = [NSScanner scannerWithString:string];
  687. int value;
  688. return [scan scanInt:&value] && [scan isAtEnd];
  689. }
  690. - (IBAction)AIButtonAction:(NSButton *)sender {
  691. if ([[[KMMemberInfo shared] validFlag] isEqualToString:@"5"]) {
  692. [[KMMemberPromptWC shared] showWindow:sender];
  693. [KMMemberPromptWC shared].tipType = KMMemberTipTypeSignouting;
  694. } else {
  695. #if VERSION_FREE
  696. #if VERSION_DMG
  697. KMPurchaseEmbeddedWindowController *winC = [KMPurchaseEmbeddedWindowController currentCode:KMAISubscriptionYearTrailCodeKey_DMG];
  698. [winC showWindow:nil];
  699. [winC.window center];
  700. #else
  701. [[KMFreeGetAIWC shared] showWindow:nil];
  702. #endif
  703. #else
  704. [[KMFreeGetAIWC shared] showWindow:nil];
  705. #endif
  706. }
  707. }
  708. - (IBAction)userButtonAction:(NSButton *)sender {
  709. if ([KMMemberInfo shared].isLogin) {
  710. [self personalCenterAction:sender];
  711. } else {
  712. [KMLoginWindowsController.shared showWindow:nil];
  713. }
  714. }
  715. - (IBAction)personalCenterAction:(NSButton *)sender {
  716. if (![KMCloudServer isConnectionAvailable]) {
  717. NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Connection Error", nil)
  718. defaultButton:NSLocalizedString(@"OK", nil)
  719. alternateButton:nil
  720. otherButton:nil
  721. informativeTextWithFormat:NSLocalizedString(@"Please make sure your internet connection is available.", nil), nil];
  722. [alert runModal];
  723. return;
  724. }
  725. // 用户头像点击事件
  726. self.userMenu = [[NSMenu alloc] init];
  727. KMUserInfoViewController *userInfo = [[KMUserInfoViewController alloc] init];
  728. NSMenuItem *item = [self.userMenu addItemWithTitle:@"" action:nil target:@""];
  729. item.target = self;
  730. item.representedObject = userInfo;
  731. item.view = userInfo.view;
  732. [self.userMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(-130, 30) inView:sender];
  733. }
  734. - (IBAction)signUpAction:(NSButton *)sender {
  735. #if VERSION_FREE
  736. #if VERSION_DMG
  737. #else
  738. [FMTrackEventManager.defaultManager trackEventWithEvent:@"Tbr" withProperties:@{@"Tbr_Btn" : @"Btn_Tbr_Login"}];
  739. #endif
  740. #endif
  741. [KMLoginWindowsController.shared showWindow:nil];
  742. }
  743. #pragma mark - NSNotification Methods
  744. - (void)deviceActivateStatusChangeNotification:(NSNotification *)notification {
  745. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  746. [self reloadData];
  747. });
  748. }
  749. - (void)IAPResultReceived:(NSNotification *)notification {
  750. dispatch_async(dispatch_get_main_queue(), ^{
  751. [self reloadData];
  752. });
  753. }
  754. - (void)IAPPurchaseSuccess:(NSNotification *)notification {
  755. dispatch_async(dispatch_get_main_queue(), ^{
  756. [self reloadData];
  757. #if VERSION_FREE
  758. #if VERSION_DMG
  759. #else
  760. [[KMProductCompareWC shared] closeAction];
  761. #endif
  762. #endif
  763. });
  764. }
  765. - (void)IAPRestoreFinish:(NSNotification *)notification {
  766. dispatch_async(dispatch_get_main_queue(), ^{
  767. [self reloadData];
  768. });
  769. }
  770. #pragma mark - Event
  771. - (void)mouseEntered:(NSEvent *)event {
  772. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  773. ActivityStatusTrial == [VerificationManager manager].status) {
  774. [[self class] cancelPreviousPerformRequestsWithTarget:self];
  775. if (!self.popover.isShown) {
  776. [self buttonAction:self.button];
  777. }
  778. }
  779. }
  780. - (void)mouseExited:(NSEvent *)event {
  781. [super mouseExited:event];
  782. [self performSelector:@selector(popOverCloseAction) withObject:nil afterDelay:0.35];
  783. }
  784. - (void)popoverDidClose:(NSNotification *)notification {
  785. self.stopPopOverHide = NO;
  786. }
  787. - (void)popoverShowNoti:(NSNotification *)noti {
  788. if (self.popover) {
  789. [self.popover close];
  790. self.stopPopOverHide = NO;
  791. }
  792. }
  793. - (void)loginSuccessNotification:(NSNotification *)noti {
  794. dispatch_async(dispatch_get_main_queue(), ^{
  795. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture"];
  796. [self reloadData];
  797. });
  798. }
  799. - (void)logoutSuccessNotification:(NSNotification *)noti {
  800. dispatch_async(dispatch_get_main_queue(), ^{
  801. self.userButton.image = [NSImage imageNamed:@"UserProfilePicture1"];
  802. [self reloadData];
  803. });
  804. }
  805. - (void)expandPersonalCenterNotification:(NSNotification *)noti {
  806. if (self.userMenu != nil) {
  807. [self personalCenterAction:_userButton];
  808. }
  809. }
  810. - (void)closeMenu:(NSNotification *)noti {
  811. if (self.userMenu != nil) {
  812. [self.userMenu cancelTracking];
  813. self.userMenu = nil;
  814. }
  815. }
  816. - (void)subscriptionLoadedNotification:(NSNotification *)noti {
  817. dispatch_async(dispatch_get_main_queue(), ^{
  818. [self reloadData];
  819. });
  820. }
  821. - (void)memberInfoChangeNotification:(NSNotification *)noti {
  822. dispatch_async(dispatch_get_main_queue(), ^{
  823. [self reloadData];
  824. });
  825. }
  826. - (void)popOverCloseAction {
  827. if (self.stopPopOverHide == NO) {
  828. if (ActivityStatusTrialExpire == [VerificationManager manager].status ||
  829. ActivityStatusTrial == [VerificationManager manager].status) {
  830. if (self.popover.isShown) {
  831. [self.popover close];
  832. self.stopPopOverHide = NO;
  833. }
  834. }
  835. }
  836. }
  837. @end