Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

149 Zeilen
6.8KB

  1. #import <Preferences/PSListController.h>
  2. #import <Preferences/PSSpecifier.h>
  3. @interface PSListController (iOS12Plus)
  4. -(BOOL)containsSpecifier:(id)arg1;
  5. @end
  6. @interface ExactTimeprefsListController : PSListController
  7. @property (nonatomic, retain) NSMutableDictionary *savedSpecifiers;
  8. @end
  9. @implementation ExactTimeprefsListController
  10. - (id)readPreferenceValue:(PSSpecifier*)specifier {
  11. NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
  12. NSMutableDictionary *settings = [NSMutableDictionary dictionary];
  13. [settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
  14. return (settings[specifier.properties[@"key"]]) ?: specifier.properties[@"default"];
  15. }
  16. - (void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier {
  17. NSString *path = [NSString stringWithFormat:@"/User/Library/Preferences/%@.plist", specifier.properties[@"defaults"]];
  18. NSMutableDictionary *settings = [NSMutableDictionary dictionary];
  19. [settings addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:path]];
  20. [settings setObject:value forKey:specifier.properties[@"key"]];
  21. [settings writeToFile:path atomically:YES];
  22. CFStringRef notificationName = (CFStringRef)specifier.properties[@"PostNotification"];
  23. if (notificationName) {
  24. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), notificationName, NULL, NULL, YES);
  25. }
  26. //Here we check if the switch is on based of the key of the PSSwitchCell, then hide the specifier
  27. //We then hide the cell using the id of it. If its already hidden we reinsert the cell below a certain specifier based on its ID
  28. NSString *key = [specifier propertyForKey:@"key"];
  29. if([key isEqualToString:@"notifications"]) {
  30. if([value boolValue]) {
  31. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"96"]] afterSpecifierID:@"95" animated:YES];
  32. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"97"]] afterSpecifierID:@"96" animated:YES];
  33. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"98"]] afterSpecifierID:@"97" animated:YES];
  34. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"99"]] afterSpecifierID:@"98" animated:YES];
  35. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"100"]] afterSpecifierID:@"99" animated:YES];
  36. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"101"]] afterSpecifierID:@"100" animated:YES];
  37. [self insertContiguousSpecifiers:@[self.savedSpecifiers[@"102"]] afterSpecifierID:@"101" animated:YES];
  38. } else if([self containsSpecifier:self.savedSpecifiers[@"96"]]) {
  39. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"96"]] animated:YES];
  40. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"97"]] animated:YES];
  41. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"98"]] animated:YES];
  42. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"99"]] animated:YES];
  43. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"100"]] animated:YES];
  44. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"101"]] animated:YES];
  45. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"102"]] animated:YES];
  46. }
  47. }
  48. }
  49. - (id)specifiers {
  50. if(_specifiers == nil) {
  51. _specifiers = [[self loadSpecifiersFromPlistName:@"ExactTimeprefs" target:self] retain];
  52. }
  53. //Code to save certain specifiers
  54. //Add the id of the specifier to the chosenIDs array.
  55. //Only add the IDs of the specifiers you want to hide
  56. NSArray *chosenIDs = @[@"96", @"97", @"98", @"99", @"100", @"101", @"102"];
  57. self.savedSpecifiers = (!self.savedSpecifiers) ? [[NSMutableDictionary alloc] init] : self.savedSpecifiers;
  58. for(PSSpecifier *specifier in _specifiers) {
  59. if([chosenIDs containsObject:[specifier propertyForKey:@"id"]]) {
  60. [self.savedSpecifiers setObject:specifier forKey:[specifier propertyForKey:@"id"]];
  61. }
  62. }
  63. return _specifiers;
  64. }
  65. -(void)viewDidLoad {
  66. [super viewDidLoad];
  67. //From my testing, at this point we can't get the value of a specifier yet as they haven't loaded
  68. //Instead you can just read your switch value from your preferences file
  69. NSDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist"];
  70. if(![preferences[@"notifications"] boolValue] == true) {
  71. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"96"]] animated:NO];
  72. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"97"]] animated:NO];
  73. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"98"]] animated:NO];
  74. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"99"]] animated:NO];
  75. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"100"]] animated:NO];
  76. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"101"]] animated:NO];
  77. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"102"]] animated:NO];
  78. }
  79. }
  80. -(void)reloadSpecifiers {
  81. [super reloadSpecifiers];
  82. //This will look the exact same as step 5, where we only check if specifiers need to be removed
  83. NSDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.gilshahar7.exacttimeprefs.plist"];
  84. if([preferences[@"notifications"] boolValue] == false) {
  85. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"96"]] animated:NO];
  86. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"97"]] animated:NO];
  87. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"98"]] animated:NO];
  88. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"99"]] animated:NO];
  89. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"100"]] animated:NO];
  90. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"101"]] animated:NO];
  91. [self removeContiguousSpecifiers:@[self.savedSpecifiers[@"102"]] animated:NO];
  92. }
  93. }
  94. - (void)loadView {
  95. [super loadView];
  96. ((UITableView *)[self table]).keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  97. }
  98. -(void)_returnKeyPressed:(id)arg1 { [self.view endEditing:YES]; }
  99. -(void)apply{
  100. [self.view endEditing:YES];
  101. }
  102. - (void)sourceLink
  103. {
  104. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/gilshahar7/ExactTime"]];
  105. }
  106. - (void)donationLink
  107. {
  108. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.paypal.me/gilshahar7"]];
  109. }
  110. - (void)openTwitterWithUsername:(NSString*)username
  111. {
  112. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@", username]]];
  113. }
  114. - (void)openTwitter
  115. {
  116. [self openTwitterWithUsername:@"gilshahar7"];
  117. }
  118. - (void)reddit {
  119. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.reddit.com/user/gilshahar7/"]];
  120. }
  121. - (void)sendEmail {
  122. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:gilshahardex99@gmail.com?subject=ExactTime"]];
  123. }
  124. @end
  125. // vim:ft=objc