Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Prompt to recreate library when upgrading app in place
Browse files Browse the repository at this point in the history
  • Loading branch information
swisspol committed Jan 25, 2014
1 parent 9dfe96f commit 3d70439
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ @implementation AppDelegate
+ (void) initialize {
// Setup initial user defaults
NSMutableDictionary* defaults = [[NSMutableDictionary alloc] init];
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_LibraryVersion];
[defaults setObject:[NSNumber numberWithBool:NO] forKey:kDefaultKey_ServerEnabled];
[defaults setObject:[NSNumber numberWithInteger:kServerMode_Trial] forKey:kDefaultKey_ServerMode];
[defaults setObject:[NSNumber numberWithInteger:kTrialMaxUploads] forKey:kDefaultKey_UploadsRemaining];
Expand All @@ -180,6 +181,7 @@ + (void) initialize {
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_CurrentCollection];
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_CurrentComic];
[defaults setObject:[NSNumber numberWithInteger:kSortingMode_ByStatus] forKey:kDefaultKey_SortingMode];
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_LaunchCount];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
[defaults release];

Expand Down Expand Up @@ -237,6 +239,7 @@ - (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(
// Update library immediately
if ([[LibraryConnection mainConnection] countObjectsOfClass:[Comic class]] == 0) {
[[LibraryUpdater sharedUpdater] update:YES];
[[NSUserDefaults standardUserDefaults] setInteger:kLibraryVersion forKey:kDefaultKey_LibraryVersion];
} else {
[[LibraryUpdater sharedUpdater] update:NO];
}
Expand Down
49 changes: 36 additions & 13 deletions Classes/LibraryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,14 @@ - (void) viewWillAppear:(BOOL)animated {

- (void) _rateNow:(id)argument {
[[AppDelegate sharedDelegate] logEvent:@"rating.now"];
[[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:kDefaultUserKey_LaunchCount];
[[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:kDefaultKey_LaunchCount];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"iTunesURL"]]];
}

- (void) _rateLater:(id)argument {
[[AppDelegate sharedDelegate] logEvent:@"rating.later"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:kDefaultUserKey_LaunchCount];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:kDefaultKey_LaunchCount];
}

- (void) _showRatingScreen {
Expand All @@ -686,7 +686,19 @@ - (void) _showRatingScreen {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}

- (void) _requireUpdate {
[self _forceUpdate];
[[NSUserDefaults standardUserDefaults] setInteger:kLibraryVersion forKey:kDefaultKey_LibraryVersion];
}

- (void) _viewDidReallyAppear {
BOOL needLibraryUpdate = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LibraryVersion] != kLibraryVersion;
if (needLibraryUpdate) {
LOG_VERBOSE(@"Library is outdated at version %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LibraryVersion]);
[_currentComic release];
_currentComic = nil;
}

if (_currentComic) {
Comic* comic = [[_currentComic retain] autorelease];
[_currentComic release];
Expand All @@ -707,16 +719,27 @@ - (void) _viewDidReallyAppear {
}];
_launchView = nil;

NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultUserKey_LaunchCount];
NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LaunchCount];
if (count >= 0) {
[[NSUserDefaults standardUserDefaults] setInteger:(count + 1) forKey:kDefaultUserKey_LaunchCount];
if ((count + 1 >= kLaunchCountBeforeRating) && !self.modalViewController && [[NetReachability sharedNetReachability] state]) {
[[NSUserDefaults standardUserDefaults] setInteger:(count + 1) forKey:kDefaultKey_LaunchCount];
if (!needLibraryUpdate && (count + 1 >= kLaunchCountBeforeRating) && !self.modalViewController && [[NetReachability sharedNetReachability] state]) {
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self performSelector:@selector(_showRatingScreen) withObject:nil afterDelay:kShowRatingDelay];
} else {
LOG_VERBOSE(@"Launch count is now %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultUserKey_LaunchCount]);
LOG_VERBOSE(@"Launch count is now %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LaunchCount]);
}
}

if (needLibraryUpdate) {
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"REQUIRE_UPDATE_TITLE", nil)
message:NSLocalizedString(@"REQUIRE_UPDATE_MESSAGE", nil)
confirmButton:NSLocalizedString(@"REQUIRE_UPDATE_CONTINUE", nil)
cancelButton:NSLocalizedString(@"REQUIRE_UPDATE_CANCEL", nil)
delegate:self
confirmSelector:@selector(_requireUpdate)
cancelSelector:NULL
argument:nil];
}
}

