Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
18 changes: 0 additions & 18 deletions .gitignore

This file was deleted.

392 changes: 18 additions & 374 deletions PomoTimer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>PomoTimerUnitTest.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>2C41B8FA178BF3410065AB62</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>2CC2A47F16A3D0010037CF76</key>
<dict>
<key>primary</key>
Expand Down

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions PomoTimer/LSAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@

@property (strong, nonatomic) UIWindow *window;

@property NSMutableArray *dailyPomodoroArray;
@property NSDictionary *todaysPomodoro;
@property (readonly) NSMutableArray *todaysPomoCycleArray;

- (void)createNewPomoCycle;
- (void)changeTodaysPomoCycleArray:(NSArray *)newArray;
@end
113 changes: 3 additions & 110 deletions PomoTimer/LSAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,150 +7,43 @@
//

#import "LSAppDelegate.h"
#import "LSPomoCycle.h"
#import "LSPomoTask.h"
#import "LSTaskViewController.h"

static NSString *PomodoroFileName = @"Pomodoro.pmtmr";
static NSString *kBackgroundDateKey = @"BackgroundDate";

@interface LSAppDelegate (){
NSDate *_backgroundDate;
}

@end
@implementation LSAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"%s", __FUNCTION__);
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"naviBar.png"] forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithWhite:0.3 alpha:0.8]];
// Override point for customization after application launch.

NSString *filePath = [documentDirectory() stringByAppendingPathComponent:PomodoroFileName];

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
NSArray *unarchArray = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
_dailyPomodoroArray = [[NSMutableArray alloc] initWithArray:unarchArray];
} else {
_dailyPomodoroArray = [[NSMutableArray alloc] initWithCapacity:10];
}

[[UIApplication sharedApplication] cancelAllLocalNotifications];

NSDate *userDefaultBackgroundDate = [[NSUserDefaults standardUserDefaults] objectForKey:kBackgroundDateKey];
if (isSameDay(userDefaultBackgroundDate, [NSDate date])){
_backgroundDate = userDefaultBackgroundDate;
}
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
_backgroundDate = [NSDate date];
NSLog(@"%s \r\n date = %@", __FUNCTION__, _backgroundDate);
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
_backgroundDate = [NSDate date];

NSString *filePath = [documentDirectory() stringByAppendingPathComponent:PomodoroFileName];

[NSKeyedArchiver archiveRootObject:_dailyPomodoroArray toFile:filePath];

NSLog(@"%s \r\n date = %@", __FUNCTION__, _backgroundDate);
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSLog(@"%s \r\n date = %@", __FUNCTION__, _backgroundDate);
//앱을 껐다가 한 참 뒤에 다시 켜는 경우에 문제가 없을까? 즉, 날짜가 바뀌었을 때.
//그 경우 Local Notification이 해결해 주겠지?



UINavigationController *mainNavigationController = (UINavigationController *)self.window.rootViewController;
LSTaskViewController *taskViewController = mainNavigationController.topViewController;

LSPomoTask *currentTask = taskViewController.pomoCycle.currentTask;
if (currentTask.status == COUNTING){
int timeGap = [[NSDate date] timeIntervalSinceDate:_backgroundDate];
int currentTaskTime = currentTask.taskTimeInSecond;
int resultTime = currentTaskTime - timeGap;
currentTask.taskTimeInSecond = resultTime;
}
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
//NSLog(@"%s \r\n date = %@", __FUNCTION__, _backgroundDate);
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

- (void)applicationWillTerminate:(UIApplication *)application
{
NSString *filePath = [documentDirectory() stringByAppendingPathComponent:PomodoroFileName];

[NSKeyedArchiver archiveRootObject:_dailyPomodoroArray toFile:filePath];

[[NSUserDefaults standardUserDefaults] setObject:_backgroundDate forKey:kBackgroundDateKey];
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (NSDictionary *)todaysPomodoro
{
NSDictionary *lastDailyPomo = [_dailyPomodoroArray lastObject];
if (lastDailyPomo != nil){
NSDate *lastPomoDate = [lastDailyPomo valueForKey:@"PomodoroDate"];
if (isSameDay(lastPomoDate, [NSDate date]))
return lastDailyPomo;
}

lastDailyPomo = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate date], kPomodoroDateKey, [NSArray array], kPomodoroCyclesKey, nil];
[_dailyPomodoroArray addObject:lastDailyPomo];

return lastDailyPomo;
}

- (void)setTodaysPomodoro:(NSDictionary *)todaysPomodoro
{
NSDictionary *lastDailyPomo = [_dailyPomodoroArray lastObject];
if (lastDailyPomo != nil){
NSDate *lastPomoDate = [lastDailyPomo valueForKey:@"PomodoroDate"];
if (isSameDay(lastPomoDate, [NSDate date])){
[_dailyPomodoroArray removeLastObject];
}
}
[_dailyPomodoroArray addObject:todaysPomodoro];
}

- (NSMutableArray *)todaysPomoCycleArray
{
NSMutableArray *pomoCycle = [[NSMutableArray alloc] initWithArray:[self.todaysPomodoro valueForKey:kPomodoroCyclesKey]];
return pomoCycle;
}

- (void)createNewPomoCycle
{
NSMutableArray *pomoCycles = [self todaysPomoCycleArray];

LSPomoCycle *newCycle = [[LSPomoCycle alloc] init];
[pomoCycles addObject:newCycle];

NSMutableDictionary *newTodayDict = [NSMutableDictionary dictionaryWithDictionary:self.todaysPomodoro];
[newTodayDict setValue:pomoCycles forKey:kPomodoroCyclesKey];
self.todaysPomodoro = newTodayDict;
}

- (void)changeTodaysPomoCycleArray:(NSArray *)newArray
{
NSMutableDictionary *newTodayDict = [NSMutableDictionary dictionaryWithDictionary:self.todaysPomodoro];
[newTodayDict setValue:newArray forKey:kPomodoroCyclesKey];
self.todaysPomodoro = newTodayDict;
}
@end
15 changes: 0 additions & 15 deletions PomoTimer/LSHistoryDetailViewController.h

This file was deleted.

Loading