Skip to content

Commit

Permalink
Support iOS 7
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli committed Dec 31, 2013
1 parent 000353d commit 5989fcb
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,8 +1,8 @@
.DS_Store
.theos
ChineseCalendar.xcodeproj/project.xcworkspace
ChineseCalendar.xcodeproj/xcuserdata/
Widget/*.deb
Widget/.theos
Widget/_
Widget/Common/
Widget/obj/
Expand Down
15 changes: 13 additions & 2 deletions Common/TLCalendarScrollView.m
Expand Up @@ -272,9 +272,20 @@ - (NSMutableArray *)attributesForDisplay:(id<TLCalendarDisplay>)display {

const NSTimeInterval DAY_INTERVAL = 24 * 60 * 60;
NSInteger days = [display numberOfDays];
NSDate *start = [_calendar dateFromComponents:[display firstDay]];
NSDate *date = nil;
for (NSInteger i = 0; i < days; i++) {
NSDate *date = [NSDate dateWithTimeInterval:(DAY_INTERVAL * i) sinceDate:start];
NSDate *now = date == nil ? [_calendar dateFromComponents:[display firstDay]] : [NSDate dateWithTimeInterval:DAY_INTERVAL sinceDate:date];
if (date) {
NSTimeInterval offset = [_calendar.timeZone daylightSavingTimeOffsetForDate:date] - [_calendar.timeZone daylightSavingTimeOffsetForDate:now];
if (offset != 0) {
date = [now dateByAddingTimeInterval:offset];
} else {
date = now;
}
} else {
date = now;
}

NSDateComponents *day = [_calendar components:[display calendarUnit] fromDate:date];

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:8];
Expand Down
30 changes: 30 additions & 0 deletions Widget/Common.h
@@ -0,0 +1,30 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define TLLog(fmt, ...) NSLog(@"-----> " fmt, ##__VA_ARGS__)

#if __LP64__
#define NSInt "ld"
#define NSUInt "lu"
#else
#define NSInt "d"
#define NSUInt "u"
#endif /* __LP64__ */

#define LC_BUNDLE_PATH @"/System/Library/WeeAppPlugins/LunarCalendarWidget.bundle"

NS_INLINE NSBundle *LunarCalendarBundle()
{
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
bundle = [[NSBundle bundleWithPath:LC_BUNDLE_PATH] retain];
});
return bundle;
}
15 changes: 15 additions & 0 deletions Widget/LunarCalendarWidgetController.h
@@ -0,0 +1,15 @@
#import <UIKit/UIKit.h>
#import "BBWeeAppController-Protocol.h"

@class TLLunarCalendarWeeView;

@interface LunarCalendarWidgetController: NSObject <BBWeeAppController> {
TLLunarCalendarWeeView *_view;
}

@property (nonatomic, readonly) UIView *view;

- (CGFloat)viewWidth;
- (CGFloat)viewHeight;

@end
20 changes: 2 additions & 18 deletions Widget/LunarCalendarWidgetController.m
@@ -1,4 +1,4 @@
#import "BBWeeAppController-Protocol.h"
#import "LunarCalendarWidgetController.h"
#import "TLMonthWidgetView.h"
#import "TLWeekWidgetView.h"
#import "TLDayWidgetView.h"
Expand All @@ -20,25 +20,9 @@ + (id)sharedInstance;
- (id)listView;
@end

@interface LunarCalendarWidgetController: NSObject <BBWeeAppController> {
TLLunarCalendarWeeView *_view;
}

@property (nonatomic, readonly) UIView *view;

- (CGFloat)viewWidth;

- (void)displayView;

@end

@implementation LunarCalendarWidgetController

- (id)init {
if((self = [super init]) != nil) {
} return self;
}

- (void)dealloc {
[_view release];
[super dealloc];
Expand Down Expand Up @@ -104,7 +88,7 @@ - (void)displayView {
}
}

