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

Revamp Settings Section: Complete Migration to Swift & SwiftUI #2826

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e891877
Added Navigation between NCSettings + NCMore
adityagi02 Mar 2, 2024
c10a33d
Added Settings screen UI
adityagi02 Mar 3, 2024
fffd8c9
Added common NCWebBrowserView + AcknowledgementsView
adityagi02 Mar 4, 2024
4ff2489
Added Settings ViewModel & connected with View
adityagi02 Mar 5, 2024
76f270c
Added AutoUpload UI
adityagi02 Mar 6, 2024
ecf6e7f
Updated AutoUpload UI
adityagi02 Mar 6, 2024
dfbe5d2
Added AutoUpload ViewModel + UI Integration
adityagi02 Mar 8, 2024
c754419
Added Advanced View UI
adityagi02 Mar 8, 2024
ad68d56
Added CCAdvancedViewModel + UI Integration
adityagi02 Mar 9, 2024
d9d8cda
Updated CCAdvanced ViewModel + View
adityagi02 Mar 10, 2024
6d3622b
Added ManageAutoUploadView
adityagi02 Mar 11, 2024
5ec0d91
Added AutoUploadFileNamesViewModel + UI Intetegration
adityagi02 Mar 12, 2024
b06e480
Added Protocols + Updated ViewModel & View Integration
adityagi02 Mar 17, 2024
f0e0bda
Added protocol for AutoUpload
adityagi02 Mar 17, 2024
019fbe4
Added & Updated protocols for Settings
adityagi02 Mar 17, 2024
f086183
Added protocol + Updated Settings ViewModels
adityagi02 Mar 17, 2024
33f330e
Updated Settings brand strings
adityagi02 Mar 17, 2024
bdaa216
Added Passcode View
adityagi02 Mar 28, 2024
a73f29a
Added Capabilities Navigation
adityagi02 Mar 29, 2024
55a222d
Added E2EE View + Auto Folder Upload Path
adityagi02 Apr 6, 2024
e0b7dfd
Added standard File Header
adityagi02 Apr 6, 2024
a36acb5
Added lockScreen toggle logic
adityagi02 Apr 7, 2024
1962dfb
Implemented UI update on account switch
adityagi02 Apr 7, 2024
094f60c
Updated project file
adityagi02 Apr 7, 2024
b7a3b19
Removed failing defaultViewModifier
adityagi02 Apr 7, 2024
8998532
Requested Changes Added
adityagi02 Apr 9, 2024
fda1a64
OpenSSL switched back to remote
adityagi02 Apr 11, 2024
89164bd
Merge branch 'develop' into settings-revamp
adityagi02 Apr 11, 2024
2028072
Added serverUrl in SelectView
adityagi02 Apr 12, 2024
5534689
Improved scene (#2875)
marinofaggiana Apr 12, 2024
343fc0b
fix
marinofaggiana Apr 12, 2024
e6a298a
Test fix
mpivchev Apr 12, 2024
0b8ec9c
Lint
marinofaggiana Apr 12, 2024
ed46c49
Merge branch 'develop' into settings-revamp
adityagi02 Apr 14, 2024
e51a268
Removed new DB instances
adityagi02 Apr 24, 2024
825d0dc
Resolved unwanted E2EE Api calls
adityagi02 Apr 24, 2024
fe5562f
Cleared out lint warnings
adityagi02 Apr 24, 2024
465b57f
Updated Localizable + WebVeiw Lint
adityagi02 Apr 25, 2024
4f2030c
Merge branch 'develop' of https://github.com/nextcloud/ios into pr/2826
mpivchev Apr 26, 2024
76e08ac
Updated ViewModel to model + Removed protocols
adityagi02 Apr 27, 2024
56f2e36
Updated Text font & Image color
adityagi02 Apr 27, 2024
fa54801
Removed XLForm/Obj-C legacy code
adityagi02 Apr 27, 2024
5586462
Removed background thread warning
adityagi02 May 3, 2024
879f6f6
Resolved reviewed code bugs
adityagi02 May 4, 2024
36e6e67
Fixed some minor bugs
adityagi02 May 4, 2024
f4f40ae
Removed unneccessary space string/ added buttons
adityagi02 May 6, 2024
13cb8c4
Merge
adityagi02 May 7, 2024
767cbcc
Added Dark Mode UI image color
adityagi02 May 7, 2024
e1e2ead
Merge branch 'develop'
adityagi02 May 9, 2024
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
205 changes: 143 additions & 62 deletions Nextcloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion iOSClient/Diagnostics/NCCapabilitiesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct NCCapabilitiesView: View {
CapabilityName(text: $capabilitiesViewOO.homeServer, image: Image(systemName: "house"), resize: false)
}
}
}
}.navigationBarTitle(NSLocalizedString("_capabilities_", comment: ""))
.frame(maxWidth: .infinity, alignment: .top)
}