- (void) viewDidAppear:(BOOL)animated {
Expand Down Expand Up @@ -749,6 +772,13 @@ - (void) saveState {
[[NSUserDefaults standardUserDefaults] setInteger:_currentComic.sqlRowID forKey:kDefaultKey_CurrentComic];
}

- (void) _forceUpdate {
LoggingPurgeHistory(0.0);
[[LibraryUpdater sharedUpdater] update:YES];
[self _updateStatistics];
[self _setCurrentCollection:nil];
}

@end

@implementation LibraryViewController (LibraryUpdaterDelegate)
Expand Down Expand Up @@ -921,13 +951,6 @@ - (IBAction) update:(id)sender {
[[LibraryUpdater sharedUpdater] update:NO];
}

- (void) _forceUpdate {
LoggingPurgeHistory(0.0);
[[LibraryUpdater sharedUpdater] update:YES];
[self _updateStatistics];
[self _setCurrentCollection:nil];
}

- (IBAction) forceUpdate:(id)sender {
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"FORCE_UPDATE_TITLE", nil)
message:NSLocalizedString(@"FORCE_UPDATE_MESSAGE", nil)
Expand Down
5 changes: 4 additions & 1 deletion Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#define kDefaultKey_LibraryVersion @"libraryVersion"
#define kLibraryVersion 1

#define kDefaultKey_ServerEnabled @"serverEnabled"
#define kDefaultKey_ServerMode @"serverMode"
typedef enum {
Expand All @@ -38,4 +41,4 @@ typedef enum {
kSortingMode_ByStatus
} SortingMode;

#define kDefaultUserKey_LaunchCount @"launchCount"
#define kDefaultKey_LaunchCount @"launchCount"
10 changes: 5 additions & 5 deletions Resources/eng.lproj/LibraryViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
<size key="titleShadowOffset" width="0.0" height="1"/>
<state key="normal" title="Regenerate Library"/>
<state key="normal" title="Recreate Library"/>
<connections>
<action selector="forceUpdate:" destination="-1" eventType="touchUpInside" id="38"/>
</connections>
Expand All @@ -100,14 +100,14 @@
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="54">
<rect key="frame" x="177" y="419" width="51" height="31"/>
<rect key="frame" x="187" y="419" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="updateServer:" destination="-1" eventType="valueChanged" id="71"/>
</connections>
</switch>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Web Server" textAlignment="right" lineBreakMode="tailTruncation" minimumFontSize="10" id="55">
<rect key="frame" x="48" y="424" width="106" height="21"/>
<rect key="frame" x="58" y="424" width="106" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
<color key="textColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -158,14 +158,14 @@
</connections>
</button>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="91">
<rect key="frame" x="177" y="20" width="51" height="31"/>
<rect key="frame" x="187" y="20" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleDimming:" destination="-1" eventType="valueChanged" id="96"/>
</connections>
</switch>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Dim Screen" textAlignment="right" lineBreakMode="tailTruncation" minimumFontSize="10" id="92">
<rect key="frame" x="43" y="25" width="111" height="21"/>
<rect key="frame" x="53" y="25" width="111" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
<color key="textColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
Expand Down
7 changes: 6 additions & 1 deletion Resources/eng.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@

"LABEL_FORMAT" = "Page %i of %i";

"REQUIRE_UPDATE_TITLE" = "Library must be recreated";
"REQUIRE_UPDATE_MESSAGE" = "All comics and series will be re-imported to be updated to the new look and bookmarks will be cleared.";
"REQUIRE_UPDATE_CANCEL" = "Remind Me Later";
"REQUIRE_UPDATE_CONTINUE" = "Recreate Now";

"FORCE_UPDATE_TITLE" = "Are you sure?";
"FORCE_UPDATE_MESSAGE" = "Regenerating the library will clear all bookmarks and re-import all comics and series.";
"FORCE_UPDATE_MESSAGE" = "Recreating the library will clear all bookmarks and re-import all comics and series.";
"FORCE_UPDATE_CANCEL" = "Cancel";
"FORCE_UPDATE_CONTINUE" = "Continue";

Expand Down

0 comments on commit 3d70439

Please sign in to comment.