Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

311 lines
13KB

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