- (float)viewHeight {
- (CGFloat)viewHeight {
CGFloat height = 71.0f;
switch (TLPreferecneIntForKey(@"viewType", TLLunarCalendarWeeViewMonthType)) {
case TLLunarCalendarWeeViewDayType:
Expand Down
43 changes: 27 additions & 16 deletions Widget/Makefile
@@ -1,26 +1,37 @@
include config.mk
export ARCHS = armv7 arm64
export TARGET = iphone:latest:5.0

GO_EASY_ON_ME = 1

# Path to theos
THEOS = /opt/theos

# IP address of target device
THEOS_DEVICE_IP = 192.168.5.11

include $(THEOS)/makefiles/common.mk

SUBPROJECTS = Preference

BUNDLE_NAME = LunarCalendarWidget
LunarCalendarWidget_FILES = LunarCalendarWidgetController.m \
../Common/NSCalendarAdditons.m \
../Common/NSDateComponentsAdditions.m \
../Common/lunardate.c \
../Common/solarterm.c \
../Common/TLCalendarScrollView.m \
../Common/TLFestivalsManager.m \
../Common/TLPreferences.m \
../Common/TLCalendarDisplayAttributeKeys.m \
TLLunarCalendarWeeView.m \
TLMonthWidgetView.m \
TLWeekWidgetView.m \
TLDayWidgetView.m \
TLWidgetView.m
LunarCalendarWidget_INSTALL_PATH = /Library/WeeLoader/Plugins/
TLCCWidgetViewController.m \
../Common/NSCalendarAdditons.m \
../Common/NSDateComponentsAdditions.m \
../Common/lunardate.c \
../Common/solarterm.c \
../Common/TLCalendarScrollView.m \
../Common/TLFestivalsManager.m \
../Common/TLPreferences.m \
../Common/TLCalendarDisplayAttributeKeys.m \
TLLunarCalendarWeeView.m \
TLMonthWidgetView.m \
TLWeekWidgetView.m \
TLDayWidgetView.m \
TLWidgetView.m
LunarCalendarWidget_INSTALL_PATH = /System/Library/WeeAppPlugins
LunarCalendarWidget_FRAMEWORKS = UIKit CoreGraphics

LunarCalendarWidget_LDFLAGS = -F$(SYSROOT)/System/Library/PrivateFrameworks -weak_framework SpringBoardUIServices

include $(THEOS_MAKE_PATH)/bundle.mk
include $(THEOS_MAKE_PATH)/aggregate.mk
Expand Down
2 changes: 1 addition & 1 deletion Widget/Preference/LCWPListController.m
Expand Up @@ -26,7 +26,7 @@ -(void)viewDidBecomeVisible {
#pragma mark - Getters

- (NSString *)widgetVersion {
return @"1.0.2";
return @"1.0.7";
}

- (NSString *)username {
Expand Down
6 changes: 3 additions & 3 deletions Widget/Preference/LCWSettingsController.m
Expand Up @@ -19,10 +19,10 @@ -(void)setPreferenceValue:(id)value specifier:(id)specifier {
[super setPreferenceValue:value specifier:specifier];
NSString *key = [specifier propertyForKey:@"key"];
if (key) {
static NSString *DOMAIN = @"tonyli.lunarcalendar.widget";
NSMutableDictionary *pref = [NSMutableDictionary dictionaryWithDictionary:[[self userDefaults] persistentDomainForName:DOMAIN]];
static NSString *APP_DOMAIN = @"tonyli.lunarcalendar.widget";
NSMutableDictionary *pref = [NSMutableDictionary dictionaryWithDictionary:[[self userDefaults] persistentDomainForName:APP_DOMAIN]];
[pref setObject:value forKey:key];
[_userDefaults setPersistentDomain:pref forName:DOMAIN];
[_userDefaults setPersistentDomain:pref forName:APP_DOMAIN];
[_userDefaults synchronize];
}
}
Expand Down
5 changes: 2 additions & 3 deletions Widget/Preference/Makefile
@@ -1,10 +1,9 @@
include ../config.mk
include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = LunarCalendarWidgetPreference
LunarCalendarWidgetPreference_FILES = LCWSettingsController.m \
LCWPListController.m \
LCWPIntroductionController.m
LCWPListController.m \
LCWPIntroductionController.m
LunarCalendarWidgetPreference_INSTALL_PATH = /Library/PreferenceBundles
LunarCalendarWidgetPreference_FRAMEWORKS = UIKit
LunarCalendarWidgetPreference_PRIVATE_FRAMEWORKS = Preferences
Expand Down
11 changes: 2 additions & 9 deletions Widget/Preference/Resources/Introduction.plist
Expand Up @@ -14,7 +14,7 @@
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>与系统日历程序进行交互:进入某日、查看某日的事件安排</string>
<string>日程显示:直接在日历中查看日程安排信息,无需进入系统日历</string>
</dict>
<dict>
<key>cell</key>
Expand All @@ -26,21 +26,14 @@
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>日历界面直接切换视图,轻松在各个视图之间切换;</string>
<string>三击切换视图:轻松在各个视图之间切换;</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>✓ 以及...以后即将加入的更多方便好用的功能!</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>如果您决定升级到Pro版,请您支持正版!
是使用两瓶可乐半包烟钱的正版,还是使用会伤害您四五千块钱手机的盗版,由您选择。</string>
</dict>
</array>
<key>title</key>
<string>Pro版功能简介</string>
Expand Down
4 changes: 2 additions & 2 deletions Widget/Preference/entry.plist
Expand Up @@ -3,8 +3,8 @@
bundle = "LunarCalendarWidgetPreference";
cell = PSLinkCell;
detail = LCWPListController;
icon = "/Library/WeeLoader/Plugins/LunarCalendarWidget.bundle/Icon-Small@2x.png";
icon = "/System/Library/WeeAppPlugins/LunarCalendarWidget.bundle/Icon-Small@2x.png";
isController = 1;
label = "\U4e2d\U56fd\U519c\U5386";
};
}
}
9 changes: 8 additions & 1 deletion Widget/Resources/Info.plist
Expand Up @@ -9,7 +9,9 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>CFBundleExecutable</key>
<string>LunarCalendarWidget</string>
<key>CFBundleDisplayName</key>
<string>LunarCalendarWidget</string>
<key>MinimumOSVersion</key>
Expand All @@ -33,5 +35,10 @@
</array>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>SBUIWidgetViewControllers</key>
<dict>
<key>SBUIWidgetIdiomNotificationCenterToday</key>
<string>TLCCWidgetViewController</string>
</dict>
</dict>
</plist>
49 changes: 49 additions & 0 deletions Widget/SBUIWidgetViewController.h
@@ -0,0 +1,49 @@
#import <UIKit/UIKit.h>
@protocol _SBUIWidgetHost <NSObject>
-(void)invalidatePreferredViewSize;
-(void)requestLaunchOfURL:(id)url;
-(void)requestPresentationOfViewController:(id)viewController presentationStyle:(int)style context:(id)context completion:(id)completion;
@end



@interface _SBUIWidgetViewController : UIViewController <_SBUIWidgetHost> {
id<_SBUIWidgetHost> *_widgetHost;
NSString *_widgetIdentifier;
int _widgetIdiom;
NSString *_widgetidentifier;
}

//@property(readonly) CGSize preferredViewSize;
//@property id<_SBUIWidgetHost> * widgetHost;
//@property(copy) NSString * widgetIdentifier;
//@property int widgetIdiom;

+ (id)_exportedInterface;
+ (id)_remoteViewControllerInterface;

- (void)__hostDidDismiss;
- (void)__hostDidPresent;
- (void)__hostWillDismiss;
- (void)__hostWillPresent;
- (void)__requestPreferredViewSizeWithReplyHandler:(id)arg1;
- (void)__setWidgetIdentifier:(id)arg1;
- (void)__setWidgetIdiom:(int)arg1;
- (void)dealloc;
- (void)hostDidDismiss;
- (void)hostDidPresent;
- (void)hostWillDismiss;
- (void)hostWillPresent;
- (void)invalidatePreferredViewSize;
- (CGSize)preferredViewSize;
- (void)requestLaunchOfURL:(id)arg1;
- (void)requestPresentationOfViewController:(id)arg1 presentationStyle:(int)arg2 context:(id)arg3 completion:(id)arg4;
- (void)setWidgetHost:(id<_SBUIWidgetHost>)arg1;
- (void)setWidgetIdentifier:(NSString *)arg1;
- (void)setWidgetIdiom:(int)arg1;
- (id)widgetHost;
- (id)widgetIdentifier;
- (int)widgetIdiom;
-(void)unloadView;

@end
58 changes: 58 additions & 0 deletions Widget/TLCCWidgetViewController.m
@@ -0,0 +1,58 @@
#import "LunarCalendarWidgetController.h"
#import "SBUIWidgetViewController.h"

@interface NSObject(SBWidgetHostDelegate)

- (void)widget:(id)arg1 didUpdatePreferredSize:(struct CGSize)arg2;

@end

@interface TLCCWidgetViewController : _SBUIWidgetViewController {
LunarCalendarWidgetController *_controller;
}
@end

@implementation TLCCWidgetViewController

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
if ( (self = [super initWithNibName:nibName bundle:nibBundle]) ) {
_controller = [[LunarCalendarWidgetController alloc] init];
}
return self;
}

- (void)dealloc
{
[_controller release];
_controller = nil;
[super dealloc];
}

- (void)loadView
{
self.view = [_controller view];
}

- (CGSize)preferredViewSize
{
return CGSizeMake([_controller viewWidth], [_controller viewHeight]);
}

- (void)hostDidPresent
{
[super hostDidPresent];
[_controller loadFullView];

if (self.view.bounds.size.height != [_controller viewHeight]) {
[[[self widgetHost] delegate] widget:[self widgetHost] didUpdatePreferredSize:[self preferredViewSize]];
}
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[_controller willRotateToInterfaceOrientation:toInterfaceOrientation];
}

@end

0 comments on commit 5989fcb

Please sign in to comment.