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

watermark feature for iOS App #1420

Closed
wants to merge 12 commits into from
5 changes: 5 additions & 0 deletions ownCloud/Client/Actions/Action+UserInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ extension Action {
let moreViewController = FrameViewController(header: header, viewController: tableViewController)
let actions = Action.sortedApplicableActions(for: context)

moreViewController.watermark(
username: core.bookmark.userName,
userMail: core.bookmark.user?.emailAddress
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This and similar code is repeated several times across in different places. It would require changes if

  • the location of the extracted userName or emailAdress changes
  • the data that should be extracted from the Bookmark changes
    Passing the bookmark directly and extracting the desired information in the watermark method would be a more flexible and less repetitive pattern.


actions.forEach({
$0.actionWillRunHandler = { [weak moreViewController] (_ donePreparing: @escaping () -> Void) in
moreViewController?.dismiss(animated: true, completion: donePreparing)
Expand Down
6 changes: 6 additions & 0 deletions ownCloud/Client/Viewer/DisplayHostViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ class DisplayHostViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()

watermark(
username: self.clientContext?.core?.bookmark.userName,
userMail: self.clientContext?.core?.bookmark.user?.emailAddress
)


self.dataSource = self
self.delegate = self

Expand Down
69 changes: 69 additions & 0 deletions ownCloud/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -72450,6 +72450,75 @@
}
}
},
"ScreenshotNotificationButton" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "أنا أفهم"
Copy link
Member

Choose a reason for hiding this comment

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

For the future: translations will happen on https://app.transifex.com/owncloud-org/owncloud-ios/dashboard/

Any change done in the source code will be overwritten on a daily basis once merged.

}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Verstanden"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "I understand"
}
}
}
},
"ScreenshotNotificationMessage" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : " تم اكتشاف لقطة شاشة، ولا يسمح بلقطات الشاشة وتسجيلات الشاشة لهذا التطبيق"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Screen Capture Detected, Screenshots und Bildschirmaufnahmen dieser Anwendung sind nicht erlaubt."
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Screen Capture Detected, Screenshots and screen recordings of this app are not allowed."
}
}
}
},
"ScreenshotNotificationTitle" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "Screenshot taken"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Bildschirmaufnahme gemacht"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Screenshot taken"
}
}
}
},
"Scroll to Bottom": {
"extractionState": "manual",
"localizations": {
Expand Down
12 changes: 12 additions & 0 deletions ownCloudAppShared/Client/Sharing/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
expirationDate = Date(timeIntervalSinceNow: numberOfDays.doubleValue * (24 * 60 * 60))
}
}
observeScreenshotEvent()
}

required public init?(coder: NSCoder) {
Expand Down Expand Up @@ -335,6 +336,12 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
}

updateState()

watermark(
username: self.clientContext?.core?.bookmark.userName,
userMail: self.clientContext?.core?.bookmark.user?.emailAddress
)

}

// MARK: - Share Role & permissions
Expand Down Expand Up @@ -1073,4 +1080,9 @@ open class ShareViewController: CollectionViewController, SearchViewControllerDe
}
}
}

deinit {
stopObserveScreenshotEvent()
}

}
10 changes: 10 additions & 0 deletions ownCloudAppShared/Client/Sharing/SharingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ open class SharingViewController: CollectionViewController {
}
}

override open func viewDidLoad() {
super.viewDidLoad()
observeScreenshotEvent()
watermark(
username: self.clientContext?.core?.bookmark.userName,
userMail: self.clientContext?.core?.bookmark.user?.emailAddress
)
}


