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

[HOLD MERGE] Update diff view for forthcoming Watchlist feature #4552

Merged
merged 18 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions WMF Framework/CommonStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ public class CommonStrings: NSObject {

public static let defaultThemeDisplayName = WMFLocalizedString("theme-default-display-name", value: "Default", comment: "Default theme name presented to the user")

public static let moreButton = WMFLocalizedString("more-menu", value: "More", comment: "Accessibility title for more button in toolbar.")

public static let watchlist = WMFLocalizedString("watchlist", value: "Watchlist", comment: "Title for watchlist feature.")

public static let rollback = WMFLocalizedString("diff-rollback", value: "Rollback", comment: "Title for rollback toolbar button.")

public static let diffFromHeading = WMFLocalizedString("diff-compare-header-from-info-heading", value: "From", comment: "Heading label in from revision info box when comparing two revisions.")

public static let diffToHeading = WMFLocalizedString("diff-compare-header-to-info-heading", value: "To", comment: "Heading label in to revision info box when comparing two revisions.")

public static let diffArticleEditHistory = WMFLocalizedString("diff-article-edit-history", value: "Article Edit History", comment: "Label for article edit history menu item in diff more menu.")

public static let diffSingleLineFormat = WMFLocalizedString("diff-single-line-format", value:"Line %1$d", comment:"Label in diff to indicate how many lines a change section encompases. This format is for a single change line. %1$d is replaced by the change line number.")

public static let diffMultiLineFormat = WMFLocalizedString("diff-multi-line-format", value:"Lines %1$d - %2$d", comment:"Label in diff to indicate how many lines a change section encompases. This format is for multiple change lines. %1$d is replaced by the starting line number and %2$d is replaced by the ending line number.")
Expand Down
4 changes: 0 additions & 4 deletions WMF Framework/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public struct FeatureFlags {
}

public static var updatedDiffsEnabled: Bool {
#if WMF_STAGING
return true
#else
return false
#endif
}

}
11 changes: 1 addition & 10 deletions WMF Framework/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,7 @@ public class Colors: NSObject {
}

public var diffCompareChangeHeading: UIColor {
switch identifier {
case .light:
return .white
case .sepia:
return .beige100
case .black, .dark:
return .black
default:
return .clear
}
return secondaryText
}

