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.

50 lines
1.7KB

  1. @interface UIDateLabel : UILabel
  2. @property (nonatomic, strong) NSDate *date;
  3. @end
  4. @interface MessageListCellView : UIView
  5. @property (nonatomic, strong) UIDateLabel *dateLabel;
  6. @end
  7. static bool is24h;
  8. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
  9. static bool enabled;
  10. %hook MessageListCellView
  11. -(void)layoutSubviews{
  12. %orig;
  13. if(enabled){
  14. if(![self.dateLabel.text containsString:@":"]){
  15. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  16. if(is24h){
  17. [dateFormatter setDateFormat:@" • HH:mm"];
  18. }else{
  19. [dateFormatter setDateFormat:@" • h:mm a"];
  20. }
  21. self.dateLabel.textAlignment = 1;
  22. self.dateLabel.numberOfLines = 1;
  23. self.dateLabel.text = [self.dateLabel.text stringByAppendingString:[dateFormatter stringFromDate:self.dateLabel.date]];
  24. [self.dateLabel sizeToFit];
  25. //calling %orig again is not the best thing to do but the label was not positioned correctly after sizing it to fit the new string. If you feel like helping me with this, send a pull request!
  26. %orig;
  27. }
  28. }
  29. }
  30. %end
  31. %ctor{
  32. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  33. enabled = [[prefs objectForKey:@"mail"] boolValue];
  34. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  35. [formatter setLocale:[NSLocale currentLocale]];
  36. [formatter setDateStyle:NSDateFormatterNoStyle];
  37. [formatter setTimeStyle:NSDateFormatterShortStyle];
  38. NSString *dateString = [formatter stringFromDate:[NSDate date]];
  39. NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
  40. NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
  41. is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
  42. }