Brion VIBBER has uploaded a new change for review. https://gerrit.wikimedia.org/r/184716
Change subject: [Work in progress] Activity indicator and background thread for conversion ...................................................................... [Work in progress] Activity indicator and background thread for conversion Currently doesn't hide the indicator view when done. Not sure why. Change-Id: If385e41c31efe639f026ed05ba0bffddb4e72138 --- M Wikipedia.xcodeproj/project.pbxproj A wikipedia/View Controllers/DataMigration/DataMigrationProgress.h A wikipedia/View Controllers/DataMigration/DataMigrationProgress.m A wikipedia/View Controllers/DataMigration/DataMigrationProgress.xib M wikipedia/View Controllers/WebView/WebViewController.h M wikipedia/View Controllers/WebView/WebViewController.m 6 files changed, 241 insertions(+), 61 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/16/184716/1 diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index 11098ab..11449b3 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -180,6 +180,8 @@ 04F27B7818FE0F2E00EDD838 /* PageHistoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F27B7418FE0F2E00EDD838 /* PageHistoryViewController.m */; }; 04F39590186CF80100B0D6FC /* TOCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F3958F186CF80100B0D6FC /* TOCViewController.m */; }; C9180EC418AED30C006C1DCA /* WikipediaAppUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = C9180EC318AED30C006C1DCA /* WikipediaAppUtils.m */; }; + D401C2C01A659E5000D4D127 /* DataMigrationProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = D401C2BE1A659E5000D4D127 /* DataMigrationProgress.m */; }; + D401C2C11A659E5000D4D127 /* DataMigrationProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = D401C2BF1A659E5000D4D127 /* DataMigrationProgress.xib */; }; D407E6411A51DBDA00CCC8B1 /* SchemaConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = D407E6401A51DBDA00CCC8B1 /* SchemaConverter.m */; }; D42E75EB18D11237002EA7E5 /* MWLanguageInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E75EA18D11237002EA7E5 /* MWLanguageInfo.m */; }; D46CD8C418A1AC4F0042959E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D46CD8C018A1AC4F0042959E /* InfoPlist.strings */; }; @@ -614,6 +616,9 @@ 04F3958F186CF80100B0D6FC /* TOCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TOCViewController.m; sourceTree = "<group>"; }; C9180EC218AED30C006C1DCA /* WikipediaAppUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WikipediaAppUtils.h; sourceTree = "<group>"; }; C9180EC318AED30C006C1DCA /* WikipediaAppUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WikipediaAppUtils.m; sourceTree = "<group>"; }; + D401C2BD1A659E5000D4D127 /* DataMigrationProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataMigrationProgress.h; path = DataMigration/DataMigrationProgress.h; sourceTree = "<group>"; }; + D401C2BE1A659E5000D4D127 /* DataMigrationProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DataMigrationProgress.m; path = DataMigration/DataMigrationProgress.m; sourceTree = "<group>"; }; + D401C2BF1A659E5000D4D127 /* DataMigrationProgress.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = DataMigrationProgress.xib; path = DataMigration/DataMigrationProgress.xib; sourceTree = "<group>"; }; D407E63F1A51DBDA00CCC8B1 /* SchemaConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SchemaConverter.h; path = wikipedia/Data/SchemaConverter.h; sourceTree = SOURCE_ROOT; }; D407E6401A51DBDA00CCC8B1 /* SchemaConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SchemaConverter.m; path = wikipedia/Data/SchemaConverter.m; sourceTree = SOURCE_ROOT; }; D42E75E918D11237002EA7E5 /* MWLanguageInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MWLanguageInfo.h; path = "mw-support/MWLanguageInfo.h"; sourceTree = "<group>"; }; @@ -1370,6 +1375,7 @@ 04A97E8418B81D440046B166 /* AccountCreation */, 04B7B9BA18B5569600A63551 /* Captcha */, 043DAC481901C3D2001CD17C /* Credits */, + D401C2B71A659DD600D4D127 /* DataMigration */, 041C55CF1950B260006CE0EF /* EditSummary */, 0447861F185145090050563B /* History */, 041A3B5718E11ED90079FF1C /* Languages */, @@ -1606,6 +1612,16 @@ C9180EC318AED30C006C1DCA /* WikipediaAppUtils.m */, ); path = "mw-utils"; + sourceTree = "<group>"; + }; + D401C2B71A659DD600D4D127 /* DataMigration */ = { + isa = PBXGroup; + children = ( + D401C2BD1A659E5000D4D127 /* DataMigrationProgress.h */, + D401C2BE1A659E5000D4D127 /* DataMigrationProgress.m */, + D401C2BF1A659E5000D4D127 /* DataMigrationProgress.xib */, + ); + name = DataMigration; sourceTree = "<group>"; }; D497FCF01A0807ED004A36A5 /* Products */ = { @@ -1999,6 +2015,7 @@ 0487041419F7683300B7D307 /* Cocoapods Notes.txt in Resources */, D46CD8C518A1AC4F0042959E /* Localizable.strings in Resources */, 04082B5318ADA25A00FAF3D6 /* text_field_x_circle_gray.png in Resources */, + D401C2C11A659E5000D4D127 /* DataMigrationProgress.xib in Resources */, 04EDEE251A20788700798076 /* SearchResultPrototypeView.xib in Resources */, 04478631185145090050563B /* HistoryResultPrototypeView.xib in Resources */, 0493C2D619526FFE00EBB973 /* WikiFont-Glyphs-iOS.ttf in Resources */, @@ -2217,6 +2234,7 @@ 04B6925018E77B2A00F88D8A /* UIWebView+HideScrollGradient.m in Sources */, 047E95511996DD030046A122 /* NearbyViewController.m in Sources */, 04AE520519DB5E0900F89B92 /* NSObject+ConstraintsScale.m in Sources */, + D401C2C01A659E5000D4D127 /* DataMigrationProgress.m in Sources */, 04CCCFF01935093A00E3F60C /* SecondaryMenuViewController.m in Sources */, D4B0AE0B19366A2C00F0AC90 /* ReadingActionFunnel.m in Sources */, 0452C810195D0F03007925A6 /* UIViewController+ModalPop.m in Sources */, diff --git a/wikipedia/View Controllers/DataMigration/DataMigrationProgress.h b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.h new file mode 100644 index 0000000..a4a8e6e --- /dev/null +++ b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.h @@ -0,0 +1,26 @@ +// +// DataMigrationProgress.h +// Wikipedia +// +// Created by Brion on 1/13/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +#import <UIKit/UIKit.h> + +@class DataMigrationProgress; + +@protocol DataMigrationProgressDelegete +-(void)dataMigrationProgressComplete:(DataMigrationProgress *)viewController; +@end + + +@interface DataMigrationProgress : UIViewController + +@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *progressIndicator; +@property (weak, nonatomic) IBOutlet UILabel *progressLabel; +@property (weak, nonatomic) id<DataMigrationProgressDelegete> delegate; + +-(BOOL)needsMigration; + +@end diff --git a/wikipedia/View Controllers/DataMigration/DataMigrationProgress.m b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.m new file mode 100644 index 0000000..63b7eea --- /dev/null +++ b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.m @@ -0,0 +1,122 @@ +// +// DataMigrationProgress.m +// Wikipedia +// +// Created by Brion on 1/13/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +#import "DataMigrationProgress.h" + +#import "SessionSingleton.h" + +#import "OldDataSchema.h" +#import "SchemaConverter.h" + +#import "DataMigrator.h" +#import "ArticleImporter.h" + + +@interface DataMigrationProgress () + +@property (readonly) OldDataSchema *oldDataSchema; +@property (readonly) DataMigrator *dataMigrator; + +@end + +@implementation DataMigrationProgress { + OldDataSchema *_oldDataSchema; + DataMigrator *_dataMigrator; +} + + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +-(void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + + [self asyncMigration]; +} + +-(OldDataSchema *)oldDataSchema +{ + if (_oldDataSchema == nil) { + _oldDataSchema = [[OldDataSchema alloc] init]; + } + return _oldDataSchema; +} + +-(DataMigrator *)dataMigrator +{ + if (_dataMigrator == nil) { + _dataMigrator = [[DataMigrator alloc] init]; + } + return _dataMigrator; +} + +-(BOOL)needsMigration +{ + return [self.oldDataSchema exists] || [self.dataMigrator hasData]; +} + +-(void)syncMigration +{ + // Middle-Ages Converter + // From the native app's initial CoreData-based implementation, + // which now lives in OldDataSchema subproject. + if ([self.oldDataSchema exists]) { + SchemaConverter *schemaConverter = [[SchemaConverter alloc] initWithDataStore:[SessionSingleton sharedInstance].dataStore]; + self.oldDataSchema.delegate = schemaConverter; + NSLog(@"begin migration"); + [self.oldDataSchema migrateData]; + NSLog(@"end migration"); + + [self.oldDataSchema removeOldData]; + + // hack for history fix + [[SessionSingleton sharedInstance].userDataStore reset]; + + return; + } + + // Ye Ancient Converter + // From the old PhoneGap app + // @fixme: fix this to work again + if ([self.dataMigrator hasData]) { + NSLog(@"Old data to migrate found!"); + NSArray *titles = [self.dataMigrator extractSavedPages]; + ArticleImporter *importer = [[ArticleImporter alloc] init]; + + for (NSDictionary *item in titles) { + NSLog(@"Will import saved page: %@ %@", item[@"lang"], item[@"title"]); + } + + [importer importArticles:titles]; + + [self.dataMigrator removeOldData]; + + return; + } + + NSLog(@"No old data to migrate."); +} + +-(void)asyncMigration +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() { + [self syncMigration]; + dispatch_async(dispatch_get_main_queue(), ^() { + [self.delegate dataMigrationProgressComplete:self]; + }); + }); +} +@end diff --git a/wikipedia/View Controllers/DataMigration/DataMigrationProgress.xib b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.xib new file mode 100644 index 0000000..c0ef14c --- /dev/null +++ b/wikipedia/View Controllers/DataMigration/DataMigrationProgress.xib @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES"> + <dependencies> + <deployment identifier="iOS"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> + </dependencies> + <objects> + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DataMigrationProgress"> + <connections> + <outlet property="progressIndicator" destination="59a-LK-cye" id="lQE-94-AB0"/> + <outlet property="progressLabel" destination="9Bj-11-8XX" id="ek2-9N-3Sx"/> + <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> + </connections> + </placeholder> + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> + <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> + <rect key="frame" x="0.0" y="0.0" width="320" height="568"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="59a-LK-cye"> + <rect key="frame" x="150" y="274" width="20" height="20"/> + </activityIndicatorView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9Bj-11-8XX"> + <fontDescription key="fontDescription" type="system" pointSize="17"/> + <color key="textColor" cocoaTouchSystemColor="darkTextColor"/> + <nil key="highlightedColor"/> + </label> + </subviews> + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> + <constraints> + <constraint firstAttribute="centerY" secondItem="59a-LK-cye" secondAttribute="centerY" id="N5m-um-eCk"/> + <constraint firstAttribute="centerX" secondItem="59a-LK-cye" secondAttribute="centerX" id="N9Z-be-UDt"/> + <constraint firstAttribute="centerX" secondItem="9Bj-11-8XX" secondAttribute="centerX" id="cRM-yQ-ug6"/> + <constraint firstItem="9Bj-11-8XX" firstAttribute="top" secondItem="59a-LK-cye" secondAttribute="bottom" constant="8" id="rG3-Pf-Ut1"/> + </constraints> + <point key="canvasLocation" x="673" y="442"/> + </view> + </objects> + <simulatedMetricsContainer key="defaultSimulatedMetrics"> + <simulatedStatusBarMetrics key="statusBar"/> + <simulatedOrientationMetrics key="orientation"/> + <simulatedScreenMetrics key="destination" type="retina4"/> + </simulatedMetricsContainer> +</document> diff --git a/wikipedia/View Controllers/WebView/WebViewController.h b/wikipedia/View Controllers/WebView/WebViewController.h index 586db74..71fd2fc 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.h +++ b/wikipedia/View Controllers/WebView/WebViewController.h @@ -6,10 +6,11 @@ #import "PullToRefreshViewController.h" #import "ArticleFetcher.h" #import "LeadImageContainer.h" +#import "DataMigrationProgress.h" @class BottomMenuViewController, CommunicationBridge; -@interface WebViewController : PullToRefreshViewController <UIWebViewDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate, UIAlertViewDelegate, FetchFinishedDelegate, LeadImageHeightDelegate> +@interface WebViewController : PullToRefreshViewController <UIWebViewDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate, UIAlertViewDelegate, FetchFinishedDelegate, LeadImageHeightDelegate, DataMigrationProgressDelegete> @property (weak, nonatomic) IBOutlet UIWebView *webView; @property (nonatomic) BOOL bottomMenuHidden; diff --git a/wikipedia/View Controllers/WebView/WebViewController.m b/wikipedia/View Controllers/WebView/WebViewController.m index 0b3b6d9..0274c0d 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -24,8 +24,6 @@ #import "UIViewController+Alert.h" #import "NSString+Extras.h" #import "PaddedLabel.h" -#import "DataMigrator.h" -#import "ArticleImporter.h" #import "RootViewController.h" #import "TopMenuViewController.h" #import "BottomMenuViewController.h" @@ -54,8 +52,7 @@ #import "AssetsFileFetcher.h" #import "LeadImageContainer.h" -#import "OldDataSchema.h" -#import "SchemaConverter.h" +#import "DataMigrationProgress.h" //#import "UIView+Debugging.h" @@ -250,11 +247,6 @@ // bottom of the web view if toc quickly dragged on and offscreen. self.webView.opaque = NO; - // This is the first view that's opened when the app opens... - // Perform any first-time data migration as needed. - [self migrateDataIfNecessary]; - - self.bottomBarViewBottomConstraint = nil; self.view.backgroundColor = CHROME_COLOR; @@ -314,24 +306,47 @@ { [super viewDidAppear:animated]; + // This is the first view that's opened when the app opens... + // Perform any first-time data migration as needed. + DataMigrationProgress *migrationVC = [[DataMigrationProgress alloc] initWithNibName:@"DataMigrationProgress" bundle:nil]; + if ([migrationVC needsMigration]) { + migrationVC.delegate = self; + [ROOT presentViewController:migrationVC animated:YES completion:nil]; + } else { + [self doStuffOnAppear]; + } +} + +-(void)dataMigrationProgressComplete:(DataMigrationProgress *)viewController +{ + [ROOT popToViewController:self animated:NO]; + NSLog(@"it should hide now"); + + [self doStuffOnAppear]; +} + +-(void)doStuffOnAppear +{ if ([self shouldShowOnboarding]) { [self showOnboarding]; - + // Ok to show the menu now. (The onboarding view is covering the web view at this point.) ROOT.topMenuHidden = NO; - + self.webView.alpha = 1.0f; } - + // Don't move this to viewDidLoad - this is because viewDidLoad may only get // called very occasionally as app suspend/resume probably doesn't cause // viewDidLoad to fire. [self downloadAssetsFilesIfNecessary]; - + [self performHousekeepingIfNecessary]; - + //[self.view randomlyColorSubviews]; } + + -(BOOL)shouldShowOnboarding { @@ -1840,52 +1855,6 @@ (session.article != nil) && (!ROOT.isAnimatingTopAndBottomMenuHidden); -} - -#pragma mark Data migration - -- (void)migrateDataIfNecessary -{ - // Middle-Ages Converter - // From the native app's initial CoreData-based implementation, - // which now lives in OldDataSchema subproject. - OldDataSchema *oldDataSchema = [[OldDataSchema alloc] init]; - if ([oldDataSchema exists]) { - SchemaConverter *schemaConverter = [[SchemaConverter alloc] initWithDataStore:session.dataStore]; - oldDataSchema.delegate = schemaConverter; - NSLog(@"begin migration"); - [oldDataSchema migrateData]; - NSLog(@"end migration"); - - [oldDataSchema removeOldData]; - - // hack for history fix - [session.userDataStore reset]; - - return; - } - - // Ye Ancient Converter - // From the old PhoneGap app - // @fixme: fix this to work again - DataMigrator *dataMigrator = [[DataMigrator alloc] init]; - if ([dataMigrator hasData]) { - NSLog(@"Old data to migrate found!"); - NSArray *titles = [dataMigrator extractSavedPages]; - ArticleImporter *importer = [[ArticleImporter alloc] init]; - - for (NSDictionary *item in titles) { - NSLog(@"Will import saved page: %@ %@", item[@"lang"], item[@"title"]); - } - - [importer importArticles:titles]; - - [dataMigrator removeOldData]; - - return; - } - - NSLog(@"No old data to migrate."); } #pragma mark Bottom menu bar -- To view, visit https://gerrit.wikimedia.org/r/184716 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If385e41c31efe639f026ed05ba0bffddb4e72138 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits