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.

47 lines
1.4KB

  1. @interface NCNotificationDateLabel
  2. @property (assign,nonatomic) NSString *text;
  3. -(void)sizeToFit;
  4. @end
  5. @interface NCLookHeaderContentView
  6. -(void)_updateDateLabelFontForShortLook;
  7. @end
  8. static bool is24h;
  9. %hook NCLookHeaderContentView
  10. -(void)_updateDateLabelFontForShortLook{
  11. %orig;
  12. NSDate *date = MSHookIvar<NSDate *>(self, "_date");
  13. NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
  14. if((date != nil) && (format == 1)){
  15. NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel");
  16. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  17. if(is24h)
  18. {
  19. [dateFormatter setDateFormat:@"HH:mm"];
  20. }else{
  21. [dateFormatter setDateFormat:@"hh:mm a"];
  22. }
  23. dateLabel.text = [dateFormatter stringFromDate:date];
  24. [dateLabel sizeToFit];
  25. [dateFormatter release];
  26. }
  27. }
  28. -(void)dateLabelDidChange:(id)arg1{
  29. %orig(arg1);
  30. [self _updateDateLabelFontForShortLook];
  31. }
  32. %end
  33. %ctor{
  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. [formatter release];
  43. }