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.

148 lines
4.5KB

  1. #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
  2. #import <AudioToolbox/AudioToolbox.h>
  3. #import <AudioToolbox/AudioServices.h>
  4. @interface SBTodayTableHeaderView : UIView
  5. -(NSString *)lunarDateHeaderString;
  6. @end
  7. @interface SBFLockScreenDateView : UIView
  8. @property (nonatomic, assign) UILabel *duplexCalendarLabel;
  9. @property (nonatomic, assign) SBTodayTableHeaderView *todayHeaderView;
  10. @property (nonatomic, assign) NSString *todayHeaderViewText;
  11. @property bool dateHidden;
  12. -(id)_dateFont;
  13. -(id)_dateColor;
  14. -(BOOL)isDateHidden;
  15. -(void)layoutDuplexCalendarLabel;
  16. @end
  17. @interface _UILegibilityView : UIView
  18. @end
  19. @interface _UILegibilityLabel : _UILegibilityView
  20. @property (nonatomic, assign) NSString* string;
  21. @property (nonatomic, assign) UIFont* font;
  22. @end
  23. extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
  24. static NSString *myObserver=@"duplexcalendarObserver";
  25. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.duplexcalendarprefs.plist";
  26. static NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  27. static void savePressed(){
  28. prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  29. }
  30. static void savePressed(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  31. prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  32. }
  33. static SBTodayTableHeaderView *stattodayHeaderView;
  34. static float originx = 0.0;
  35. static float originy = 0.0;
  36. static float sizewidth = 0.0;
  37. static float sizeheight = 0.0;
  38. %hook SBTodayTableHeaderView
  39. -(SBTodayTableHeaderView *)initWithFrame:(CGRect)arg1{
  40. stattodayHeaderView = %orig();
  41. return stattodayHeaderView;
  42. }
  43. %end
  44. %hook SBFLockScreenDateView
  45. %property (nonatomic, assign) UILabel *duplexCalendarLabel;
  46. %property (nonatomic, assign) NSString *todayHeaderViewText;
  47. -(SBFLockScreenDateView *)initWithFrame:(id)arg1{
  48. SBFLockScreenDateView *origself = %orig(arg1);
  49. if(!self.duplexCalendarLabel){
  50. self.duplexCalendarLabel = [[UILabel alloc] initWithFrame:CGRectMake(originx-50, originy + 19, sizewidth+100, sizeheight)];
  51. self.duplexCalendarLabel.font = [[self _dateFont] fontWithSize:16];
  52. [self addSubview:self.duplexCalendarLabel];
  53. self.duplexCalendarLabel.textColor = [self _dateColor];
  54. self.duplexCalendarLabel.textAlignment = 1;
  55. }
  56. return origself;
  57. }
  58. %new
  59. -(void)layoutDuplexCalendarLabel{
  60. NSString *offsetXTextField = [prefs objectForKey:@"offsetXTextField"];
  61. NSString *offsetYTextField = [prefs objectForKey:@"offsetYTextField"];
  62. NSString *FontSizeTextField = [prefs objectForKey:@"FontSizeTextField"];
  63. if(originx <= 0.0)
  64. {
  65. UILabel *originalLabel = MSHookIvar<UILabel *>(self, "_dateLabel");
  66. originx = originalLabel.frame.origin.x;
  67. originy = originalLabel.frame.origin.y;
  68. sizewidth = originalLabel.frame.size.width;
  69. sizeheight = originalLabel.frame.size.height;
  70. }
  71. [self.duplexCalendarLabel setFrame:CGRectMake(originx-50+ [offsetXTextField floatValue], originy + 19 + [offsetYTextField floatValue], sizewidth+100, sizeheight)];
  72. UIFont *font = self.duplexCalendarLabel.font;
  73. if([FontSizeTextField floatValue] == 0){
  74. self.duplexCalendarLabel.font = [font fontWithSize:16.0];
  75. }else{
  76. self.duplexCalendarLabel.font = [font fontWithSize:[FontSizeTextField floatValue]];
  77. }
  78. if(self.duplexCalendarLabel){
  79. if([self isDateHidden]){
  80. self.duplexCalendarLabel.hidden = true;
  81. }else{
  82. self.duplexCalendarLabel.hidden = false;
  83. }
  84. }
  85. }
  86. -(void)_updateLabels{
  87. [self layoutDuplexCalendarLabel];
  88. if(!self.todayHeaderViewText){
  89. self.todayHeaderViewText = [stattodayHeaderView lunarDateHeaderString];
  90. }
  91. self.duplexCalendarLabel.text = self.todayHeaderViewText;
  92. %orig;
  93. }
  94. -(void)_layoutDateLabel {
  95. [self layoutDuplexCalendarLabel];
  96. %orig;
  97. _UILegibilityLabel *originalLegibilityLabel = MSHookIvar<_UILegibilityLabel *>(self, "_legibilityDateLabel");
  98. [originalLegibilityLabel setFrame:CGRectMake(originx, originy - 3, sizewidth, sizeheight)];
  99. }
  100. -(void)updateFormat{
  101. [self layoutDuplexCalendarLabel];
  102. %orig;
  103. }
  104. -(void)layoutSubviews {
  105. [self layoutDuplexCalendarLabel];
  106. %orig;
  107. }
  108. -(void)setDateHidden:(bool)arg1{
  109. %orig(arg1);
  110. if(self.duplexCalendarLabel){
  111. self.duplexCalendarLabel.hidden = arg1;
  112. }
  113. }
  114. %end
  115. %ctor{
  116. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  117. (void*)myObserver,
  118. savePressed,
  119. CFSTR("duplexcalendar.savepressed"),
  120. NULL,
  121. CFNotificationSuspensionBehaviorDeliverImmediately);
  122. savePressed();
  123. }