public var talkPageCoffeRollBackground: UIColor {
Expand Down
12 changes: 1 addition & 11 deletions Wikipedia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1728,10 +1728,6 @@
833B8C8A281AE2110021C12C /* RemoteNotificationsFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1218327FC8750006B8CCC /* RemoteNotificationsFunnel.swift */; };
833B8C8B281AE2120021C12C /* RemoteNotificationsFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83B1218327FC8750006B8CCC /* RemoteNotificationsFunnel.swift */; };
833D4FFB20A9E20800B44E7C /* String+HTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833D4FFA20A9E20800B44E7C /* String+HTML.swift */; };
833D6B48229EE872003CB650 /* TalkPageTopic+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833D6B47229EE872003CB650 /* TalkPageTopic+Extensions.swift */; };
833D6B49229EE872003CB650 /* TalkPageTopic+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833D6B47229EE872003CB650 /* TalkPageTopic+Extensions.swift */; };
833D6B4A229EE872003CB650 /* TalkPageTopic+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833D6B47229EE872003CB650 /* TalkPageTopic+Extensions.swift */; };
833D6B4B229EE872003CB650 /* TalkPageTopic+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833D6B47229EE872003CB650 /* TalkPageTopic+Extensions.swift */; };
8341A345299ACD8C00016535 /* MEPEventProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8341A344299ACD8C00016535 /* MEPEventProviding.swift */; };
8341A347299D7D5900016535 /* UserHistorySnapshotCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8341A346299D7D5900016535 /* UserHistorySnapshotCache.swift */; };
8341A348299D7D5900016535 /* UserHistorySnapshotCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8341A346299D7D5900016535 /* UserHistorySnapshotCache.swift */; };
Expand Down Expand Up @@ -1880,7 +1876,6 @@
83AE025C299D9CDD00C45F73 /* SearchFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AE025B299D9CDD00C45F73 /* SearchFunnel.swift */; };
83AE025D299D9CDD00C45F73 /* SearchFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AE025B299D9CDD00C45F73 /* SearchFunnel.swift */; };
83AE025E299D9CDD00C45F73 /* SearchFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AE025B299D9CDD00C45F73 /* SearchFunnel.swift */; };
83AE025F299D9CDD00C45F73 /* SearchFunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AE025B299D9CDD00C45F73 /* SearchFunnel.swift */; };
83AE1C811F34BB59004B62E0 /* ImageDimmingExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7683C01F30C56300A487AA /* ImageDimmingExampleViewController.swift */; };
83AE1C821F34BB5A004B62E0 /* ImageDimmingExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7683C01F30C56300A487AA /* ImageDimmingExampleViewController.swift */; };
83AE1C831F34BB5A004B62E0 /* ImageDimmingExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7683C01F30C56300A487AA /* ImageDimmingExampleViewController.swift */; };
Expand Down Expand Up @@ -4467,7 +4462,6 @@
8338AF8B21F7B33E000C4055 /* WMFLegacyFetcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WMFLegacyFetcher.h; sourceTree = "<group>"; };
8338AF8C21F7B33E000C4055 /* WMFLegacyFetcher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WMFLegacyFetcher.m; sourceTree = "<group>"; };
833D4FFA20A9E20800B44E7C /* String+HTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+HTML.swift"; sourceTree = "<group>"; };
833D6B47229EE872003CB650 /* TalkPageTopic+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TalkPageTopic+Extensions.swift"; sourceTree = "<group>"; };
8341A344299ACD8C00016535 /* MEPEventProviding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MEPEventProviding.swift; sourceTree = "<group>"; };
8341A346299D7D5900016535 /* UserHistorySnapshotCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserHistorySnapshotCache.swift; sourceTree = "<group>"; };
834C269B24042DBF00245BE7 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10385,7 +10379,7 @@
B0267CE91E316A79006B6D8D /* WMFForgotPasswordViewController.storyboard in Resources */,
B0845E1C2061B44A00CDD98E /* SavedProgressViewController.storyboard in Resources */,
6782DBF023453799003FA21B /* DiffHeaderCompareView.xib in Resources */,
00A8F58826BDD88700175B8E /* Featured Article Widget Preview Content.json in Resources */,
00A8F58826BDD88700175B8E /* Widget Featured Content Preview.json in Resources */,
671F5E0B236B8CAF00111116 /* EmptyViewController.xib in Resources */,
83836ED11F615E5B007D1A05 /* ShareViewController.xib in Resources */,
0EE2438F1DC988AA00066CBD /* WMFTableHeaderFooterLabelView.xib in Resources */,
Expand Down Expand Up @@ -11419,7 +11413,6 @@
7AC19E452301F79700E25B83 /* PageHistoryFilterCountCollectionViewCell.swift in Sources */,
0EC0447B1C796FEF0033D773 /* WMFImageTextActivitySource.swift in Sources */,
83EE476A20D019A100A21F34 /* ExploreViewController.swift in Sources */,
B0E805951C0CE2C60065EBC0 /* ToCInteractionFunnel.m in Sources */,
7A8422532268DA2C0074648E /* InsertMediaSearchResultPreviewingViewController.swift in Sources */,
B0BCF0B9202537D800986F72 /* Panels.swift in Sources */,
67C6F7A127E8C7C500B9C864 /* NotificationsCenterCommonViewModel+ActionExtensions.swift in Sources */,
Expand Down Expand Up @@ -12226,7 +12219,6 @@
6741245327E97DBC0071177D /* NotificationsCenterDetailViewModel+ActionExtensions.swift in Sources */,
00E2EA8C26E28A9700B1A741 /* NotificationsCenterCellStyle.swift in Sources */,
D8A42A9B1E815A9C00D8E281 /* UIVIewController+WMFCommonRotationSupport.swift in Sources */,
B0C17B9C21FAB060009ED5C3 /* AbuseFilterAlertView.swift in Sources */,
D8A42A9D1E815A9C00D8E281 /* WMFTitleInsetRespectingButton.m in Sources */,
B0F4761E21F921D300C4E254 /* EditSummaryViewController.swift in Sources */,
B0421AA5206991F500C22630 /* SavedTabBarItemProgressBadgeManager.swift in Sources */,
Expand Down Expand Up @@ -12632,7 +12624,6 @@
BAC6EECA1F1E519B00228AD0 /* AppearanceSettingsViewController.swift in Sources */,
83927D841F705B7B00051890 /* SearchResultsViewController.swift in Sources */,
7A82896B21B3467D005D7EC1 /* TextFormattingDetailTableViewCell.swift in Sources */,
67E8B093226A57EA00537BC9 /* TalkPageTopicListViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -13767,7 +13758,6 @@
7AEBAD472102117C002FAB41 /* NSFetchedResultsController+IndexPathValidation.swift in Sources */,
679A24092968E0D0008D7686 /* ShiftingScrollView.swift in Sources */,
67DAEDDA27E8DCBF005CF9B6 /* NotificationsCenterDetailViewModel+TextExtensions.swift in Sources */,
670F766122B0C48F00D87545 /* FakeProgressLoading.swift in Sources */,
83B01F7423DA5327001185F4 /* ArticleViewController+ArticleWebMessageHandling.swift in Sources */,
00D9276C29511E95004ECBEA /* PageHistoryCountsView.swift in Sources */,
0010F93A27A49C7700D77848 /* HorizontalSpacerView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"location" : "https://github.com/wikimedia/wikipedia-ios-components.git",
"state" : {
"branch" : "main",
"revision" : "e0f1de2f41b084b671c18416e64506c9492e7916"
"revision" : "df4595a6fdc55f60a0141ad09a3f96cebea4dd63"
}
}
],
Expand Down
119 changes: 58 additions & 61 deletions Wikipedia/Code/DiffContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,7 @@ class DiffContainerViewController: ViewController {
}

private var byteDifference: Int? {
guard let toModel = toModel,
type == .single else {
return nil
}

if toModel.revisionSize == 0 { // indication that this has not been calculated yet from Page History, need fromModel for calculation

guard let fromModel = fromModel else {
return isOnFirstRevisionInHistory ? toModel.articleSizeAtRevision : nil
}

return toModel.articleSizeAtRevision - fromModel.articleSizeAtRevision
} else {
return toModel.revisionSize
}
return (toModel?.articleSizeAtRevision ?? 0) - (fromModel?.articleSizeAtRevision ?? 0)
}

init(siteURL: URL, theme: Theme, fromRevisionID: Int?, toRevisionID: Int?, type: DiffContainerViewModel.DiffType, articleTitle: String?, needsSetNavDelegate: Bool = false) {
Expand Down Expand Up @@ -221,10 +207,6 @@ class DiffContainerViewController: ViewController {

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

if let scrollView = diffListViewController?.scrollView {
configureExtendedViewSquishing(scrollView: scrollView)
}

if let emptyViewController = scrollingEmptyViewController {
navigationBar.setNeedsLayout()
Expand Down Expand Up @@ -670,7 +652,8 @@ private extension DiffContainerViewController {
let articleTitle = articleTitle else {
return
}
let newTitleViewModel = DiffHeaderViewModel.generateTitleViewModelForCompare(articleTitle: articleTitle, editCounts: editCounts)

let newTitleViewModel = DiffHeaderViewModel.generateTitleViewModelForCompare(articleTitle: articleTitle, byteDifference: byteDifference)
headerViewModel.title = newTitleViewModel
headerTitleView?.update(newTitleViewModel)
case .single:
Expand Down Expand Up @@ -771,18 +754,7 @@ private extension DiffContainerViewController {
}
}
}

func configureExtendedViewSquishing(scrollView: UIScrollView) {
guard let headerTitleView = headerTitleView,
let headerExtendedView = headerExtendedView else {
return
}

let beginSquishYOffset = headerTitleView.frame.height
let scrollYOffset = scrollView.contentOffset.y + scrollView.adjustedContentInset.top
headerExtendedView.configureHeight(beginSquishYOffset: beginSquishYOffset, scrollYOffset: scrollYOffset)
}


func setupHeaderViewIfNeeded() {

guard let headerViewModel = containerViewModel.headerViewModel else {
Expand Down Expand Up @@ -874,27 +846,20 @@ private extension DiffContainerViewController {
}

func setupToolbarIfNeeded() {

switch type {
case .single:
if diffToolbarView == nil {
let toolbarView = DiffToolbarView(frame: .zero)
self.diffToolbarView = toolbarView
toolbarView.delegate = self
toolbarView.translatesAutoresizingMaskIntoConstraints = false
view.insertSubview(toolbarView, aboveSubview: navigationBar)
let bottom = view.bottomAnchor.constraint(equalTo: toolbarView.bottomAnchor)
let leading = view.leadingAnchor.constraint(equalTo: toolbarView.leadingAnchor)
let trailing = view.trailingAnchor.constraint(equalTo: toolbarView.trailingAnchor)
NSLayoutConstraint.activate([bottom, leading, trailing])
toolbarView.apply(theme: theme)
toolbarView.setPreviousButtonState(isEnabled: false)
toolbarView.setNextButtonState(isEnabled: false)
}
default:
break
if diffToolbarView == nil {
let toolbarView = DiffToolbarView(frame: .zero)
self.diffToolbarView = toolbarView
toolbarView.delegate = self
toolbarView.translatesAutoresizingMaskIntoConstraints = false
view.insertSubview(toolbarView, aboveSubview: navigationBar)
let bottom = view.bottomAnchor.constraint(equalTo: toolbarView.bottomAnchor)
let leading = view.leadingAnchor.constraint(equalTo: toolbarView.leadingAnchor)
let trailing = view.trailingAnchor.constraint(equalTo: toolbarView.trailingAnchor)
NSLayoutConstraint.activate([bottom, leading, trailing])
toolbarView.apply(theme: theme)
toolbarView.setPreviousButtonState(isEnabled: false)
toolbarView.setNextButtonState(isEnabled: false)
}

}

func setupDiffListViewControllerIfNeeded() {
Expand Down Expand Up @@ -969,8 +934,6 @@ private extension DiffContainerViewController {
extension DiffContainerViewController: DiffListDelegate {
func diffListScrollViewDidScroll(_ scrollView: UIScrollView) {
self.scrollViewDidScroll(scrollView)

configureExtendedViewSquishing(scrollView: scrollView)
}
}

Expand Down Expand Up @@ -1119,8 +1082,8 @@ extension DiffContainerViewController: DiffToolbarViewDelegate {
return
}

let singleDiffVC = DiffContainerViewController(articleTitle: articleTitle, siteURL: siteURL, type: .single, fromModel: fromModel, toModel: toModel, theme: theme, revisionRetrievingDelegate: revisionRetrievingDelegate, firstRevision: firstRevision, needsSetNavDelegate: needsSetNavDelegate)
replaceLastAndPush(with: singleDiffVC)
let diffVC = DiffContainerViewController(articleTitle: articleTitle, siteURL: siteURL, type: .compare, fromModel: fromModel, toModel: toModel, theme: theme, revisionRetrievingDelegate: revisionRetrievingDelegate, firstRevision: firstRevision, needsSetNavDelegate: needsSetNavDelegate)
replaceLastAndPush(with: diffVC)
}

func tappedNext() {
Expand All @@ -1133,8 +1096,8 @@ extension DiffContainerViewController: DiffToolbarViewDelegate {
return
}

let singleDiffVC = DiffContainerViewController(articleTitle: articleTitle, siteURL: siteURL, type: .single, fromModel: nextModel.from, toModel: nextModel.to, theme: theme, revisionRetrievingDelegate: revisionRetrievingDelegate, firstRevision: firstRevision, needsSetNavDelegate: needsSetNavDelegate)
replaceLastAndPush(with: singleDiffVC)
let diffVC = DiffContainerViewController(articleTitle: articleTitle, siteURL: siteURL, type: .compare, fromModel: nextModel.from, toModel: nextModel.to, theme: theme, revisionRetrievingDelegate: revisionRetrievingDelegate, firstRevision: firstRevision, needsSetNavDelegate: needsSetNavDelegate)
replaceLastAndPush(with: diffVC)
}

func tappedShare(_ sender: UIBarButtonItem) {
Expand All @@ -1151,12 +1114,46 @@ extension DiffContainerViewController: DiffToolbarViewDelegate {
}

func tappedThankButton() {
guard type == .single else {
return
}
let isUserAnonymous = toModel?.isAnon ?? true
tappedThank(for: toModelRevisionID, isUserAnonymous: isUserAnonymous)
}

func tappedUndo() {
let message = WMFLocalizedString("diff-undo-message", value: "This will undo the changes made by the revisions(s) of the article shown here. To continue, please provide a reason for undoing this edit.", comment: "Message showed in alert when user taps undo in diff toolbar.")

let alertController = UIAlertController(title: CommonStrings.undo, message: message, preferredStyle: .alert)
alertController.addTextField { textField in
textField.clearButtonMode = .always
}

let cancel = UIAlertAction(title: CommonStrings.cancelActionTitle, style: .cancel)
let undo = UIAlertAction(title: CommonStrings.undo, style: .destructive)
undo.isEnabled = false

// DIFFTODO: Hook up undo action and enable only if textfield is non-empty

alertController.addAction(cancel)
alertController.addAction(undo)

present(alertController, animated: true)
}

func tappedRollback() {
let title = WMFLocalizedString("diff-rollback-alert-title", value: "Rollback edits", comment: "Title of alert when user taps rollback in diff toolbar.")
let message = WMFLocalizedString("diff-rollback-alert-message", value: "Are you sure you want to rollback the edits?", comment: "Message in alert when user taps rollback in diff toolbar.")
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)

let cancel = UIAlertAction(title: CommonStrings.cancelActionTitle, style: .cancel)
let rollback = UIAlertAction(title: CommonStrings.rollback, style: .destructive)

// DIFFTODO: Hook up rollback action

alertController.addAction(cancel)
alertController.addAction(rollback)

present(alertController, animated: true)
}

}

extension DiffContainerViewController: UINavigationControllerDelegate {
Expand Down
Loading