Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article language tweaks for Article "Read More" #258

Merged
merged 7 commits into from Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions Wikipedia.xcodeproj/project.pbxproj
Expand Up @@ -19,7 +19,6 @@
041A3B5E18E11ED90079FF1C /* LanguageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 041A3B5918E11ED90079FF1C /* LanguageCell.m */; };
041A3B6218E11ED90079FF1C /* LanguagesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 041A3B5D18E11ED90079FF1C /* LanguagesViewController.m */; };
041C55D21950B27D006CE0EF /* EditSummaryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 041C55D11950B27D006CE0EF /* EditSummaryViewController.m */; };
041C6206199ED2A20061516F /* MWKSection+TOC.m in Sources */ = {isa = PBXBuildFile; fileRef = 041C6205199ED2A20061516F /* MWKSection+TOC.m */; };
041E32371B72AB9A001D0E28 /* WMFSectionHeadersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 041E32311B72AB9A001D0E28 /* WMFSectionHeadersViewController.m */; };
041E32381B72AB9A001D0E28 /* WMFSectionHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 041E32331B72AB9A001D0E28 /* WMFSectionHeader.m */; };
041E32391B72AB9A001D0E28 /* WMFSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = 041E32341B72AB9A001D0E28 /* WMFSectionHeader.xib */; };
Expand Down Expand Up @@ -599,8 +598,6 @@
041A3B5D18E11ED90079FF1C /* LanguagesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LanguagesViewController.m; sourceTree = "<group>"; };
041C55D01950B27D006CE0EF /* EditSummaryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditSummaryViewController.h; sourceTree = "<group>"; };
041C55D11950B27D006CE0EF /* EditSummaryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = EditSummaryViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
041C6204199ED2A20061516F /* MWKSection+TOC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MWKSection+TOC.h"; sourceTree = "<group>"; };
041C6205199ED2A20061516F /* MWKSection+TOC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MWKSection+TOC.m"; sourceTree = "<group>"; };
041E322F1B72AB9A001D0E28 /* WMFSectionHeaderEditProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMFSectionHeaderEditProtocol.h; sourceTree = "<group>"; };
041E32301B72AB9A001D0E28 /* WMFSectionHeadersViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMFSectionHeadersViewController.h; sourceTree = "<group>"; };
041E32311B72AB9A001D0E28 /* WMFSectionHeadersViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMFSectionHeadersViewController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2089,8 +2086,6 @@
04B91AAA18E3D9E200FFAA1C /* NSString+FormattedAttributedString.m */,
0472BC16193AD88C00C40BDA /* MWKSection+DisplayHtml.h */,
0472BC17193AD88C00C40BDA /* MWKSection+DisplayHtml.m */,
041C6204199ED2A20061516F /* MWKSection+TOC.h */,
041C6205199ED2A20061516F /* MWKSection+TOC.m */,
047801BC18AE987900DBB747 /* UIButton+ColorMask.h */,
047801BD18AE987900DBB747 /* UIButton+ColorMask.m */,
0415581A18ADFA5C00B81A59 /* UIImage+ColorMask.h */,
Expand Down Expand Up @@ -4585,7 +4580,6 @@
BC505EEE1B594B5700537006 /* WMFImageCollectionViewCell.m in Sources */,
0E4D1CFF1BBDC857009BEB64 /* WMFTableOfContentsCell.swift in Sources */,
BC8C0BA41BCFC3C600E2B167 /* DDLog+WMFLogger.m in Sources */,
041C6206199ED2A20061516F /* MWKSection+TOC.m in Sources */,
046D3CA01B8BDFB3004F2B92 /* UIWebView+WMFJavascriptToXcodeConsoleLogging.m in Sources */,
BC505EEB1B59461400537006 /* WMFCollectionViewPageLayout.m in Sources */,
BC2CBB8E1AA10F400079A313 /* UIView+WMFFrameUtils.m in Sources */,
Expand Down
9 changes: 0 additions & 9 deletions Wikipedia/Categories/MWKSection+TOC.h

This file was deleted.

50 changes: 0 additions & 50 deletions Wikipedia/Categories/MWKSection+TOC.m

This file was deleted.

10 changes: 9 additions & 1 deletion Wikipedia/UI-V5/TableOfContentsReadMoreItem.swift
Expand Up @@ -13,7 +13,15 @@ public protocol TableOfContentsFooterItem : TableOfContentsItem {
}

