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.

86 lines
2.9KB

  1. @interface BSUIRelativeDateLabel
  2. @property (assign,nonatomic) NSString *text;
  3. -(void)sizeToFit;
  4. @end
  5. @interface MTPlatterHeaderContentView
  6. -(void)_updateTextAttributesForDateLabel;
  7. @end
  8. static bool is24h;
  9. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
  10. %hook MTPlatterHeaderContentView
  11. -(void)_updateTextAttributesForDateLabel{
  12. %orig;
  13. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  14. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  15. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  16. CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
  17. if((date != nil) && (format == 1)){
  18. BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
  19. int timeSinceNow = (int)[date timeIntervalSinceNow];
  20. timeSinceNow = timeSinceNow*-1;
  21. bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
  22. bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
  23. int hours = timeSinceNow / 3600;
  24. int minutes = (timeSinceNow % 3600) / 60;
  25. if(addMinutes){
  26. if(hours == 0){
  27. if(minutes == 0){
  28. }else{
  29. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  30. }
  31. }else{
  32. if(minutes == 0){
  33. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  34. } else{
  35. dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
  36. }
  37. }
  38. }else if(addToCurrent){
  39. if(hours == 0){
  40. if(minutes == 0){
  41. }else{
  42. dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
  43. }
  44. }else{
  45. dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
  46. }
  47. }
  48. if((timeSinceNow/60) >= affectTime){
  49. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  50. if(is24h){
  51. [dateFormatter setDateFormat:@"HH:mm"];
  52. }else{
  53. [dateFormatter setDateFormat:@"h:mm a"];
  54. }
  55. if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
  56. dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
  57. }else{
  58. dateLabel.text =[dateFormatter stringFromDate:date];
  59. }
  60. [dateLabel sizeToFit];
  61. [dateFormatter release];
  62. }
  63. }
  64. }
  65. -(void)dateLabelDidChange:(id)arg1{
  66. %orig(arg1);
  67. [self _updateTextAttributesForDateLabel];
  68. }
  69. %end
  70. %ctor{
  71. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  72. [formatter setLocale:[NSLocale currentLocale]];
  73. [formatter setDateStyle:NSDateFormatterNoStyle];
  74. [formatter setTimeStyle:NSDateFormatterShortStyle];
  75. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  76. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  77. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  78. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  79. [formatter release];
  80. }