You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
11KB

  1. //IOS 10
  2. @interface NCNotificationDateLabel
  3. @property (assign,nonatomic) NSString *text;
  4. -(void)sizeToFit;
  5. @end
  6. //IOS 10
  7. @interface NCLookHeaderContentView
  8. -(void)_updateDateLabelFontForShortLook;
  9. @end
  10. //IOS 11 & 12 And Above
  11. @interface BSUIRelativeDateLabel
  12. @property (assign,nonatomic) NSString *text;
  13. -(void)sizeToFit;
  14. @end
  15. //IOS 11
  16. @interface MTPlatterHeaderContentView
  17. -(void)_updateTextAttributesForDateLabel;
  18. @end
  19. //IOS 12 And Above
  20. @interface PLPlatterHeaderContentView
  21. -(void)_updateTextAttributesForDateLabel;
  22. @end
  23. static bool is24h;
  24. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
  25. %group iOS10
  26. %hook NCLookHeaderContentView
  27. -(void)_updateDateLabelFontForShortLook{
  28. %orig;
  29. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  30. bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
  31. if(enabled){
  32. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  33. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  34. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  35. if((date != nil) && (format == 1)){
  36. NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel");
  37. int timeSinceNow = (int)[date timeIntervalSinceNow];
  38. bool isFuture = false;
  39. if (timeSinceNow > 0){
  40. isFuture = true;
  41. }else{
  42. timeSinceNow = timeSinceNow*-1;
  43. }
  44. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  45. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  46. int hours = timeSinceNow / 3600;
  47. int minutes = (timeSinceNow % 3600) / 60;
  48. if(addMinutes){
  49. if(hours == 0){
  50. if(minutes == 0){
  51. }else{
  52. if(isFuture){
  53. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  54. }else{
  55. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  56. }
  57. }
  58. }else{
  59. if(minutes == 0){
  60. if(isFuture){
  61. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  62. }else{
  63. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  64. }
  65. } else{
  66. if(isFuture){
  67. dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
  68. }else{
  69. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  70. }
  71. }
  72. }
  73. }else if(addToCurrent){
  74. if(hours == 0){
  75. if(minutes == 0){
  76. }else{
  77. if(isFuture){
  78. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  79. }else{
  80. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  81. }
  82. }
  83. }else{
  84. if(isFuture){
  85. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  86. }else{
  87. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  88. }
  89. }
  90. }
  91. if((timeSinceNow/60) >= affectTime){
  92. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  93. if(is24h){
  94. [dateFormatter setDateFormat:@"HH:mm"];
  95. }else{
  96. [dateFormatter setDateFormat:@"h:mm a"];
  97. }
  98. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  99. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  100. }else{
  101. dateLabel.text =[dateFormatter stringFromDate:date];
  102. }
  103. [dateLabel sizeToFit];
  104. [dateFormatter release];
  105. }
  106. }
  107. }
  108. }
  109. -(void)dateLabelDidChange:(id)arg1{
  110. %orig(arg1);
  111. [self _updateDateLabelFontForShortLook];
  112. }
  113. %end
  114. %end
  115. %group iOS11
  116. %hook MTPlatterHeaderContentView
  117. -(void)_updateTextAttributesForDateLabel{
  118. %orig;
  119. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  120. bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
  121. if(enabled){
  122. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  123. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  124. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  125. if((date != nil) && (format == 1)){
  126. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  127. int timeSinceNow = (int)[date timeIntervalSinceNow];
  128. bool isFuture = false;
  129. if (timeSinceNow > 0){
  130. isFuture = true;
  131. }else{
  132. timeSinceNow = timeSinceNow*-1;
  133. }
  134. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  135. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  136. int hours = timeSinceNow / 3600;
  137. int minutes = (timeSinceNow % 3600) / 60;
  138. if(addMinutes){
  139. if(hours == 0){
  140. if(minutes == 0){
  141. }else{
  142. if(isFuture){
  143. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  144. }else{
  145. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  146. }
  147. }
  148. }else{
  149. if(minutes == 0){
  150. if(isFuture){
  151. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  152. }else{
  153. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  154. }
  155. } else{
  156. if(isFuture){
  157. dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
  158. }else{
  159. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  160. }
  161. }
  162. }
  163. }else if(addToCurrent){
  164. if(hours == 0){
  165. if(minutes == 0){
  166. }else{
  167. if(isFuture){
  168. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  169. }else{
  170. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  171. }
  172. }
  173. }else{
  174. if(isFuture){
  175. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  176. }else{
  177. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  178. }
  179. }
  180. }
  181. if((timeSinceNow/60) >= affectTime){
  182. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  183. if(is24h){
  184. [dateFormatter setDateFormat:@"HH:mm"];
  185. }else{
  186. [dateFormatter setDateFormat:@"h:mm a"];
  187. }
  188. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  189. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  190. }else{
  191. dateLabel.text =[dateFormatter stringFromDate:date];
  192. }
  193. [dateLabel sizeToFit];
  194. [dateFormatter release];
  195. }
  196. }
  197. }
  198. }
  199. -(void)dateLabelDidChange:(id)arg1{
  200. %orig(arg1);
  201. [self _updateTextAttributesForDateLabel];
  202. }
  203. %end
  204. %end
  205. %group iOS12AndAbove
  206. %hook PLPlatterHeaderContentView
  207. -(void)_updateTextAttributesForDateLabel{
  208. %orig;
  209. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  210. bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
  211. if(enabled){
  212. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  213. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  214. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  215. if((date != nil) && (format == 1)){
  216. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  217. int timeSinceNow = (int)[date timeIntervalSinceNow];
  218. bool isFuture = false;
  219. if (timeSinceNow > 0){
  220. isFuture = true;
  221. }else{
  222. timeSinceNow = timeSinceNow*-1;
  223. }
  224. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  225. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  226. int hours = timeSinceNow / 3600;
  227. int minutes = (timeSinceNow % 3600) / 60;
  228. if(addMinutes){
  229. if(hours == 0){
  230. if(minutes == 0){
  231. }else{
  232. if(isFuture){
  233. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  234. }else{
  235. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  236. }
  237. }
  238. }else{
  239. if(minutes == 0){
  240. if(isFuture){
  241. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  242. }else{
  243. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  244. }
  245. } else{
  246. if(isFuture){
  247. dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
  248. }else{
  249. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  250. }
  251. }
  252. }
  253. }else if(addToCurrent){
  254. if(hours == 0){
  255. if(minutes == 0){
  256. }else{
  257. if(isFuture){
  258. dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
  259. }else{
  260. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  261. }
  262. }
  263. }else{
  264. if(isFuture){
  265. dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
  266. }else{
  267. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  268. }
  269. }
  270. }
  271. if((timeSinceNow/60) >= affectTime){
  272. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  273. if(is24h){
  274. [dateFormatter setDateFormat:@"HH:mm"];
  275. }else{
  276. [dateFormatter setDateFormat:@"h:mm a"];
  277. }
  278. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  279. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  280. }else{
  281. dateLabel.text =[dateFormatter stringFromDate:date];
  282. }
  283. [dateLabel sizeToFit];
  284. [dateFormatter release];
  285. }
  286. }
  287. }
  288. }
  289. -(void)dateLabelDidChange:(id)arg1{
  290. %orig(arg1);
  291. [self _updateTextAttributesForDateLabel];
  292. }
  293. %end
  294. %end
  295. %ctor{
  296. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  297. [formatter setLocale:[NSLocale currentLocale]];
  298. [formatter setDateStyle:NSDateFormatterNoStyle];
  299. [formatter setTimeStyle:NSDateFormatterShortStyle];
  300. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  301. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  302. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  303. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  304. [formatter release];
  305. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 11.0) {
  306. %init(iOS10);
  307. } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 12.0) {
  308. %init(iOS11);
  309. }else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 12.0) {
  310. %init(iOS12AndAbove);
  311. }
  312. }