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

Commit 3d70439

Browse files
committed
Prompt to recreate library when upgrading app in place
1 parent 9dfe96f commit 3d70439

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

Classes/AppDelegate.m

+3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ @implementation AppDelegate
171171
+ (void) initialize {
172172
// Setup initial user defaults
173173
NSMutableDictionary* defaults = [[NSMutableDictionary alloc] init];
174+
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_LibraryVersion];
174175
[defaults setObject:[NSNumber numberWithBool:NO] forKey:kDefaultKey_ServerEnabled];
175176
[defaults setObject:[NSNumber numberWithInteger:kServerMode_Trial] forKey:kDefaultKey_ServerMode];
176177
[defaults setObject:[NSNumber numberWithInteger:kTrialMaxUploads] forKey:kDefaultKey_UploadsRemaining];
@@ -180,6 +181,7 @@ + (void) initialize {
180181
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_CurrentCollection];
181182
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_CurrentComic];
182183
[defaults setObject:[NSNumber numberWithInteger:kSortingMode_ByStatus] forKey:kDefaultKey_SortingMode];
184+
[defaults setObject:[NSNumber numberWithInteger:0] forKey:kDefaultKey_LaunchCount];
183185
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
184186
[defaults release];
185187

@@ -237,6 +239,7 @@ - (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(
237239
// Update library immediately
238240
if ([[LibraryConnection mainConnection] countObjectsOfClass:[Comic class]] == 0) {
239241
[[LibraryUpdater sharedUpdater] update:YES];
242+
[[NSUserDefaults standardUserDefaults] setInteger:kLibraryVersion forKey:kDefaultKey_LibraryVersion];
240243
} else {
241244
[[LibraryUpdater sharedUpdater] update:NO];
242245
}

Classes/LibraryViewController.m

+36-13
Original file line numberDiff line numberDiff line change
@@ -663,14 +663,14 @@ - (void) viewWillAppear:(BOOL)animated {
663663

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

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

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

676676
- (void) _showRatingScreen {
@@ -686,7 +686,19 @@ - (void) _showRatingScreen {
686686
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
687687
}
688688

689+
- (void) _requireUpdate {
690+
[self _forceUpdate];
691+
[[NSUserDefaults standardUserDefaults] setInteger:kLibraryVersion forKey:kDefaultKey_LibraryVersion];
692+
}
693+
689694
- (void) _viewDidReallyAppear {
695+
BOOL needLibraryUpdate = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LibraryVersion] != kLibraryVersion;
696+
if (needLibraryUpdate) {
697+
LOG_VERBOSE(@"Library is outdated at version %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LibraryVersion]);
698+
[_currentComic release];
699+
_currentComic = nil;
700+
}
701+
690702
if (_currentComic) {
691703
Comic* comic = [[_currentComic retain] autorelease];
692704
[_currentComic release];
@@ -707,16 +719,27 @@ - (void) _viewDidReallyAppear {
707719
}];
708720
_launchView = nil;
709721

710-
NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultUserKey_LaunchCount];
722+
NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LaunchCount];
711723
if (count >= 0) {
712-
[[NSUserDefaults standardUserDefaults] setInteger:(count + 1) forKey:kDefaultUserKey_LaunchCount];
713-
if ((count + 1 >= kLaunchCountBeforeRating) && !self.modalViewController && [[NetReachability sharedNetReachability] state]) {
724+
[[NSUserDefaults standardUserDefaults] setInteger:(count + 1) forKey:kDefaultKey_LaunchCount];
725+
if (!needLibraryUpdate && (count + 1 >= kLaunchCountBeforeRating) && !self.modalViewController && [[NetReachability sharedNetReachability] state]) {
714726
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
715727
[self performSelector:@selector(_showRatingScreen) withObject:nil afterDelay:kShowRatingDelay];
716728
} else {
717-
LOG_VERBOSE(@"Launch count is now %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultUserKey_LaunchCount]);
729+
LOG_VERBOSE(@"Launch count is now %i", [[NSUserDefaults standardUserDefaults] integerForKey:kDefaultKey_LaunchCount]);
718730
}
719731
}
732+
733+
if (needLibraryUpdate) {
734+
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"REQUIRE_UPDATE_TITLE", nil)
735+
message:NSLocalizedString(@"REQUIRE_UPDATE_MESSAGE", nil)
736+
confirmButton:NSLocalizedString(@"REQUIRE_UPDATE_CONTINUE", nil)
737+
cancelButton:NSLocalizedString(@"REQUIRE_UPDATE_CANCEL", nil)
738+
delegate:self
739+
confirmSelector:@selector(_requireUpdate)
740+
cancelSelector:NULL
741+
argument:nil];
742+
}
720743
}
721744

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

775+
- (void) _forceUpdate {
776+
LoggingPurgeHistory(0.0);
777+
[[LibraryUpdater sharedUpdater] update:YES];
778+
[self _updateStatistics];
779+
[self _setCurrentCollection:nil];
780+
}
781+
752782
@end
753783

754784
@implementation LibraryViewController (LibraryUpdaterDelegate)
@@ -921,13 +951,6 @@ - (IBAction) update:(id)sender {
921951
[[LibraryUpdater sharedUpdater] update:NO];
922952
}
923953

924-
- (void) _forceUpdate {
925-
LoggingPurgeHistory(0.0);
926-
[[LibraryUpdater sharedUpdater] update:YES];
927-
[self _updateStatistics];
928-
[self _setCurrentCollection:nil];
929-
}
930-
931954
- (IBAction) forceUpdate:(id)sender {
932955
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"FORCE_UPDATE_TITLE", nil)
933956
message:NSLocalizedString(@"FORCE_UPDATE_MESSAGE", nil)

Defaults.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
#define kDefaultKey_LibraryVersion @"libraryVersion"
18+
#define kLibraryVersion 1
19+
1720
#define kDefaultKey_ServerEnabled @"serverEnabled"
1821
#define kDefaultKey_ServerMode @"serverMode"
1922
typedef enum {
@@ -38,4 +41,4 @@ typedef enum {
3841
kSortingMode_ByStatus
3942
} SortingMode;
4043

41-
#define kDefaultUserKey_LaunchCount @"launchCount"
44+
#define kDefaultKey_LaunchCount @"launchCount"

Resources/eng.lproj/LibraryViewController.xib

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
8888
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
8989
<size key="titleShadowOffset" width="0.0" height="1"/>
90-
<state key="normal" title="Regenerate Library"/>
90+
<state key="normal" title="Recreate Library"/>
9191
<connections>
9292
<action selector="forceUpdate:" destination="-1" eventType="touchUpInside" id="38"/>
9393
</connections>
@@ -100,14 +100,14 @@
100100
<nil key="highlightedColor"/>
101101
</label>
102102
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="54">
103-
<rect key="frame" x="177" y="419" width="51" height="31"/>
103+
<rect key="frame" x="187" y="419" width="51" height="31"/>
104104
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
105105
<connections>
106106
<action selector="updateServer:" destination="-1" eventType="valueChanged" id="71"/>
107107
</connections>
108108
</switch>
109109
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Web Server" textAlignment="right" lineBreakMode="tailTruncation" minimumFontSize="10" id="55">
110-
<rect key="frame" x="48" y="424" width="106" height="21"/>
110+
<rect key="frame" x="58" y="424" width="106" height="21"/>
111111
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
112112
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
113113
<color key="textColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
@@ -158,14 +158,14 @@
158158
</connections>
159159
</button>
160160
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="91">
161-
<rect key="frame" x="177" y="20" width="51" height="31"/>
161+
<rect key="frame" x="187" y="20" width="51" height="31"/>
162162
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
163163
<connections>
164164
<action selector="toggleDimming:" destination="-1" eventType="valueChanged" id="96"/>
165165
</connections>
166166
</switch>
167167
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Dim Screen" textAlignment="right" lineBreakMode="tailTruncation" minimumFontSize="10" id="92">
168-
<rect key="frame" x="43" y="25" width="111" height="21"/>
168+
<rect key="frame" x="53" y="25" width="111" height="21"/>
169169
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
170170
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
171171
<color key="textColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>

Resources/eng.lproj/Localizable.strings

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@
3636

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

39+
"REQUIRE_UPDATE_TITLE" = "Library must be recreated";
40+
"REQUIRE_UPDATE_MESSAGE" = "All comics and series will be re-imported to be updated to the new look and bookmarks will be cleared.";
41+
"REQUIRE_UPDATE_CANCEL" = "Remind Me Later";
42+
"REQUIRE_UPDATE_CONTINUE" = "Recreate Now";
43+
3944
"FORCE_UPDATE_TITLE" = "Are you sure?";
40-
"FORCE_UPDATE_MESSAGE" = "Regenerating the library will clear all bookmarks and re-import all comics and series.";
45+
"FORCE_UPDATE_MESSAGE" = "Recreating the library will clear all bookmarks and re-import all comics and series.";
4146
"FORCE_UPDATE_CANCEL" = "Cancel";
4247
"FORCE_UPDATE_CONTINUE" = "Continue";
4348

0 commit comments

Comments
 (0)