This commit is contained in:
2018-03-18 07:21:24 +02:00
committed by GitHub
parent 2fa8a407a9
commit 7baaa07fdb
3 changed files with 143 additions and 62 deletions

View File

@ -1,3 +1,4 @@
ARCHS = armv7 arm64 ARCHS = armv7 arm64
include $(THEOS)/makefiles/common.mk include $(THEOS)/makefiles/common.mk
@ -9,4 +10,4 @@ include $(THEOS_MAKE_PATH)/tweak.mk
after-install:: after-install::
install.exec "killall -9 SpringBoard" install.exec "killall -9 SpringBoard"
SUBPROJECTS += exacttimeprefs SUBPROJECTS += exacttimeprefs
include $(THEOS_MAKE_PATH)/aggregate.mk include $(THEOS)/makefiles/aggregate.mk

200
Tweak.xm
View File

@ -1,75 +1,150 @@
//IOS 10
@interface NCNotificationDateLabel @interface NCNotificationDateLabel
@property (assign,nonatomic) NSString *text; @property (assign,nonatomic) NSString *text;
-(void)sizeToFit; -(void)sizeToFit;
@end @end
//IOS 10
@interface NCLookHeaderContentView @interface NCLookHeaderContentView
-(void)_updateDateLabelFontForShortLook; -(void)_updateDateLabelFontForShortLook;
@end @end
//IOS 11
@interface BSUIRelativeDateLabel
@property (assign,nonatomic) NSString *text;
-(void)sizeToFit;
@end
//IOS 11
@interface MTPlatterHeaderContentView
-(void)_updateTextAttributesForDateLabel;
@end
static bool is24h; static bool is24h;
static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist"; static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist";
%group iOS10
%hook NCLookHeaderContentView
-(void)_updateDateLabelFontForShortLook{
%orig;
NSDate *date = MSHookIvar<NSDate *>(self, "_date");
NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
if((date != nil) && (format == 1)){
NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel");
int timeSinceNow = (int)[date timeIntervalSinceNow];
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{
dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
}
}else{
if(minutes == 0){
dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
} else{
dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
}
}
}else if(addToCurrent){
if(hours == 0){
if(minutes == 0){
}else{
dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
}
}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
%hook NCLookHeaderContentView %group iOS11
-(void)_updateDateLabelFontForShortLook{ %hook MTPlatterHeaderContentView
%orig; -(void)_updateTextAttributesForDateLabel{
NSDate *date = MSHookIvar<NSDate *>(self, "_date"); %orig;
NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle"); NSDate *date = MSHookIvar<NSDate *>(self, "_date");
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath]; NSInteger format = MSHookIvar<NSInteger >(self, "_dateFormatStyle");
CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue]; NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
if((date != nil) && (format == 1)){ CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue];
NCNotificationDateLabel *dateLabel = MSHookIvar<NCNotificationDateLabel *>(self, "_dateLabel"); if((date != nil) && (format == 1)){
int timeSinceNow = (int)[date timeIntervalSinceNow]; BSUIRelativeDateLabel *dateLabel = MSHookIvar<BSUIRelativeDateLabel *>(self, "_dateLabel");
timeSinceNow = timeSinceNow*-1; int timeSinceNow = (int)[date timeIntervalSinceNow];
bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue]; timeSinceNow = timeSinceNow*-1;
bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue]; bool addMinutes = [[prefs objectForKey:@"addMinutes"] boolValue];
int hours = timeSinceNow / 3600; bool addToCurrent = [[prefs objectForKey:@"addToCurrent"] boolValue];
int minutes = (timeSinceNow % 3600) / 60; int hours = timeSinceNow / 3600;
if(addMinutes){ int minutes = (timeSinceNow % 3600) / 60;
if(hours == 0){ if(addMinutes){
if(minutes == 0){ if(hours == 0){
}else{ if(minutes == 0){
dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes]; }else{
} dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
}else{ }
if(minutes == 0){ }else{
dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours]; if(minutes == 0){
} else{ dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes]; } else{
} dateLabel.text = [NSString stringWithFormat:@"%ih %im ago", hours, minutes];
} }
}else if(addToCurrent){ }
if(hours == 0){ }else if(addToCurrent){
if(minutes == 0){ if(hours == 0){
}else{ if(minutes == 0){
dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes]; }else{
} dateLabel.text = [NSString stringWithFormat:@"%im ago", minutes];
}else{ }
dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours]; }else{
} dateLabel.text = [NSString stringWithFormat:@"%ih ago", hours];
} }
if((timeSinceNow/60) >= affectTime){ }
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; if((timeSinceNow/60) >= affectTime){
if(is24h){ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"]; if(is24h){
}else{ [dateFormatter setDateFormat:@"HH:mm"];
[dateFormatter setDateFormat:@"h:mm a"]; }else{
} [dateFormatter setDateFormat:@"h:mm a"];
if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){ }
dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]]; if(addToCurrent && !([dateLabel.text isEqualToString:[dateFormatter stringFromDate:date]])){
}else{ dateLabel.text = [[dateLabel.text stringByAppendingString:@" • "] stringByAppendingString:[dateFormatter stringFromDate:date]];
dateLabel.text =[dateFormatter stringFromDate:date]; }else{
} dateLabel.text =[dateFormatter stringFromDate:date];
[dateLabel sizeToFit]; }
[dateFormatter release]; [dateLabel sizeToFit];
} [dateFormatter release];
} }
} }
-(void)dateLabelDidChange:(id)arg1{ }
%orig(arg1); -(void)dateLabelDidChange:(id)arg1{
[self _updateDateLabelFontForShortLook]; %orig(arg1);
} [self _updateTextAttributesForDateLabel];
}
%end
%end %end
%ctor{ %ctor{
@ -82,4 +157,9 @@ static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]]; NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound); is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
[formatter release]; [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);
}
} }

View File

@ -1,7 +1,7 @@
Package: com.gilshahar7.exacttime Package: com.gilshahar7.exacttime
Name: ExactTime Name: ExactTime
Depends: mobilesubstrate Depends: mobilesubstrate
Version: 1.3 Version: 1.4
Architecture: iphoneos-arm Architecture: iphoneos-arm
Description: Shows the exact time of a notification. Description: Shows the exact time of a notification.
Maintainer: gilshahar7 Maintainer: gilshahar7