Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Commit

Permalink
[tweak,prefs] implement settings sample notification thing
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Jun 18, 2017
1 parent 166d214 commit 8fd3a09
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 24 deletions.
4 changes: 4 additions & 0 deletions HBCZNowPlayingController.x
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#pragma mark - NSObject

- (instancetype)init {
if (!IN_SPRINGBOARD) {
return nil;
}

self = [super init];

if (self) {
Expand Down
12 changes: 7 additions & 5 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ HBCZPreferences *preferences;
// set up variables
preferences = [HBCZPreferences sharedInstance];

// get the controller rolling
[HBCZNowPlayingController sharedInstance];
if (IN_SPRINGBOARD) {
// get the controller rolling
[HBCZNowPlayingController sharedInstance];

%init;
%init;

if (IS_IOS_OR_NEWER(iOS_10_0)) {
%init(PhilSchiller);
if (IS_IOS_OR_NEWER(iOS_10_0)) {
%init(PhilSchiller);
}
}
}
100 changes: 92 additions & 8 deletions prefs/HBCZNotificationTableCell.x
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
#import "HBCZNotificationTableCell.h"
#import <Preferences/PSSpecifier.h>
#import <UIKit/UIImage+Private.h>
#include <dlfcn.h>

@interface NCNotificationRequest : NSObject
@interface NCNotificationContent : NSObject <NSCopying, NSMutableCopying>

+ (instancetype)notificationRequestWithSectionId:(NSString *)sectionID notificationId:(NSString *)notificationID threadId:(NSString *)threadID title:(NSString *)title message:(NSString *)message timestamp:(NSDate *)timestamp destinations:(NSSet *)destinations;
@property (nonatomic, readonly, copy) NSString *header;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *message;
@property (nonatomic, readonly, copy) NSString *subtitle;
@property (nonatomic, readonly, copy) NSString *topic;

@property (nonatomic, readonly) NSDate *date;
@property (getter=isDateAllDay, nonatomic, readonly) BOOL dateAllDay;
@property (nonatomic, readonly) NSTimeZone *timeZone;

@property (nonatomic, readonly) UIImage *icon;
@property (nonatomic, readonly) UIImage *attachmentImage;

@end

@interface NCMutableNotificationContent : NCNotificationContent

@property (nonatomic, copy) NSString *header;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *message;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *topic;

@property (nonatomic, retain) NSDate *date;
@property (getter=isDateAllDay, nonatomic) BOOL dateAllDay;
@property (nonatomic, retain) NSTimeZone *timeZone;

@property (nonatomic, retain) UIImage *icon;
@property (nonatomic, retain) UIImage *attachmentImage;

@end

@interface NCNotificationRequest : NSObject <NSCopying, NSMutableCopying>

@property (nonatomic, copy, readonly) NSString *sectionIdentifier;

@property (nonatomic, retain, readonly) NCNotificationContent *content;

@end

@interface NCMutableNotificationRequest : NSObject

@property (nonatomic, copy) NSString *sectionIdentifier;

@property (nonatomic, retain) NCMutableNotificationContent *content;

@end

Expand Down Expand Up @@ -39,9 +84,10 @@

UIImageView *wallpaperView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
wallpaperView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
wallpaperView.image = [UIImage imageWithContentsOfFile:@"~/Library/SpringBoard/LockBackgroundThumbnail.jpg".stringByExpandingTildeInPath];
wallpaperView.image = [UIImage imageWithContentsOfCPBitmapFile:@"~/Library/SpringBoard/LockBackground.cpbitmap".stringByExpandingTildeInPath flags:kNilOptions];
wallpaperView.contentMode = UIViewContentModeScaleAspectFill;
wallpaperView.clipsToBounds = YES;
wallpaperView.layer.minificationFilter = kCAFilterTrilinear;
[self.contentView addSubview:wallpaperView];

[self _setUpNotification];
Expand All @@ -51,24 +97,62 @@
}

- (void)_setUpNotification {
dlopen("/Library/MobileSubstrate/DynamicLibraries/Canzone.dylib", RTLD_LAZY);
static NSArray *Songs;
static UIImage *CanzoneImage;
static UIImage *PlaceholderImage;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/UserNotificationsUIKit.framework"] load];
dlopen("/Library/MobileSubstrate/DynamicLibraries/Canzone.dylib", RTLD_LAZY);

Songs = @[
@[ @"Take on Me", @"Hunting High and Low\na-ha" ],
@[ @"Get Lucky", @"Random Access Memories\nDaft Punk" ],
@[ @"Drop It Like It’s Hot", @"R&G (Rhythm & Gangsta): The Masterpiece\nSnoop Dogg ft. Pharrell" ],
@[ @"Every Teardrop is a Waterfall", @"Until Now\nColdplay vs Swedish House Mafia" ],
@[ @"Satellite", @"Sirens of the Sea\nOceanlab" ],
@[ @"What Is Love", @"The Album\nHaddaway" ],
@[ @"All Star", @"All Star Smash Hits\nSmash Mouth" ],
@[ @"Sandstorm", @"Before the Storm\nDarude" ],
@[ @"Secret Agent", @"Netsky\nNetsky" ],
@[ @"Strobe", @"For Lack Of A Better Name\ndeadmau5" ],
@[ @"Slam The Door", @"Slam The Door\nZedd" ],
@[ @"Till The Sky Falls Down", @"The New Daylight\nDash Berlin" ],
@[ @"Deep At Night (Adam K & Soha Remix)", @"Deep At Night\nErcola & Heikki L" ],
@[ @"Snowcone", @"W:/2016ALBUM/\ndeadmau5" ],
@[ @"Kyoto", @"Horsestep\nDJ Sn0w & DJ Horse" ]
];

CanzoneImage = [UIImage _applicationIconImageForBundleIdentifier:@"ws.hbang.canzone.app" format:MIIconVariantDocumentSmall scale:[UIScreen mainScreen].scale]; // yeah the names are messed up
PlaceholderImage = [UIImage imageNamed:@"placeholder-artwork" inBundle:[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/MedaPlayerUI.framework"]];
});

if (_notificationCell) {
[_notificationCell removeFromSuperview];
_notificationCell = nil;
}

[[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/UserNotificationsUIKit.framework"] load];
NSArray *song = Songs[arc4random_uniform(Songs.count)];

NCMutableNotificationRequest *request = [[%c(NCMutableNotificationRequest) alloc] init];
request.sectionIdentifier = @"ws.hbang.canzone.app";

NCNotificationRequest *request = [%c(NCNotificationRequest) notificationRequestWithSectionId:@"ws.hbang.canzone.app" notificationId:@"0" threadId:@"0" title:@"Now Playing" message:@"Take on Me\nHunting High and Low\na-ha" timestamp:[NSDate date] destinations:[NSSet set]];
NCMutableNotificationContent *content = [[%c(NCMutableNotificationContent) alloc] init];
content.title = NSLocalizedStringFromTableInBundle(@"NOW_PLAYING_TITLE", @"Localizable", [NSBundle bundleForClass:self.class], nil);
content.subtitle = song[0];
content.message = song[1];
content.date = [NSDate date];
content.icon = CanzoneImage;
content.attachmentImage = PlaceholderImage;
request.content = [content copy];

_notificationCell = [[%c(NCNotificationListCell) alloc] initWithFrame:CGRectInset(self.contentView.bounds, 15.f, 15.f)];
_notificationCell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_notificationCell.contentViewController = [[%c(NCNotificationViewController) alloc] initWithNotificationRequest:request];
_notificationCell.contentViewController = [[%c(NCNotificationViewController) alloc] initWithNotificationRequest:[request copy]];
_notificationCell.contentViewController.associatedView = _notificationCell;
_notificationCell.insetMargins = UIEdgeInsetsMake(15.f, 15.f, 15.f, 15.f);
_notificationCell.userInteractionEnabled = NO;
_notificationCell.adjustsFontForContentSizeCategory = YES;
_notificationCell.adjustsFontForContentSizeCategory = NO;
_notificationCell.backgroundBlurred = YES;
_notificationCell.configured = YES;
[self.contentView addSubview:_notificationCell];
Expand Down
4 changes: 2 additions & 2 deletions prefs/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>SAMPLE</string>
<string>PREVIEW</string>
</dict>
<dict>
<key>cellClass</key>
<string>HBCZNotificationTableCell</string>
<key>height</key>
<integer>116</integer>
<integer>122</integer>
</dict>
<dict>
<key>cell</key>
Expand Down
6 changes: 3 additions & 3 deletions prefs/Resources/en.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<key>WIDGET_EXPLANATION</key>
<string>Enable the Now Playing widget via the Notification Center Today page.</string>

<!-- Label for the notification sample section. -->
<key>SAMPLE</key>
<string>Sample</string>
<!-- Label for the notification preview section. -->
<key>PREVIEW</key>
<string>Preview</string>

<!-- Label for the notifications section. -->
<key>NOTIFICATIONS</key>
Expand Down
6 changes: 3 additions & 3 deletions prefs/Resources/en_AU.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<key>WIDGET_EXPLANATION</key>
<string>Enable the Now Playing widget via the Notification Centre Today page.</string>

<!-- Label for the notification sample section. -->
<key>SAMPLE</key>
<string>Sample</string>
<!-- Label for the notification preview section. -->
<key>PREVIEW</key>
<string>Preview</string>

<!-- Label for the notifications section. -->
<key>NOTIFICATIONS</key>
Expand Down
6 changes: 3 additions & 3 deletions prefs/Resources/en_GB.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<key>WIDGET_EXPLANATION</key>
<string>Enable the Now Playing widget via the Notification Centre Today page.</string>

<!-- Label for the notification sample section. -->
<key>SAMPLE</key>
<string>Sample</string>
<!-- Label for the notification preview section. -->
<key>PREVIEW</key>
<string>Preview</string>

<!-- Label for the notifications section. -->
<key>NOTIFICATIONS</key>
Expand Down

0 comments on commit 8fd3a09

Please sign in to comment.