Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

235 linhas
9.9KB

  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
  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
  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. timeSinceNow = timeSinceNow*-1;
  37. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  38. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  39. int hours = timeSinceNow / 3600;
  40. int minutes = (timeSinceNow % 3600) / 60;
  41. if(addMinutes){
  42. if(hours == 0){
  43. if(minutes == 0){
  44. }else{
  45. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  46. }
  47. }else{
  48. if(minutes == 0){
  49. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  50. } else{
  51. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  52. }
  53. }
  54. }else if(addToCurrent){
  55. if(hours == 0){
  56. if(minutes == 0){
  57. }else{
  58. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  59. }
  60. }else{
  61. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  62. }
  63. }
  64. if((timeSinceNow/60) >= affectTime){
  65. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  66. if(is24h){
  67. [dateFormatter setDateFormat:@"HH:mm"];
  68. }else{
  69. [dateFormatter setDateFormat:@"h:mm a"];
  70. }
  71. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  72. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  73. }else{
  74. dateLabel.text =[dateFormatter stringFromDate:date];
  75. }
  76. [dateLabel sizeToFit];
  77. [dateFormatter release];
  78. }
  79. }
  80. }
  81. -(void)dateLabelDidChange:(id)arg1{
  82. %orig(arg1);
  83. [self _updateDateLabelFontForShortLook];
  84. }
  85. %end
  86. %end
  87. %group iOS11
  88. %hook MTPlatterHeaderContentView
  89. -(void)_updateTextAttributesForDateLabel{
  90. %orig;
  91. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  92. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  93. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  94. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  95. if((date != nil) && (format == 1)){
  96. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  97. int timeSinceNow = (int)[date timeIntervalSinceNow];
  98. timeSinceNow = timeSinceNow*-1;
  99. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  100. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  101. int hours = timeSinceNow / 3600;
  102. int minutes = (timeSinceNow % 3600) / 60;
  103. if(addMinutes){
  104. if(hours == 0){
  105. if(minutes == 0){
  106. }else{
  107. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  108. }
  109. }else{
  110. if(minutes == 0){
  111. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  112. } else{
  113. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  114. }
  115. }
  116. }else if(addToCurrent){
  117. if(hours == 0){
  118. if(minutes == 0){
  119. }else{
  120. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  121. }
  122. }else{
  123. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  124. }
  125. }
  126. if((timeSinceNow/60) >= affectTime){
  127. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  128. if(is24h){
  129. [dateFormatter setDateFormat:@"HH:mm"];
  130. }else{
  131. [dateFormatter setDateFormat:@"h:mm a"];
  132. }
  133. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  134. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  135. }else{
  136. dateLabel.text =[dateFormatter stringFromDate:date];
  137. }
  138. [dateLabel sizeToFit];
  139. [dateFormatter release];
  140. }
  141. }
  142. }
  143. -(void)dateLabelDidChange:(id)arg1{
  144. %orig(arg1);
  145. [self _updateTextAttributesForDateLabel];
  146. }
  147. %end
  148. %end
  149. %group iOS12
  150. %hook PLPlatterHeaderContentView
  151. -(void)_updateTextAttributesForDateLabel{
  152. %orig;
  153. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  154. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  155. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  156. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  157. if((date != nil) && (format == 1)){
  158. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  159. int timeSinceNow = (int)[date timeIntervalSinceNow];
  160. timeSinceNow = timeSinceNow*-1;
  161. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  162. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  163. int hours = timeSinceNow / 3600;
  164. int minutes = (timeSinceNow % 3600) / 60;
  165. if(addMinutes){
  166. if(hours == 0){
  167. if(minutes == 0){
  168. }else{
  169. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  170. }
  171. }else{
  172. if(minutes == 0){
  173. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  174. } else{
  175. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  176. }
  177. }
  178. }else if(addToCurrent){
  179. if(hours == 0){
  180. if(minutes == 0){
  181. }else{
  182. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  183. }
  184. }else{
  185. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  186. }
  187. }
  188. if((timeSinceNow/60) >= affectTime){
  189. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  190. if(is24h){
  191. [dateFormatter setDateFormat:@"HH:mm"];
  192. }else{
  193. [dateFormatter setDateFormat:@"h:mm a"];
  194. }
  195. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  196. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  197. }else{
  198. dateLabel.text =[dateFormatter stringFromDate:date];
  199. }
  200. [dateLabel sizeToFit];
  201. [dateFormatter release];
  202. }
  203. }
  204. }
  205. -(void)dateLabelDidChange:(id)arg1{
  206. %orig(arg1);
  207. [self _updateTextAttributesForDateLabel];
  208. }
  209. %end
  210. %end
  211. %ctor{
  212. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  213. [formatter setLocale:[NSLocale currentLocale]];
  214. [formatter setDateStyle:NSDateFormatterNoStyle];
  215. [formatter setTimeStyle:NSDateFormatterShortStyle];
  216. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  217. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  218. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  219. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  220. [formatter release];
  221. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 11.0) {
  222. %init(iOS10);
  223. } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 12.0) {
  224. %init(iOS11);
  225. }else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 12.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 13.0) {
  226. %init(iOS12);
  227. }
  228. }