diff --git a/Makefile b/Makefile index 55c9f08..87d32e9 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,5 @@ include $(THEOS_MAKE_PATH)/tweak.mk after-install:: install.exec "killall -9 SpringBoard" +SUBPROJECTS += exacttimeprefs +include $(THEOS_MAKE_PATH)/aggregate.mk diff --git a/Tweak.xm b/Tweak.xm index 59307bb..05b1298 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -8,24 +8,62 @@ @end static bool is24h; +static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist"; + %hook NCLookHeaderContentView -(void)_updateDateLabelFontForShortLook{ %orig; NSDate *date = MSHookIvar(self, "_date"); NSInteger format = MSHookIvar(self, "_dateFormatStyle"); + NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath]; + CGFloat affectTime = [[prefs objectForKey:@"affectTime"] floatValue]; if((date != nil) && (format == 1)){ NCNotificationDateLabel *dateLabel = MSHookIvar(self, "_dateLabel"); - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - if(is24h) - { - [dateFormatter setDateFormat:@"HH:mm"]; - }else{ - [dateFormatter setDateFormat:@"h:mm a"]; + 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]; } - dateLabel.text = [dateFormatter stringFromDate:date]; - [dateLabel sizeToFit]; - [dateFormatter release]; } } -(void)dateLabelDidChange:(id)arg1{ diff --git a/control b/control index a2d4fd2..75e5388 100644 --- a/control +++ b/control @@ -1,7 +1,7 @@ Package: com.gilshahar7.exacttime Name: ExactTime Depends: mobilesubstrate -Version: 1.0 +Version: 1.3 Architecture: iphoneos-arm Description: Shows the exact time of a notification. Maintainer: gilshahar7 diff --git a/exacttimeprefs/ExactTimeprefs.mm b/exacttimeprefs/ExactTimeprefs.mm new file mode 100644 index 0000000..2419590 --- /dev/null +++ b/exacttimeprefs/ExactTimeprefs.mm @@ -0,0 +1,20 @@ +#import + +@interface ExactTimeprefsListController: PSListController { +} +@end + +@implementation ExactTimeprefsListController +- (id)specifiers { + if(_specifiers == nil) { + _specifiers = [[self loadSpecifiersFromPlistName:@"ExactTimeprefs" target:self] retain]; + } + return _specifiers; +} + +-(void)apply{ +[self.view endEditing:YES]; +} +@end + +// vim:ft=objc diff --git a/exacttimeprefs/Makefile b/exacttimeprefs/Makefile new file mode 100644 index 0000000..8786ab8 --- /dev/null +++ b/exacttimeprefs/Makefile @@ -0,0 +1,14 @@ +ARCHS = armv7 arm64 +include $(THEOS)/makefiles/common.mk + +BUNDLE_NAME = ExactTimeprefs +ExactTimeprefs_FILES = ExactTimeprefs.mm +ExactTimeprefs_INSTALL_PATH = /Library/PreferenceBundles +ExactTimeprefs_FRAMEWORKS = UIKit +ExactTimeprefs_PRIVATE_FRAMEWORKS = Preferences + +include $(THEOS_MAKE_PATH)/bundle.mk + +internal-stage:: + $(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END) + $(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/ExactTimeprefs.plist$(ECHO_END) diff --git a/exacttimeprefs/Resources/ExactTime@2x.png b/exacttimeprefs/Resources/ExactTime@2x.png new file mode 100644 index 0000000..bb776e2 Binary files /dev/null and b/exacttimeprefs/Resources/ExactTime@2x.png differ diff --git a/exacttimeprefs/Resources/ExactTimeprefs.plist b/exacttimeprefs/Resources/ExactTimeprefs.plist new file mode 100644 index 0000000..71fe062 --- /dev/null +++ b/exacttimeprefs/Resources/ExactTimeprefs.plist @@ -0,0 +1,82 @@ + + + + + items + + + cell + PSGroupCell + footerText + Only show the exact time for notifications older than this value (0~240). Default value for stock iOS is 240 minutes (4 hours) + + + cell + PSEditTextCell + defaults + com.gilshahar7.exacttimeprefs + key + affectTime + default + 10 + isNumeric + + label + Affect after (in minutes) + + + cell + PSButtonCell + defaults com.gilshahar7.exacttimeprefs + label + Apply + action + apply + + + cell + PSGroupCell + footerText + This will add "Xh ago" where there is an exact time, separated by a ' • ' Note: this will override any language + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.exacttimeprefs + key + addToCurrent + label + Add estimated time to exact time + + + cell + PSGroupCell + footerText + This will add minutes to all "Xh ago" Note: this will override any language + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.exacttimeprefs + key + addMinutes + label + Change "2h ago" to "2h 17m ago" + + + cell + PSGroupCell + footerText + Made by: gilshahar7. + + + title + ExactTime + + diff --git a/exacttimeprefs/Resources/Info.plist b/exacttimeprefs/Resources/Info.plist new file mode 100644 index 0000000..4c5b2ad --- /dev/null +++ b/exacttimeprefs/Resources/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ExactTimeprefs + CFBundleIdentifier + com.gilshahar7.exacttimeprefs + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + DTPlatformName + iphoneos + MinimumOSVersion + 3.0 + NSPrincipalClass + ExactTimeprefsListController + + diff --git a/exacttimeprefs/entry.plist b/exacttimeprefs/entry.plist new file mode 100644 index 0000000..a0d975d --- /dev/null +++ b/exacttimeprefs/entry.plist @@ -0,0 +1,10 @@ +{ + entry = { + bundle = ExactTimeprefs; + cell = PSLinkCell; + detail = ExactTimeprefsListController; + icon = ExactTime.png; + isController = 1; + label = ExactTime; + }; +} diff --git a/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs b/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs new file mode 100644 index 0000000..679e0f2 Binary files /dev/null and b/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs differ diff --git a/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs.plist b/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs.plist new file mode 100644 index 0000000..71fe062 --- /dev/null +++ b/exacttimeprefs/obj/ExactTimeprefs.bundle/ExactTimeprefs.plist @@ -0,0 +1,82 @@ + + + + + items + + + cell + PSGroupCell + footerText + Only show the exact time for notifications older than this value (0~240). Default value for stock iOS is 240 minutes (4 hours) + + + cell + PSEditTextCell + defaults + com.gilshahar7.exacttimeprefs + key + affectTime + default + 10 + isNumeric + + label + Affect after (in minutes) + + + cell + PSButtonCell + defaults com.gilshahar7.exacttimeprefs + label + Apply + action + apply + + + cell + PSGroupCell + footerText + This will add "Xh ago" where there is an exact time, separated by a ' • ' Note: this will override any language + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.exacttimeprefs + key + addToCurrent + label + Add estimated time to exact time + + + cell + PSGroupCell + footerText + This will add minutes to all "Xh ago" Note: this will override any language + + + cell + PSSwitchCell + default + + defaults + com.gilshahar7.exacttimeprefs + key + addMinutes + label + Change "2h ago" to "2h 17m ago" + + + cell + PSGroupCell + footerText + Made by: gilshahar7. + + + title + ExactTime + + diff --git a/exacttimeprefs/obj/ExactTimeprefs.bundle/Info.plist b/exacttimeprefs/obj/ExactTimeprefs.bundle/Info.plist new file mode 100644 index 0000000..4c5b2ad --- /dev/null +++ b/exacttimeprefs/obj/ExactTimeprefs.bundle/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ExactTimeprefs + CFBundleIdentifier + com.gilshahar7.exacttimeprefs + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + DTPlatformName + iphoneos + MinimumOSVersion + 3.0 + NSPrincipalClass + ExactTimeprefsListController + + diff --git a/exacttimeprefs/obj/ExactTimeprefs.mm.4bb0a109.o b/exacttimeprefs/obj/ExactTimeprefs.mm.4bb0a109.o new file mode 100644 index 0000000..8e113f9 Binary files /dev/null and b/exacttimeprefs/obj/ExactTimeprefs.mm.4bb0a109.o differ