Skip to content

Commit

Permalink
Merge pull request #641 from TheBLVD/icloud-sync-beta-toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
inb4ohnoes authored Sep 12, 2024
2 parents 98f8623 + a8e6dc1 commit 7411b78
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions Mammoth/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
GlobalStruct.openLinksInReaderView = UserDefaults.standard.value(forKey: "openLinksInReaderView") as? Bool ?? false
GlobalStruct.preferredBrowser = UserDefaults.standard.string(forKey: "PreferredBrowser") ?? "In-App Browser"
GlobalStruct.appLock = UserDefaults.standard.value(forKey: "appLock") as? Bool ?? false
GlobalStruct.cloudSync = UserDefaults.standard.value(forKey: "cloudSync") as? Bool ?? false
GlobalStruct.shareAnalytics = UserDefaults.standard.value(forKey: "shareAnalytics") as? Bool ?? true

GlobalStruct.tab2 = UserDefaults.standard.value(forKey: "tab2") as? Bool ?? true
Expand Down
11 changes: 11 additions & 0 deletions Mammoth/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -65757,6 +65757,17 @@
}
}
},
"settings.cloudsync" : {
"comment" : "iCloud Sync settings title string",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "iCloud Sync - beta"
}
}
}
},
"settings.composer" : {
"comment" : "Button in settings.",
"extractionState" : "manual",
Expand Down
8 changes: 8 additions & 0 deletions Mammoth/Managers/CloudSyncManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CloudSyncManager {
}

public func enableSaving(forFeedType feedType: NewsFeedTypes) {
if !GlobalStruct.cloudSync { return }

switch feedType {
case .following:
shouldSaveFollowing = true
Expand Down Expand Up @@ -84,6 +86,8 @@ class CloudSyncManager {
}

public func saveSyncStatus(for type: NewsFeedTypes, scrollPosition: NewsFeedScrollPosition) {
if !GlobalStruct.cloudSync { return }

switch type {
case .following:
if !shouldSaveFollowing {
Expand Down Expand Up @@ -119,6 +123,8 @@ class CloudSyncManager {
}

public func cloudSavedPosition(for type: NewsFeedTypes) -> NewsFeedScrollPosition? {
if !GlobalStruct.cloudSync { return nil }

let (itemKey, dateKey) = keys(for: type)

guard !itemKey.isEmpty, !dateKey.isEmpty else { return nil }
Expand All @@ -136,6 +142,8 @@ class CloudSyncManager {
}

private func setSyncStatus(for type: NewsFeedTypes, scrollPosition: NewsFeedScrollPosition) {
if !GlobalStruct.cloudSync { return }

let (itemKey, dateKey) = keys(for: type)
guard !itemKey.isEmpty, !dateKey.isEmpty else { return }

Expand Down
1 change: 1 addition & 0 deletions Mammoth/Models/GlobalStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public struct GlobalStruct {
static var openLinksInReaderView: Bool = false
static var preferredBrowser: String = "In-App Browser"
static var appLock: Bool = false
static var cloudSync: Bool = false
static var shareAnalytics: Bool = true

// composer
Expand Down
6 changes: 5 additions & 1 deletion Mammoth/Screens/Settings/SettingsTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum SettingsItem {

case appLock

case cloudSync

case clearData

var title: String {
Expand All @@ -55,6 +57,7 @@ public enum SettingsItem {
case .openLinks: return NSLocalizedString("settings.openLinks", comment: "")
case .readerView: return NSLocalizedString("settings.readerView", comment: "")
case .appLock: return NSLocalizedString("settings.appLock", comment: "")
case .cloudSync: return NSLocalizedString("settings.cloudsync", comment: "iCloud Sync settings title string")
case .development: return NSLocalizedString("settings.development", comment: "")
case .analytics: return NSLocalizedString("settings.analytics", comment: "")
case .sourceCode: return NSLocalizedString("settings.sourceCode", comment: "")
Expand All @@ -78,6 +81,7 @@ public enum SettingsItem {
case .openLinks: return "\u{f08e}"
case .readerView: return "\u{e1d8}"
case .appLock: return "\u{f023}"
case .cloudSync: return "\u{f2f1}"
case .development: return "\u{f121}"
case .analytics: return "\u{f681}"
case .sourceCode: return "\u{f121}"
Expand All @@ -96,5 +100,5 @@ public enum SettingsItem {

public struct SettingsSection {
var items: [SettingsItem]
var footerTitle: String? = nil
var footerTitle: String?
}
41 changes: 37 additions & 4 deletions Mammoth/Screens/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ class SettingsViewController: UIViewController {
.pushNotifications,
.soundsAndHaptics,
.siriShortcuts
].compactMap{$0}),
].compactMap {$0}),
SettingsSection(items: [
.openLinks,
GlobalStruct.preferredBrowser == "In-App Browser" ? .readerView : nil,
.appLock
].compactMap{$0}),
].compactMap {$0}),
SettingsSection(items: [
.cloudSync
].compactMap {$0}),
SettingsSection(items: [
.getInTouch,
.subscriptions,
Expand All @@ -64,12 +67,15 @@ class SettingsViewController: UIViewController {
.pushNotifications,
.soundsAndHaptics,
.siriShortcuts
].compactMap{$0}),
].compactMap {$0}),
SettingsSection(items: [
.openLinks,
GlobalStruct.preferredBrowser == "In-App Browser" ? .readerView : nil,
.appLock
].compactMap{$0}),
].compactMap {$0}),
SettingsSection(items: [
.cloudSync
].compactMap {$0}),
SettingsSection(items: [
.getInTouch,
.development
Expand Down Expand Up @@ -226,6 +232,15 @@ class SettingsViewController: UIViewController {
}
}

@objc func switchCloudSync(_ sender: UISwitch) {
if sender.isOn {
GlobalStruct.cloudSync = true
UserDefaults.standard.setValue(true, forKey: "cloudSync")
} else {
GlobalStruct.cloudSync = false
UserDefaults.standard.setValue(false, forKey: "cloudSync")
}
}
}

// MARK: - UITableView
Expand Down Expand Up @@ -304,6 +319,24 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
cell.accessoryType = .none
cell.selectionStyle = .none
cell.textLabel?.textAlignment = .left
} else if item == .cloudSync {
let switchView = UISwitch(frame: .zero)
if UserDefaults.standard.value(forKey: "cloudSync") as? Bool != nil {
if UserDefaults.standard.value(forKey: "cloudSync") as? Bool == false {
switchView.setOn(false, animated: false)
} else {
switchView.setOn(true, animated: false)
}
} else {
switchView.setOn(false, animated: false)
}
switchView.onTintColor = .custom.gold

switchView.addTarget(self, action: #selector(switchCloudSync), for: .valueChanged)
cell.accessoryView = switchView
cell.accessoryType = .none
cell.selectionStyle = .none
cell.textLabel?.textAlignment = .left
} else if item == .clearData {
cell.accessoryView = nil
cell.accessoryType = .none
Expand Down

0 comments on commit 7411b78

Please sign in to comment.