Expand Down
13 changes: 11 additions & 2 deletions iOSClient/More/NCMore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,18 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
tapImageLogoManageAccount()
return
}
// Checking if the selected row is the Settings cell
if item.name == "_settings_" {
// Created an instance of the NCSettings view
let ncSettingsView = NCSettings(model: NCSettingsModel())

// Created a hosting controller for the NCSettings view & performing the segue
let hostingController = UIHostingController(rootView: ncSettingsView)
self.navigationController?.pushViewController(hostingController, animated: true)
}

// Action
if item.url.contains("segue") && !item.url.contains("//") {
// Action conditions
if item.url.contains("segue") && item.name != "_settings_" && !item.url.contains("//") {
self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
} else if item.url.contains("openStoryboard") && !item.url.contains("//") {
let nameStoryboard = item.url.replacingOccurrences(of: "openStoryboard", with: "")
Expand Down
61 changes: 0 additions & 61 deletions iOSClient/Settings/Acknowledgements.m

This file was deleted.

175 changes: 175 additions & 0 deletions iOSClient/Settings/AutoUpload/AutoUploadModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//
// AutoUploadViewModel.swift
// Nextcloud
//
// Created by Aditya Tyagi on 08/03/24.
// Copyright © 2024 Marino Faggiana. All rights reserved.
//
// Author Aditya Tyagi <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import NextcloudKit

/// A model that allows the user to configure the `auto upload settings for Nextcloud`
class AutoUploadModel: ObservableObject, ViewOnAppearHandling, NCSelectDelegate {
var appDelegate = AppDelegate()
/// A state variable that indicates whether auto upload is enabled or not
@Published var autoUpload: Bool = false
/// A state variable that indicates whether to open NCSelect View or not
@Published var autoUploadFolder: Bool = false
/// A state variable that indicates whether auto upload for photos is enabled or not
@Published var autoUploadImage: Bool = false
/// A state variable that indicates whether auto upload for photos is restricted to Wi-Fi only or not
@Published var autoUploadWWAnPhoto: Bool = false
/// A state variable that indicates whether auto upload for videos is enabled or not
@Published var autoUploadVideo: Bool = false
/// A state variable that indicates whether auto upload for videos is enabled or not
@Published var autoUploadWWAnVideo: Bool = false
/// A state variable that indicates whether auto upload for full resolution photos is enabled or not
@Published var autoUploadFull: Bool = false
/// A state variable that indicates whether auto upload creates subfolders based on date or not
@Published var autoUploadCreateSubfolder: Bool = false
/// A state variable that indicates the granularity of the subfolders, either daily, monthly, or yearly
@Published var autoUploadSubfolderGranularity: Granularity = .monthly
/// A state variable that shows error in view in case of an error
@Published var showErrorAlert: Bool = false
@Published var sectionName = ""
@Published var isAuthorized: Bool = false
/// A string variable that contains error text
@Published var error: String = ""
private let manageDatabase = NCManageDatabase.shared
@Published var autoUploadPath = "\(NCManageDatabase.shared.getAccountAutoUploadFileName())"
var serverUrl: String = NCUtilityFileSystem().getHomeServer(urlBase: AppDelegate().urlBase, userId: AppDelegate().userId)
/// Initialization code to set up the ViewModel with the active account
init() {
onViewAppear()
}
// MARK: All functions
/// A function to update the published properties based on the active account
func onViewAppear() {
let activeAccount: tableAccount? = NCManageDatabase.shared.getActiveAccount()
if let account = activeAccount {
autoUpload = account.autoUpload
autoUploadImage = account.autoUploadImage
autoUploadWWAnPhoto = account.autoUploadWWAnPhoto
autoUploadVideo = account.autoUploadVideo
autoUploadWWAnVideo = account.autoUploadWWAnVideo
autoUploadFull = account.autoUploadFull
autoUploadCreateSubfolder = account.autoUploadCreateSubfolder
autoUploadSubfolderGranularity = Granularity(rawValue: account.autoUploadSubfolderGranularity) ?? .monthly
if autoUpload {
requestAuthorization()
}
}
}
func requestAuthorization() {
PHPhotoLibrary.requestAuthorization { status in
DispatchQueue.main.async {
self.isAuthorized = status == .authorized
}
}
}
/// Updates the auto-upload setting.
func handleAutoUploadChange(newValue: Bool) {
updateAccountProperty(\.autoUpload, value: newValue)
}
/// Updates the auto-upload image setting.
func handleAutoUploadImageChange(newValue: Bool) {
updateAccountProperty(\.autoUploadImage, value: newValue)
}
/// Updates the auto-upload image over WWAN setting.
func handleAutoUploadWWAnPhotoChange(newValue: Bool) {
updateAccountProperty(\.autoUploadWWAnPhoto, value: newValue)
}
/// Updates the auto-upload video setting.
func handleAutoUploadVideoChange(newValue: Bool) {
updateAccountProperty(\.autoUploadVideo, value: newValue)
}
/// Updates the auto-upload video over WWAN setting.
func handleAutoUploadWWAnVideoChange(newValue: Bool) {
updateAccountProperty(\.autoUploadWWAnVideo, value: newValue)
}
/// Updates the auto-upload full content setting.
func handleAutoUploadFullChange(newValue: Bool) {
updateAccountProperty(\.autoUploadFull, value: newValue)
}
/// Updates the auto-upload create subfolder setting.
func handleAutoUploadCreateSubfolderChange(newValue: Bool) {
updateAccountProperty(\.autoUploadCreateSubfolder, value: newValue)
}
/// Updates the auto-upload subfolder granularity setting.
func handleAutoUploadSubfolderGranularityChange(newValue: Granularity) {
updateAccountProperty(\.autoUploadSubfolderGranularity, value: newValue.rawValue)
}
/// Updates a property of the active account in the database.
private func updateAccountProperty<T>(_ keyPath: ReferenceWritableKeyPath<tableAccount, T>, value: T) {
guard let activeAccount = manageDatabase.getActiveAccount() else { return }
activeAccount[keyPath: keyPath] = value
manageDatabase.updateAccount(activeAccount)
}
/// Returns the path for auto-upload based on the active account's settings.
///
/// - Returns: The path for auto-upload.
func returnPath() -> String {
let path = NCManageDatabase.shared.getAccountAutoUploadFileName()
let userEmail = NCManageDatabase.shared.getActiveAccount()?.email

// Check if userEmail is a present in userEmail
guard let range = path.range(of: userEmail ?? "") else {
return "" // Return etymp if userEmail is not found in path
}
// Get the range of the substring after string2
let uploadPath = Range(uncheckedBounds: (range.upperBound, path.endIndex))
// Extract the uploadPath
return path.substring(with: uploadPath)
}
/// Sets the auto-upload directory based on the provided server URL.
///
/// - Parameter
/// serverUrl: The server URL to set as the auto-upload directory.
func setAutoUploadDirectory(serverUrl: String?) {
guard let serverUrl = serverUrl else { return }

// It checks if the provided server URL is the home server. If it is, an error is set, and the function returns early.
let home = NCUtilityFileSystem().getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId)
if serverUrl == home {
let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: NSLocalizedString("_autoupload_error_select_folder_", comment: ""), responseData: nil)
self.error = error.errorDescription
self.showErrorAlert = true
return
}

// Otherwise, it updates the auto-upload directory in the database
NCManageDatabase.shared.setAccountAutoUploadFileName(serverUrl)
if let path = NCUtilityFileSystem().deleteLastPath(serverUrlPath: serverUrl, home: home) {
NCManageDatabase.shared.setAccountAutoUploadDirectory(path, urlBase: appDelegate.urlBase, userId: appDelegate.userId, account: appDelegate.account)
}
onViewAppear()
}
// MARK: NCSelectDelegate
func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {}
}

/// An enum that represents the granularity of the subfolders for auto upload
enum Granularity: Int {
/// Daily granularity, meaning the subfolders are named by day
case daily = 2
/// Monthly granularity, meaning the subfolders are named by month
case monthly = 1
/// Yearly granularity, meaning the subfolders are named by year
case yearly = 0
}
Loading