Brion VIBBER has uploaded a new change for review.
https://gerrit.wikimedia.org/r/88165
Change subject: Made details page license selectable for new images.
......................................................................
Made details page license selectable for new images.
Change-Id: Ib1061e91647310ee8ba9bfd2ea116b65c8b97560
---
M Commons-iOS.xcodeproj/project.pbxproj
M Commons-iOS/CommonsApp.m
M Commons-iOS/DetailScrollViewController.m
M Commons-iOS/FileUpload.h
M Commons-iOS/FileUpload.m
M Commons-iOS/FileUpload.xcdatamodeld/.xccurrentversion
M Commons-iOS/FileUpload.xcdatamodeld/FileUpload 3.xcdatamodel/contents
A Commons-iOS/FileUpload.xcdatamodeld/FileUpload 4.xcdatamodel/contents
8 files changed, 192 insertions(+), 44 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/ios/commons
refs/changes/65/88165/1
diff --git a/Commons-iOS.xcodeproj/project.pbxproj
b/Commons-iOS.xcodeproj/project.pbxproj
index 07c631c..e01e242 100644
--- a/Commons-iOS.xcodeproj/project.pbxproj
+++ b/Commons-iOS.xcodeproj/project.pbxproj
@@ -341,6 +341,7 @@
0417D9E9176E666B00081D8C /* GalleryMultiSelectCollectionVC.m */
= {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = GalleryMultiSelectCollectionVC.m; sourceTree =
"<group>"; };
0417D9EE176EB00000081D8C /* GalleryMultiSelectAlbumCell.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = GalleryMultiSelectAlbumCell.h; sourceTree = "<group>"; };
0417D9EF176EB00100081D8C /* GalleryMultiSelectAlbumCell.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = GalleryMultiSelectAlbumCell.m; sourceTree =
"<group>"; };
+ 0438EF0317FCCB96005F8BF5 /* FileUpload 4.xcdatamodel */ = {isa
= PBXFileReference; lastKnownFileType = file; path = "FileUpload
4.xcdatamodel"; sourceTree = "<group>"; };
044A0C3A170F6504003395DD /* GradientButton.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
GradientButton.h; sourceTree = "<group>"; };
044A0C3B170F6504003395DD /* GradientButton.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= GradientButton.m; sourceTree = "<group>"; };
0451C8601739A2CC00C2D03B /* FetchImageOperation.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
FetchImageOperation.h; sourceTree = "<group>"; };
@@ -1997,11 +1998,12 @@
D41B99ED16B1CB2E0045BEB5 /* FileUpload.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
+ 0438EF0317FCCB96005F8BF5 /* FileUpload
4.xcdatamodel */,
D41BFA46173AF10600472EC7 /* FileUpload
3.xcdatamodel */,
D4C5B4201720BCD700C40532 /* FileUpload
2.xcdatamodel */,
D41B99EE16B1CB2E0045BEB5 /*
FileUpload.xcdatamodel */,
);
- currentVersion = D41BFA46173AF10600472EC7 /* FileUpload
3.xcdatamodel */;
+ currentVersion = 0438EF0317FCCB96005F8BF5 /* FileUpload
4.xcdatamodel */;
path = FileUpload.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
diff --git a/Commons-iOS/CommonsApp.m b/Commons-iOS/CommonsApp.m
index fb4ac60..907c52d 100644
--- a/Commons-iOS/CommonsApp.m
+++ b/Commons-iOS/CommonsApp.m
@@ -683,6 +683,9 @@
if (_currentUploadOp.isLoggedIn) {
record.progress = @0.0f;
+
+ // In case license somehow is not set by now...
+ if (record.license == nil) record.license = @"cc-by-sa-3.0";
MWPromise *upload = [_currentUploadOp uploadFile:fileName
withFileData:fileData
@@ -763,12 +766,12 @@
NSString *format = @"== {{int:filedesc}} ==\n"
@"{{Information\n|description=%@\n|source={{own}}\n|author=[[User:%@|%2$@]]\n|date=%@}}\n"
@"== {{int:license-header}} ==\n"
- @"{{self|cc-by-sa-3.0}}\n"
+ @"{{self|%@}}\n"
@"\n"
@"{{Uploaded from Mobile|platform=iOS|version=%@}}\n"
@"%@";
NSString *cats = [self formatCategories:record];
- NSString *desc = [NSString stringWithFormat:format, record.desc,
self.username, [self formatDescriptionDate:record], self.version, cats];
+ NSString *desc = [NSString stringWithFormat:format, record.desc,
self.username, [self formatDescriptionDate:record], record.license,
self.version, cats];
return desc;
}
diff --git a/Commons-iOS/DetailScrollViewController.m
b/Commons-iOS/DetailScrollViewController.m
index 5f0058c..bf9b2a0 100644
--- a/Commons-iOS/DetailScrollViewController.m
+++ b/Commons-iOS/DetailScrollViewController.m
@@ -69,6 +69,9 @@
CFTimeInterval timeLastCategoryPan_;
CategoryLicenseExtractor *categoryLicenseExtractor_;
NSURL *licenseURL_;
+ NSArray *selectableLicenses_;
+ NSInteger selectedLicenseIndex_;
+ NSMutableArray *licenseLabels_;
}
#pragma mark - Init / dealloc
@@ -87,6 +90,9 @@
self.categoriesNeedToBeRefreshed = NO;
timeLastDetailsPan_ = CACurrentMediaTime();
timeLastCategoryPan_ = CACurrentMediaTime();
+ selectableLicenses_ = nil;
+ selectedLicenseIndex_ = 0;
+ licenseLabels_ = nil;
}
return self;
}
@@ -116,7 +122,10 @@
self.view.translatesAutoresizingMaskIntoConstraints = NO;
previewImage_ = nil;
-
+
+ // Load the list of licenses user may choose from
+ [self loadSelectableLicenses];
+
// Get the app delegate so the loading indicator may be accessed
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication]
delegate];
@@ -403,6 +412,146 @@
}
}
+#pragma mark - License retrieval
+
+- (void)getPreviouslySavedLicenseFromCategories:(NSMutableArray *)categories
+{
+ // Replaces "loading..." message in licenseDefaultLabel with name of
license or "Tap for license"
+ // message if no license found. If no license found makes "Tap for
license" actually link to the
+ // image's wiki page.
+
+ // Extract license from categories now that categories have been retrieved
+ NSString *license = [categoryLicenseExtractor_
getLicenseFromCategories:categories];
+
+ // If license was name was not retrieved change it to say "Tap for
License" for now
+ if (license == nil){
+ license = [MWMessage forKey:@"picture-of-day-tap-for-license"].text;
+
+ UITapGestureRecognizer *licenseTapGesture = [[UITapGestureRecognizer
alloc] initWithTarget:self action:@selector(handleLicenseTap:)];
+ [self.licenseDefaultLabel addGestureRecognizer:licenseTapGesture];
+
+ // Get the wiki url for the image
+ NSString *pageTitle = [@"File:"
stringByAppendingString:self.selectedRecord.title];
+ NSURL *wikiUrl = [CommonsApp.singleton URLForWikiPage:pageTitle];
+ licenseURL_ = wikiUrl;
+ }else{
+ licenseURL_ = [NSURL URLWithString:[categoryLicenseExtractor_
getURLForLicense:license]];
+ license = [license uppercaseString];
+ }
+
+ // Update licenseDefaultLabel to show name of found license
+ self.licenseDefaultLabel.text = license;
+}
+
+#pragma mark - License choices
+
+-(void)updateLicenseContainer{
+ // Presents and constrains a label for each license choice.
+
+ //NSLog(@"license from record = %@", self.selectedRecord.license);
+
+ if (self.selectedRecord.license == nil) self.selectedRecord.license =
@"cc-by-sa-3.0";
+ selectedLicenseIndex_ = [self getSelectedRecordLicenseIndex];
+
+ // Remove the "Loading..." label
+ [self.licenseDefaultLabel removeFromSuperview];
+
+ licenseLabels_ = [@[] mutableCopy];
+ UIView *labelAbove = self.licenseLabel;
+ NSInteger tag = 0;
+ for (NSDictionary *license in selectableLicenses_) {
+ UILabelDynamicHeight *label = [[UILabelDynamicHeight alloc] init];
+ label.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.licenseContainer addSubview:label];
+ [self styleDetailsLabel:label];
+ [licenseLabels_ addObject:label];
+
+ label.text = license[@"description"];
+
+ [self.licenseContainer addSubview:label];
+ label.tag = tag++;
+
+ // Constrain each license label appropriately
+ [self.licenseContainer addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-[label]-|" options:0 metrics:nil
views:@{@"label": label}]];
+
+ NSString *formatString = @"V:[labelAbove]-[label]";
+ if (selectableLicenses_.lastObject == license) {
+ formatString = [formatString stringByAppendingString:@"-|"];
+ }
+
+ [self.licenseContainer addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:formatString options:0 metrics:nil
views:@{@"label": label, @"labelAbove": labelAbove}]];
+ labelAbove = label;
+
+ // Make label respond to taps
+ UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(licenseSelectionTapped:)];
+ [label addGestureRecognizer:tapGesture];
+
+ // Make the selected license appear highlighted
+ [self setLicenseSelectionIndication:label];
+ }
+}
+
+#pragma mark - License selection
+
+-(void) loadSelectableLicenses
+{
+ // The list of licenses to be chosen from.
+ selectableLicenses_ = @[
+ @{
+ @"license" :@"cc-by-sa-3.0",
+ @"description": @"Creative Commons Attribution
ShareAlike 3.0"
+ },
+ @{
+ @"license" :@"cc-by-3.0",
+ @"description": @"Creative Commons Attribution
3.0"
+ },
+ @{
+ @"license" :@"cc-zero",
+ @"description": @"Creative Commons CC0 Waiver"
+ }
+ ];
+}
+
+-(void)licenseSelectionTapped:(UITapGestureRecognizer *)recognizer
+{
+ NSLog(@"license selected = %d", recognizer.view.tag);
+ selectedLicenseIndex_ = recognizer.view.tag;
+ if (!(selectedLicenseIndex_ < selectableLicenses_.count)) {
+ selectedLicenseIndex_ = 0;
+ }
+ NSDictionary *selectedLicense =
selectableLicenses_[selectedLicenseIndex_];
+ self.selectedRecord.license = selectedLicense[@"license"];
+
+ // Add the license to categories too (needed since we're pulling license
info from categories)
+ [self.selectedRecord addCategory:[selectedLicense[@"license"]
uppercaseString]];
+
+ for (UILabelDynamicHeight *label in licenseLabels_) {
+ [self setLicenseSelectionIndication:label];
+ }
+}
+
+-(NSInteger)getSelectedRecordLicenseIndex
+{
+ // Looks for self.selectedRecord.license in selectableLicenses_ and
returns index of match.
+ NSInteger index = 0;
+ for (NSDictionary *license in selectableLicenses_) {
+ if ([license[@"license"] isEqualToString:self.selectedRecord.license])
{
+ return index;
+ }
+ index++;
+ }
+ return index;
+}
+
+-(void)setLicenseSelectionIndication:(UILabelDynamicHeight *)label
+{
+ if (label.tag == selectedLicenseIndex_){
+ label.borderView.layer.borderWidth = 2.0f;
+ }else{
+ label.borderView.layer.borderWidth = 0.0f;
+ }
+}
+
#pragma mark - Selected record
-(void)configureForSelectedRecord
@@ -429,10 +578,8 @@
});
}else{
[self updateCategoryContainer];
-
-// new pic! add list of licenses to be chosen from here
-
+ [self updateLicenseContainer];
}
dispatch_async(dispatch_get_main_queue(), ^(void) {
@@ -900,39 +1047,6 @@
}];
}
-#pragma mark - License retrieval
-
-- (void)getPreviouslySavedLicenseFromCategories:(NSMutableArray *)categories
-{
- // Replaces "loading..." message in licenseDefaultLabel with name of
license or "Tap for license"
- // message if no license found. If no license found makes "Tap for
license" actually link to the
- // image's wiki page.
-
- // Extract license from categories now that categories have been retrieved
- NSString *license = [categoryLicenseExtractor_
getLicenseFromCategories:categories];
-
-//license = nil;
-
- // If license was name was not retrieved change it to say "Tap for
License" for now
- if (license == nil){
- license = [MWMessage forKey:@"picture-of-day-tap-for-license"].text;
-
- UITapGestureRecognizer *licenseTapGesture = [[UITapGestureRecognizer
alloc] initWithTarget:self action:@selector(handleLicenseTap:)];
- [self.licenseDefaultLabel addGestureRecognizer:licenseTapGesture];
-
- // Get the wiki url for the image
- NSString *pageTitle = [@"File:"
stringByAppendingString:self.selectedRecord.title];
- NSURL *wikiUrl = [CommonsApp.singleton URLForWikiPage:pageTitle];
- licenseURL_ = wikiUrl;
- }else{
- licenseURL_ = [NSURL URLWithString:[categoryLicenseExtractor_
getURLForLicense:license]];
- license = [license uppercaseString];
- }
-
- // Update licenseDefaultLabel to show name of found license
- self.licenseDefaultLabel.text = license;
-}
-
#pragma mark - Category retrieval
- (void)getPreviouslySavedCategoriesForRecord:(FileUpload *)record
@@ -1103,6 +1217,7 @@
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.borderColor = [UIColor clearColor];
+ label.borderView.layer.borderColor = [UIColor colorWithWhite:1.0f
alpha:0.8f].CGColor;
label.paddingColor = DETAIL_NON_EDITABLE_TEXTBOX_BACKGROUND_COLOR;
[label setPaddingInsets:DETAIL_CATEGORY_PADDING_INSET];
}
diff --git a/Commons-iOS/FileUpload.h b/Commons-iOS/FileUpload.h
index 302e880..a9f46f3 100644
--- a/Commons-iOS/FileUpload.h
+++ b/Commons-iOS/FileUpload.h
@@ -24,6 +24,7 @@
@property (nonatomic, retain) NSString * source;
@property (nonatomic, retain) NSString * thumbnailURL;
@property (nonatomic, retain) NSNumber * fileSize;
+@property (nonatomic, retain) NSString * license;
@property (nonatomic, retain) NSNumber * fetchThumbnailProgress;
diff --git a/Commons-iOS/FileUpload.m b/Commons-iOS/FileUpload.m
index 34e042b..7af3a35 100644
--- a/Commons-iOS/FileUpload.m
+++ b/Commons-iOS/FileUpload.m
@@ -23,6 +23,7 @@
@dynamic source;
@dynamic thumbnailURL;
@dynamic fileSize;
+@dynamic license;
@synthesize fetchThumbnailProgress;
diff --git a/Commons-iOS/FileUpload.xcdatamodeld/.xccurrentversion
b/Commons-iOS/FileUpload.xcdatamodeld/.xccurrentversion
index 9578caa..e4a3d0e 100644
--- a/Commons-iOS/FileUpload.xcdatamodeld/.xccurrentversion
+++ b/Commons-iOS/FileUpload.xcdatamodeld/.xccurrentversion
@@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
- <string>FileUpload 3.xcdatamodel</string>
+ <string>FileUpload 4.xcdatamodel</string>
</dict>
</plist>
diff --git a/Commons-iOS/FileUpload.xcdatamodeld/FileUpload
3.xcdatamodel/contents b/Commons-iOS/FileUpload.xcdatamodeld/FileUpload
3.xcdatamodel/contents
index f511604..e7ba70d 100644
--- a/Commons-iOS/FileUpload.xcdatamodeld/FileUpload 3.xcdatamodel/contents
+++ b/Commons-iOS/FileUpload.xcdatamodeld/FileUpload 3.xcdatamodel/contents
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<model name="" userDefinedModelVersionIdentifier=""
type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0"
lastSavedToolsVersion="2061" systemVersion="12D78" minimumToolsVersion="Xcode
4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+<model userDefinedModelVersionIdentifier=""
type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0"
lastSavedToolsVersion="3396" systemVersion="12F37" minimumToolsVersion="Xcode
4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="Category" representedClassName="Category" syncable="YES">
<attribute name="lastUsed" optional="YES" attributeType="Date"
syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String"
syncable="YES"/>
@@ -19,7 +19,7 @@
<attribute name="title" optional="YES" attributeType="String"
syncable="YES"/>
</entity>
<elements>
- <element name="FileUpload" positionX="160" positionY="192" width="128"
height="210"/>
- <element name="Category" positionX="160" positionY="192" width="128"
height="90"/>
+ <element name="Category" positionX="0" positionY="0" width="0"
height="0"/>
+ <element name="FileUpload" positionX="0" positionY="0" width="0"
height="0"/>
</elements>
</model>
\ No newline at end of file
diff --git a/Commons-iOS/FileUpload.xcdatamodeld/FileUpload
4.xcdatamodel/contents b/Commons-iOS/FileUpload.xcdatamodeld/FileUpload
4.xcdatamodel/contents
new file mode 100644
index 0000000..840e6de
--- /dev/null
+++ b/Commons-iOS/FileUpload.xcdatamodeld/FileUpload 4.xcdatamodel/contents
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<model userDefinedModelVersionIdentifier=""
type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0"
lastSavedToolsVersion="3396" systemVersion="12F37" minimumToolsVersion="Xcode
4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+ <entity name="Category" representedClassName="Category" syncable="YES">
+ <attribute name="lastUsed" optional="YES" attributeType="Date"
syncable="YES"/>
+ <attribute name="name" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="timesUsed" optional="YES" attributeType="Integer 32"
defaultValueString="0" syncable="YES"/>
+ </entity>
+ <entity name="FileUpload" representedClassName="FileUpload" syncable="YES">
+ <attribute name="categories" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="complete" optional="YES" attributeType="Boolean"
syncable="YES"/>
+ <attribute name="created" optional="YES" attributeType="Date"
syncable="YES"/>
+ <attribute name="desc" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="fileSize" optional="YES" attributeType="Integer 32"
defaultValueString="0" syncable="YES"/>
+ <attribute name="fileType" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="license" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="localFile" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="progress" optional="YES" attributeType="Float"
defaultValueString="0.0" syncable="YES"/>
+ <attribute name="source" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="thumbnailURL" optional="YES" attributeType="String"
syncable="YES"/>
+ <attribute name="title" optional="YES" attributeType="String"
syncable="YES"/>
+ </entity>
+ <elements>
+ <element name="Category" positionX="0" positionY="0" width="0"
height="0"/>
+ <element name="FileUpload" positionX="0" positionY="0" width="0"
height="0"/>
+ </elements>
+</model>
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/88165
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1061e91647310ee8ba9bfd2ea116b65c8b97560
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/commons
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits