Brion VIBBER has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/177676

Change subject: Convenience methods for retrieving all a section's images
......................................................................

Convenience methods for retrieving all a section's images

Uncomment the showImageToggle to test

Change-Id: Id7194517a13224aca2f5e17e869bf156f601e2ab
---
M MediaWikiKit/MediaWikiKit/MWKArticleStore.h
M MediaWikiKit/MediaWikiKit/MWKArticleStore.m
M MediaWikiKit/MediaWikiKit/MWKImageList.h
M MediaWikiKit/MediaWikiKit/MWKImageList.m
M wikipedia/View Controllers/WebView/WebViewController.m
5 files changed, 45 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/76/177676/1

diff --git a/MediaWikiKit/MediaWikiKit/MWKArticleStore.h 
b/MediaWikiKit/MediaWikiKit/MWKArticleStore.h
index 0501214..335a281 100644
--- a/MediaWikiKit/MediaWikiKit/MWKArticleStore.h
+++ b/MediaWikiKit/MediaWikiKit/MWKArticleStore.h
@@ -38,6 +38,10 @@
 @property (readwrite) MWKImage *thumbnailImage;
 @property (readonly) UIImage *thumbnailUIImage;
 
+-(NSArray *)imageURLsForSectionId:(int)sectionId;
+-(NSArray *)imagesForSectionId:(int)sectionId;
+-(NSArray *)UIImagesForSectionId:(int)sectionId;
+
 -(void)saveImageList;
 
 @property (readwrite) BOOL needsRefresh;
diff --git a/MediaWikiKit/MediaWikiKit/MWKArticleStore.m 
b/MediaWikiKit/MediaWikiKit/MWKArticleStore.m
index 3581d1c..dc3b598 100644
--- a/MediaWikiKit/MediaWikiKit/MWKArticleStore.m
+++ b/MediaWikiKit/MediaWikiKit/MWKArticleStore.m
@@ -243,4 +243,28 @@
     }
 }
 
+-(NSArray *)imageURLsForSectionId:(int)sectionId
+{
+    return [self.imageList imageURLsForSectionId:sectionId];
+}
+
+-(NSArray *)imagesForSectionId:(int)sectionId
+{
+    NSMutableArray *arr = [[NSMutableArray alloc] init];
+    for (NSString *url in [self imageURLsForSectionId:sectionId]) {
+        [arr addObject:[self imageWithURL:url]];
+    }
+    return [NSArray arrayWithArray:arr];
+}
+
+-(NSArray *)UIImagesForSectionId:(int)sectionId
+{
+    NSMutableArray *arr = [[NSMutableArray alloc] init];
+    for (MWKImage *image in [self imagesForSectionId:sectionId]) {
+        [arr addObject:[self UIImageWithImage:image]];
+    }
+    return [NSArray arrayWithArray:arr];
+}
+
+
 @end
diff --git a/MediaWikiKit/MediaWikiKit/MWKImageList.h 
b/MediaWikiKit/MediaWikiKit/MWKImageList.h
index 280b297..eb8109a 100644
--- a/MediaWikiKit/MediaWikiKit/MWKImageList.h
+++ b/MediaWikiKit/MediaWikiKit/MWKImageList.h
@@ -25,5 +25,7 @@
 -(BOOL)hasImageURL:(NSString *)imageURL;
 -(NSString *)largestImageVariant:(NSString *)image;
 
+-(NSArray *)imageURLsForSectionId:(int)sectionId;
+
 @property (readwrite)NSString *thumbnailURL;
 @end
diff --git a/MediaWikiKit/MediaWikiKit/MWKImageList.m 
b/MediaWikiKit/MediaWikiKit/MWKImageList.m
index 265775b..e1fcfff 100644
--- a/MediaWikiKit/MediaWikiKit/MWKImageList.m
+++ b/MediaWikiKit/MediaWikiKit/MWKImageList.m
@@ -78,6 +78,11 @@
     return biggestURL;
 }
 
+-(NSArray *)imageURLsForSectionId:(int)sectionId
+{
+    return [[self entriesBySection:sectionId] copy];
+}
+
 #pragma mark - data i/o
 
 -(instancetype)initWithTitle:(MWKTitle *)title
diff --git a/wikipedia/View Controllers/WebView/WebViewController.m 
b/wikipedia/View Controllers/WebView/WebViewController.m
index b226289..f6201e6 100644
--- a/wikipedia/View Controllers/WebView/WebViewController.m
+++ b/wikipedia/View Controllers/WebView/WebViewController.m
@@ -1333,20 +1333,15 @@
     showImageSheet = !showImageSheet;
     
     if(showImageSheet){
-        /*
-        NSManagedObjectContext *ctx = articleDataContext_.mainContext;
-        [ctx performBlockAndWait:^(){
-            NSManagedObjectID *articleID =
-            [ctx getArticleIDForTitle: session.currentArticleTitle
-                               domain: session.currentArticleDomain];
-            Article *article = (Article *)[ctx objectWithID:articleID];
-            NSArray *sectionImages = [article 
getSectionImagesUsingContext:ctx];
+        MWKArticleStore *articleStore = session.articleStore;
+        for (MWKSection *section in articleStore.sections) {
+            NSArray *sectionImages = [articleStore 
UIImagesForSectionId:section.sectionId];
             NSMutableArray *views = @[].mutableCopy;
-            for (SectionImage *sectionImage in sectionImages) {
-                Section *section = sectionImage.section;
-                NSString *title = (section.title.length > 0) ? section.title : 
session.currentArticleTitle;
+            int index = 0;
+            for (UIImage *image in sectionImages) {
+                NSString *title = (section.line) ? section.line : 
articleStore.title.prefixedText;
                 //NSLog(@"\n\n\nsection image = %@ \n\tsection = %@ \n\tindex 
in section = %@ \n\timage size = %@", sectionImage.image.fileName, 
sectionTitle, sectionImage.index, sectionImage.image.dataSize);
-                if(sectionImage.index.integerValue == 0){
+                if(index == 0){
                     PaddedLabel *label = [[PaddedLabel alloc] init];
                     label.padding = UIEdgeInsetsMake(20, 20, 10, 20);
                     label.numberOfLines = 0;
@@ -1358,15 +1353,15 @@
                     label.text = title;
                     [views addObject:label];
                 }
-                UIImageView *imageView = [[UIImageView alloc] 
initWithImage:[[UIImage alloc] initWithData:sectionImage.image.imageData.data]];
+                UIImageView *imageView = [[UIImageView alloc] 
initWithImage:image];
                 imageView.contentMode = UIViewContentModeScaleAspectFit;
                 [views addObject:imageView];
                 UIView *spacerView = [[UIView alloc] 
initWithFrame:CGRectMake(0, 0, 10, 5)];
                 [views addObject:spacerView];
+                index++;
             }
             [NAV topActionSheetShowWithViews:views 
orientation:TABULAR_SCROLLVIEW_LAYOUT_HORIZONTAL];
-        }];
-         */
+        }
     }else{
         [NAV topActionSheetHide];
     }

-- 
To view, visit https://gerrit.wikimedia.org/r/177676
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7194517a13224aca2f5e17e869bf156f601e2ab
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to