Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

166 rindas
6.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
  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. static bool is24h;
  20. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
  21. %group iOS10
  22. %hook NCLookHeaderContentView
  23. -(void)_updateDateLabelFontForShortLook{
  24. %orig;
  25. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  26. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  27. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  28. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  29. if((date != nil) && (format == 1)){
  30. NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel");
  31. int timeSinceNow = (int)[date timeIntervalSinceNow];
  32. timeSinceNow = timeSinceNow*-1;
  33. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  34. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  35. int hours = timeSinceNow / 3600;
  36. int minutes = (timeSinceNow % 3600) / 60;
  37. if(addMinutes){
  38. if(hours == 0){
  39. if(minutes == 0){
  40. }else{
  41. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  42. }
  43. }else{
  44. if(minutes == 0){
  45. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  46. } else{
  47. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  48. }
  49. }
  50. }else if(addToCurrent){
  51. if(hours == 0){
  52. if(minutes == 0){
  53. }else{
  54. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  55. }
  56. }else{
  57. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  58. }
  59. }
  60. if((timeSinceNow/60) >= affectTime){
  61. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  62. if(is24h){
  63. [dateFormatter setDateFormat:@"HH:mm"];
  64. }else{
  65. [dateFormatter setDateFormat:@"h:mm a"];
  66. }
  67. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  68. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  69. }else{
  70. dateLabel.text =[dateFormatter stringFromDate:date];
  71. }
  72. [dateLabel sizeToFit];
  73. [dateFormatter release];
  74. }
  75. }
  76. }
  77. -(void)dateLabelDidChange:(id)arg1{
  78. %orig(arg1);
  79. [self _updateDateLabelFontForShortLook];
  80. }
  81. %end
  82. %end
  83. %group iOS11
  84. %hook MTPlatterHeaderContentView
  85. -(void)_updateTextAttributesForDateLabel{
  86. %orig;
  87. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  88. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  89. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  90. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  91. if((date != nil) && (format == 1)){
  92. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  93. int timeSinceNow = (int)[date timeIntervalSinceNow];
  94. timeSinceNow = timeSinceNow*-1;
  95. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  96. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  97. int hours = timeSinceNow / 3600;
  98. int minutes = (timeSinceNow % 3600) / 60;
  99. if(addMinutes){
  100. if(hours == 0){
  101. if(minutes == 0){
  102. }else{
  103. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  104. }
  105. }else{
  106. if(minutes == 0){
  107. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  108. } else{
  109. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  110. }
  111. }
  112. }else if(addToCurrent){
  113. if(hours == 0){
  114. if(minutes == 0){
  115. }else{
  116. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  117. }
  118. }else{
  119. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  120. }
  121. }
  122. if((timeSinceNow/60) >= affectTime){
  123. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  124. if(is24h){
  125. [dateFormatter setDateFormat:@"HH:mm"];
  126. }else{
  127. [dateFormatter setDateFormat:@"h:mm a"];
  128. }
  129. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  130. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  131. }else{
  132. dateLabel.text =[dateFormatter stringFromDate:date];
  133. }
  134. [dateLabel sizeToFit];
  135. [dateFormatter release];
  136. }
  137. }
  138. }
  139. -(void)dateLabelDidChange:(id)arg1{
  140. %orig(arg1);
  141. [self _updateTextAttributesForDateLabel];
  142. }
  143. %end
  144. %end
  145. %ctor{
  146. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  147. [formatter setLocale:[NSLocale currentLocale]];
  148. [formatter setDateStyle:NSDateFormatterNoStyle];
  149. [formatter setTimeStyle:NSDateFormatterShortStyle];
  150. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  151. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  152. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  153. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  154. [formatter release];
  155. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 11.0) {
  156. %init(iOS10);
  157. } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 12.0) {
  158. %init(iOS11);
  159. }
  160. }