Settings & Account
Relevant source files
The following files were used as context for generating this wiki page:
- Putio/Features/Settings/SettingsViewModel.swift
- Putio/Features/Settings/SettingsViewModel+Sections.swift
- Putio/Features/Settings/SettingsViewModel+Persistence.swift
- Putio/Features/Settings/SettingsModel.swift
- Putio/Common/Models/UserModel.swift
- Putio/Common/API/PutioSDK.swift
- Putio/AppDelegate.swift
The Settings & Account module manages user profile information, application preferences, security configurations, and data persistence for the put.io iOS client. It serves as the central hub for modifying account-level behaviors, such as storage usage visualization, default file sorting, media playback proxies, and security settings like Two-Factor Authentication (2FA).
The system follows a Model-View-ViewModel (MVVM) architecture, utilizing Realm for local state persistence and the PutioSDK for remote synchronization. It ensures that changes made within the app are reflected on the put.io servers while maintaining a responsive UI through local caching and reactive observers.
Sources: Putio/Features/Settings/SettingsViewModel.swift, Putio/Features/Settings/SettingsViewModel+Sections.swift
Architecture and Data Flow
The module is driven by the SettingsViewModel, which orchestrates data retrieval from both the local Realm database and the remote API. It maintains references to User, UserSettings, and UserConfig objects.
Data Synchronization Flow
When the Settings view is initialized or data is fetched, the ViewModel follows a structured flow to ensure the UI stays in sync with the backend.
Key Components
| Component | Responsibility |
|---|---|
SettingsViewModel | Manages state, handles remote mutations, and builds UI sections. |
SettingsModel | Defines the data structures for sections and items (SectionItemType). |
PutioRealm | Handles local storage and object notifications for reactive updates. |
PutioSDK | Provides the interface for network requests such as saveAccountSettings. |
User / UserSettings | Realm models representing account info and preference flags. |
Sources: Putio/Features/Settings/SettingsModel.swift:5-40, Putio/Common/Models/UserModel.swift:7-60
Settings Sections and Management
The settings interface is organized into logical sections, each containing specific configuration items. The buildSections function dynamically constructs these based on the current user state and settings.
Section Breakdown
- Information: Displays account identifiers like
UsernameandEmail address. - Storage: Controls how disk usage is displayed (Optimistic vs. Standard) and manages Trash settings.
- Files: Configures default sorting options (Name, Size, Date, etc.).
- Media Playback: Configures HLS/MP4 playback for Chromecast, subtitle visibility, and proxy routes.
- Security: Manages 2FA, recovery codes, and active sessions.
- Privacy & Support: Controls history population and provides links to App Store ratings or Intercom support.
- Danger Zone: Provides destructive actions like clearing data or account destruction.
Sources: Putio/Features/Settings/SettingsViewModel+Sections.swift:10-210
Mutation Logic
Remote mutations follow a "perform-and-update" pattern. The app displays a "Saving..." alert, executes the API call via PutioSDK, and upon success, writes the change to Realm before updating the local ViewModel state.
Data Models and Configuration
The module relies on persistent Realm objects to store the state of the user's account and preferences.
User Settings Model (UserSettings)
This model stores the flags that control application behavior.
| Field | Type | Description |
|---|---|---|
routeName | String | The selected proxy tunnel route (e.g., "Amsterdam"). |
historyEnabled | Bool | Toggles whether activity history is populated. |
trashEnabled | Bool | Enables moving deleted files to trash instead of permanent deletion. |
sortBy | String | The default sorting string (e.g., "NAME_ASC"). |
showOptimisticUsage | Bool | Toggles between "Used" and "Free" storage display. |
twoFactorEnabled | Bool | Status of Two-Factor Authentication. |
hideSubtitles | Bool | Global toggle for subtitle visibility. |
Sources: Putio/Common/Models/UserModel.swift:42-60
Implementation Detail: Sorting State
Sorting preferences are stored as a combined string (e.g., NAME_DESC). The ViewModel parses this into selectedSortByKey and selectedSortByDirection to drive the UI selection state.
func updateSelectedSortState() {
let components = settings.sortBy.split(separator: "_")
guard components.count == 2 else {
selectedSortByKey = SettingsModel.sortByKeys.first!
selectedSortByDirection = SettingsModel.SortByDirection(key: "ASC")
return
}
let nextSortKey = String(components[0])
let nextSortDirection = String(components[1])
selectedSortByKey = SettingsModel.sortByKeys.first { $0.key == nextSortKey } ?? SettingsModel.sortByKeys.first!
selectedSortByDirection = SettingsModel.SortByDirection(key: nextSortDirection)
}
Sources: Putio/Features/Settings/SettingsViewModel.swift:132-145
Authentication and Session Management
The AppDelegate manages the lifecycle of the user session, interacting with the Settings & Account data during login and logout.
- Login: When a user authenticates, the
fetchUsermethod retrieves both account info and global configuration, persisting them to Realm viaPutioRealm.replaceUserSession. - Logout: The
logoutmethod clears the keychain token, wipes video playback positions, and resets the Intercom session before returning to the login screen.
Sources: Putio/AppDelegate.swift:171-181, Putio/AppDelegate.swift:257-263
Summary
The Settings & Account system provides a robust framework for managing user-specific configurations. By combining PutioSDK for remote state management with Realm for local persistence, it ensures that user preferences are consistently applied across app sessions. The use of a modular section-building logic in the ViewModel allows for easy expansion of settings items while maintaining clear separation between UI representation and data persistence logic.