deinit {
if let core = clientContext?.core, let itemSharesQuery {
core.stop(itemSharesQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ open class ClientItemViewController: CollectionViewController, SortBarDelegate,
public override func viewDidLoad() {
super.viewDidLoad()

watermark(
username: self.clientContext?.accountConnection?.core?.connection.loggedInUser?.userName,
userMail: self.clientContext?.accountConnection?.core?.connection.loggedInUser?.emailAddress
)

// Add navigation bar button items
updateNavigationBarButtonItems()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class ClientSharedByMeViewController: CollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()

observeScreenshotEvent()
watermark(
username: self.clientContext?.core?.bookmark.userName,
userMail: self.clientContext?.core?.bookmark.user?.emailAddress
)

// Disable dragging of items, so keyboard control does
// not include "Drag Item" in the accessibility actions
// invoked with Tab + Z
Expand Down Expand Up @@ -120,4 +126,8 @@ class ClientSharedByMeViewController: CollectionViewController {

setCoverView(coverView, layout: .top)
}
deinit {
stopObserveScreenshotEvent()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class ClientSharedWithMeViewController: CollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()

observeScreenshotEvent()
watermark(
username: self.clientContext?.core?.bookmark.userName,
userMail: self.clientContext?.core?.bookmark.user?.emailAddress
)

// Disable dragging of items, so keyboard control does
// not include "Drag Item" in the accessibility actions
// invoked with Tab + Z
Expand Down Expand Up @@ -123,4 +129,8 @@ class ClientSharedWithMeViewController: CollectionViewController {

setCoverView(coverView, layout: .top)
}

deinit {
stopObserveScreenshotEvent()
}
}
71 changes: 70 additions & 1 deletion ownCloudAppShared/Tools/VendorServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,58 @@ public class VendorServices : NSObject {
return false
}

public var watermarkEnabled: Bool {
if let watermarkEnabled = self.classSetting(forOCClassSettingsKey: .watermarkEnabled) as? Bool {
return watermarkEnabled
}

return false
}

public var watermarkOpacity: Int {
if let watermarkOpacity = self.classSetting(forOCClassSettingsKey: .watermarkOpacity) as? Int {
return watermarkOpacity
}

return 100
}

public var watermarkFontSize: Int {
if let watermarkFontSize = self.classSetting(forOCClassSettingsKey: .watermarkFontSize) as? Int {
return watermarkFontSize
}

return 15
}

public var watermarkText: String? {
return self.classSetting(forOCClassSettingsKey: .watermarkText) as? String
}

public var watermarkShowMail: Bool {
if let watermarkShowMail = self.classSetting(forOCClassSettingsKey: .watermarkShowMail) as? Bool {
return watermarkShowMail
}

return false
}

public var watermarkShowDate: Bool {
if let watermarkShowDate = self.classSetting(forOCClassSettingsKey: .watermarkShowDate) as? Bool {
return watermarkShowDate
}

return false
}

public var showScreenshotNotification: Bool {
if let showScreenshotNotification = self.classSetting(forOCClassSettingsKey: .showScreenshotNotification) as? Bool {
return showScreenshotNotification
}

return false
}

static public var shared : VendorServices = {
return VendorServices()
}()
Expand Down Expand Up @@ -151,6 +203,14 @@ public extension OCClassSettingsKey {

static let appStoreLink = OCClassSettingsKey("app-store-link")
static let recommendToFriendEnabled = OCClassSettingsKey("recommend-to-friend-enabled")

static let watermarkEnabled = OCClassSettingsKey("watermark-enabled")
static let watermarkOpacity = OCClassSettingsKey("watermark-opacity")
static let watermarkFontSize = OCClassSettingsKey("watermark-font-size")
static let watermarkText = OCClassSettingsKey("watermark-text")
static let watermarkShowMail = OCClassSettingsKey("watermark-show-mail")
static let watermarkShowDate = OCClassSettingsKey("watermark-show-date")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the watermark options here are so numerous, related and for a specific feature only, it would be good to move them to their own category (classSettingsIdentifier) and class rather than adding them to the broader VendorServices / app category.

static let showScreenshotNotification = OCClassSettingsKey("show-screenshot-notification")
}

extension VendorServices : OCClassSettingsSupport {
Expand All @@ -165,7 +225,16 @@ extension VendorServices : OCClassSettingsSupport {
.enableReviewPrompt: VendorServices.shared.enableReviewPrompt,

.appStoreLink : "https://itunes.apple.com/app/id1359583808?mt=8",
.recommendToFriendEnabled: !VendorServices.shared.isBranded
.recommendToFriendEnabled: !VendorServices.shared.isBranded,

.watermarkEnabled: false,
.watermarkOpacity: 80,
.watermarkFontSize: 20,
.watermarkText: "",
.watermarkShowMail: true,
.watermarkShowDate: true,
.showScreenshotNotification: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a trailing comma here that should be removed.


]
}

Expand Down
2 changes: 2 additions & 0 deletions ownCloudAppShared/UIKit Extension/UIView+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

import UIKit
import ownCloudApp
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not needed and should be removed.



public extension UIView {
// MARK: - Animation
Expand Down
Loading
Loading