|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- //IOS 10
- @interface NCNotificationDateLabel
- @property (assign,nonatomic) NSString *text;
- -(void)sizeToFit;
- @end
- //IOS 10
- @interface NCLookHeaderContentView
- -(void)_updateDateLabelFontForShortLook;
- @end
- //IOS 11 & 12 And Above
- @interface BSUIRelativeDateLabel
- @property (assign,nonatomic) NSString *text;
- -(void)sizeToFit;
- @end
- //IOS 11
- @interface MTPlatterHeaderContentView
- -(void)_updateTextAttributesForDateLabel;
- @end
- //IOS 12 And Above
- @interface PLPlatterHeaderContentView
- -(void)_updateTextAttributesForDateLabel;
- @end
-
-
-
- static bool is24h;
- static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
-
- %group iOS10
- %hook NCLookHeaderContentView
- -(void)_updateDateLabelFontForShortLook{
- %orig;
- NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
- bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
- if(enabled){
- NSDate *date = MSHookIvar<NSDate *>(self, "_date");
- NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
- CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
- if((date != nil) && (format == 1)){
- NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel");
- int timeSinceNow = (int)[date timeIntervalSinceNow];
- bool isFuture = false;
- if (timeSinceNow > 0){
- isFuture = true;
- }else{
- timeSinceNow = timeSinceNow*-1;
- }
- bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
- bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
- int hours = timeSinceNow / 3600;
- int minutes = (timeSinceNow % 3600) / 60;
- if(addMinutes){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(minutes == 0){
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- } else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
- }
- }
- }
- }else if(addToCurrent){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- }
- }
- if((timeSinceNow/60) >= affectTime){
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- if(is24h){
- [dateFormatter setDateFormat:@"HH:mm"];
- }else{
- [dateFormatter setDateFormat:@"h:mm a"];
- }
- if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
- dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
- }else{
- dateLabel.text =[dateFormatter stringFromDate:date];
- }
- [dateLabel sizeToFit];
- [dateFormatter release];
- }
- }
- }
- }
- -(void)dateLabelDidChange:(id)arg1{
- %orig(arg1);
- [self _updateDateLabelFontForShortLook];
- }
- %end
- %end
-
- %group iOS11
- %hook MTPlatterHeaderContentView
- -(void)_updateTextAttributesForDateLabel{
- %orig;
- NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
- bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
- if(enabled){
- NSDate *date = MSHookIvar<NSDate *>(self, "_date");
- NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
- CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
- if((date != nil) && (format == 1)){
- BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
- int timeSinceNow = (int)[date timeIntervalSinceNow];
- bool isFuture = false;
- if (timeSinceNow > 0){
- isFuture = true;
- }else{
- timeSinceNow = timeSinceNow*-1;
- }
- bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
- bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
- int hours = timeSinceNow / 3600;
- int minutes = (timeSinceNow % 3600) / 60;
- if(addMinutes){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(minutes == 0){
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- } else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
- }
- }
- }
- }else if(addToCurrent){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- }
- }
- if((timeSinceNow/60) >= affectTime){
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- if(is24h){
- [dateFormatter setDateFormat:@"HH:mm"];
- }else{
- [dateFormatter setDateFormat:@"h:mm a"];
- }
- if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
- dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
- }else{
- dateLabel.text =[dateFormatter stringFromDate:date];
- }
- [dateLabel sizeToFit];
- [dateFormatter release];
- }
- }
- }
- }
- -(void)dateLabelDidChange:(id)arg1{
- %orig(arg1);
- [self _updateTextAttributesForDateLabel];
- }
- %end
- %end
-
- %group iOS12AndAbove
- %hook PLPlatterHeaderContentView
- -(void)_updateTextAttributesForDateLabel{
- %orig;
- NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
- bool enabled = [[prefs objectForKey:@"notifications"] boolValue];
- if(enabled){
- NSDate *date = MSHookIvar<NSDate *>(self, "_date");
- NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
- CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
- if((date != nil) && (format == 1)){
- BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
- int timeSinceNow = (int)[date timeIntervalSinceNow];
- bool isFuture = false;
- if (timeSinceNow > 0){
- isFuture = true;
- }else{
- timeSinceNow = timeSinceNow*-1;
- }
- bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
- bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
- int hours = timeSinceNow / 3600;
- int minutes = (timeSinceNow % 3600) / 60;
- if(addMinutes){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(minutes == 0){
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- } else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih %im", hours, minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
- }
- }
- }
- }else if(addToCurrent){
- if(hours == 0){
- if(minutes == 0){
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %im", minutes];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
- }
- }
- }else{
- if(isFuture){
- dateLabel.text = [NSString stringWithFormat:@"in %ih", hours];
- }else{
- dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
- }
- }
- }
- if((timeSinceNow/60) >= affectTime){
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- if(is24h){
- [dateFormatter setDateFormat:@"HH:mm"];
- }else{
- [dateFormatter setDateFormat:@"h:mm a"];
- }
- if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
- dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
- }else{
- dateLabel.text =[dateFormatter stringFromDate:date];
- }
- [dateLabel sizeToFit];
- [dateFormatter release];
- }
- }
- }
- }
- -(void)dateLabelDidChange:(id)arg1{
- %orig(arg1);
- [self _updateTextAttributesForDateLabel];
- }
- %end
- %end
-
- %ctor{
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setLocale:[NSLocale currentLocale]];
- [formatter setDateStyle:NSDateFormatterNoStyle];
- [formatter setTimeStyle:NSDateFormatterShortStyle];
- NSString *dateString = [formatter stringFromDate:[NSDate date]];
- NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
- NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
- is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
- [formatter release];
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 11.0) {
- %init(iOS10);
- } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 12.0) {
- %init(iOS11);
- }else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 12.0) {
- %init(iOS12AndAbove);
- }
- }
|