public class TableOfContentsReadMoreItem : NSObject, TableOfContentsFooterItem {
public let titleText: String = localizedStringForKeyFallingBackOnEnglish("article-read-more-title")
let site:MWKSite
init(site: MWKSite) {
self.site = site
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is calling super.init() optional in swift?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Interestingly in Swift instance vars need to be set before super init... http://stackoverflow.com/a/24150540

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - anything that is a let needs to be set before you call init - since that is a constant (can't change later). for instance you can see the delegate ivar in the toc view controller is just a var. so it doesn't need to be set.

}

public var titleText:String {
return localizedStringForSiteWithKeyFallingBackOnEnglish(self.site, "article-read-more-title")
}

public let itemType: TableOfContentsItemType = TableOfContentsItemType.Primary
public let footerViewIndex: WMFArticleFooterViewIndex = WMFArticleFooterViewIndex.ReadMore

Expand Down
8 changes: 6 additions & 2 deletions Wikipedia/UI-V5/WMFArticleContainerViewController+TOC.swift
Expand Up @@ -10,7 +10,7 @@ extension WMFArticleContainerViewController : WMFTableOfContentsViewControllerDe
} else if let footerIndex: WMFArticleFooterViewIndex = WMFArticleFooterViewIndex(rawValue: webViewController.visibleFooterIndex()) {
switch footerIndex {
case .ReadMore:
tableOfContentsViewController!.selectAndScrollToItem(TableOfContentsReadMoreItem(), animated: false)
tableOfContentsViewController!.selectAndScrollToItem(TableOfContentsReadMoreItem(site: self.articleTitle.site), animated: false)
}
} else {
assertionFailure("Couldn't find current position of user at current offset!")
Expand Down Expand Up @@ -38,6 +38,10 @@ extension WMFArticleContainerViewController : WMFTableOfContentsViewControllerDe
public func tableOfContentsControllerDidCancel(controller: WMFTableOfContentsViewController) {
dismissViewControllerAnimated(true, completion: nil)
}

public func tableOfContentsArticleSite() -> MWKSite {
return self.articleTitle.site
}
}

extension WMFArticleContainerViewController {
Expand All @@ -53,7 +57,7 @@ extension WMFArticleContainerViewController {
if let sections = self.article?.sections {
// HAX: need to forcibly downcast each section object to our protocol type. yay objc/swift interop!
var items = sections.entries.map() { $0 as! TableOfContentsItem }
items.append(TableOfContentsReadMoreItem())
items.append(TableOfContentsReadMoreItem(site: self.articleTitle.site))
self.tableOfContentsViewController = WMFTableOfContentsViewController(presentingViewController: self, items: items, delegate: self)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/UI-V5/WMFArticleContainerViewController.m
Expand Up @@ -500,7 +500,7 @@ - (void)webViewController:(WebViewController*)controller didTapShareWithSelected

- (nullable NSString*)webViewController:(WebViewController*)controller titleForFooterViewController:(UIViewController*)footerViewController {
if (footerViewController == self.readMoreListViewController) {
return [MWLocalizedString(@"article-related-articles-title", nil) uppercaseStringWithLocale:[NSLocale currentLocale]];
return [MWSiteLocalizedString(self.articleTitle.site, @"article-read-more-title", nil) uppercaseStringWithLocale:[NSLocale currentLocale]];
}
return nil;
}
Expand Down
21 changes: 15 additions & 6 deletions Wikipedia/UI-V5/WMFTableOfContentsHeader.swift
@@ -1,17 +1,26 @@
import UIKit

public class WMFTableOfContentsHeader: UIView {

@IBOutlet public var contentsLabel: UILabel!

public override func awakeFromNib() {
super.awakeFromNib()
var headerString = localizedStringForKeyFallingBackOnEnglish("table-of-contents-heading")

var site:MWKSite!

public var articleSite:MWKSite! {
get {
return site
}
set(newSite){
self.contentsLabel.text = self.headerTextForSite(newSite)
site = newSite
}
}

public func headerTextForSite(site: MWKSite) -> String {
var headerString = localizedStringForSiteWithKeyFallingBackOnEnglish(site, "table-of-contents-heading")
if(NSLocale.wmf_isCurrentLocaleEnglish()){
headerString = headerString.uppercaseStringWithLocale(NSLocale.currentLocale())
}
self.contentsLabel.text = headerString
return headerString
}

public override func layoutSubviews() {
Expand Down
3 changes: 3 additions & 0 deletions Wikipedia/UI-V5/WMFTableOfContentsViewController.swift
Expand Up @@ -20,6 +20,8 @@ public protocol WMFTableOfContentsViewControllerDelegate : AnyObject {
The delegate is responsible for dismissing the view controller
*/
func tableOfContentsControllerDidCancel(controller: WMFTableOfContentsViewController)

func tableOfContentsArticleSite() -> MWKSite
}

public class WMFTableOfContentsViewController: UITableViewController, WMFTableOfContentsAnimatorDelegate {
Expand Down Expand Up @@ -111,6 +113,7 @@ public class WMFTableOfContentsViewController: UITableViewController, WMFTableOf
public override func viewDidLoad() {
super.viewDidLoad()
let header = WMFTableOfContentsHeader.wmf_viewFromClassNib()
header.articleSite = delegate?.tableOfContentsArticleSite()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to assert that the delegate is set in viewDidLoad now since we require it for the header.

self.tableView.tableHeaderView = header
tableView.registerNib(WMFTableOfContentsCell.wmf_classNib(),
forCellReuseIdentifier: WMFTableOfContentsCell.reuseIdentifier())
Expand Down