mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-20 12:55:58 +00:00
* current user picker progress
* one hand picker
* thin bullet icon
* more user picker buttons
* button clickable areas
* divider padding
* extra space after sun
* send current user option to address view
* add unread count badge
* with anim for apperance close
* edit current profile from picker
* remove you section from settings
* remove help and support
* simplify
* move settings and sun to same row
* remove redundant vstack
* long press on sun/moon switches to system setting
* remove back button from migrate device
* smooth profile transitions
* close user picker on list profiles
* fix dismiss on migrate from device
* fix dismiss when deleting last visible user while having hidden users
* picker visibility toggle tweaks
* remove strange square from profile switcher click
* dirty way to save auto accept settings on dismiss
* Revert "dirty way to save auto accept settings on dismiss"
This reverts commit e7b19ee8aa.
* consistent animation on user picker toggle
* change space between profiles
* remove result
* ignore result
* unread badge
* move to sheet
* half sheet on one hand ui
* fix dismiss on device migration
* fix desktop connect
* sun to meet other action icons
* fill bullet list button
* fix tap in settings to take full width
* icon sizings and paddings
* open settings in same sheet
* apply same trick as other buttons for ligth toggle
* layout
* open profiles sheet large when +3 users
* layout
* layout
* paddings
* paddings
* remove show progress
* always small user picker
* fixed height
* open all actions as sheets
* type, color
* simpler and more effective way of avoid moving around on user select
* dismiss user profiles sheet on user change
* connect desktop back button remove
* remove back buttons from user address view
* remove porgress
* header inside list
* alert on auto accept unsaved changes
* Cancel -> Discard
* revert
* fix connect to desktop
* remove extra space
* fix share inside multi sheet
* user picker and options as separate sheet
* revert showShareSheet
* fix current profile and all profiles selection
* change alert
* update
* cleanup user address
* remove func
* alert on unsaved changes in chat prefs
* fix layout
* cleanup
---------
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
109 lines
4.0 KiB
Swift
109 lines
4.0 KiB
Swift
//
|
|
// PreferencesView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by Evgeny on 13/11/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct PreferencesView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@EnvironmentObject var theme: AppTheme
|
|
@State var profile: LocalProfile
|
|
@State var preferences: FullPreferences
|
|
@State var currentPreferences: FullPreferences
|
|
|
|
var body: some View {
|
|
VStack {
|
|
List {
|
|
timedMessagesFeatureSection($preferences.timedMessages.allow)
|
|
featureSection(.fullDelete, $preferences.fullDelete.allow)
|
|
featureSection(.reactions, $preferences.reactions.allow)
|
|
featureSection(.voice, $preferences.voice.allow)
|
|
featureSection(.calls, $preferences.calls.allow)
|
|
|
|
Section {
|
|
Button("Reset") { preferences = currentPreferences }
|
|
Button("Save (and notify contacts)") { savePreferences() }
|
|
}
|
|
.disabled(currentPreferences == preferences)
|
|
}
|
|
}
|
|
.onDisappear {
|
|
if currentPreferences != preferences {
|
|
AlertManager.shared.showAlert(Alert(
|
|
title: Text("Your chat preferences"),
|
|
message: Text("Chat preferences were changed."),
|
|
primaryButton: .default(Text("Save")) {
|
|
savePreferences()
|
|
},
|
|
secondaryButton: .cancel()
|
|
))
|
|
}
|
|
}
|
|
}
|
|
|
|
private func featureSection(_ feature: ChatFeature, _ allowFeature: Binding<FeatureAllowed>) -> some View {
|
|
Section {
|
|
settingsRow(feature.icon, color: theme.colors.secondary) {
|
|
Picker(feature.text, selection: allowFeature) {
|
|
ForEach(FeatureAllowed.values) { allow in
|
|
Text(allow.text)
|
|
}
|
|
}
|
|
.frame(height: 36)
|
|
}
|
|
}
|
|
footer: { featureFooter(feature, allowFeature).foregroundColor(theme.colors.secondary) }
|
|
|
|
}
|
|
|
|
private func timedMessagesFeatureSection(_ allowFeature: Binding<FeatureAllowed>) -> some View {
|
|
Section {
|
|
let allow = Binding(
|
|
get: { allowFeature.wrappedValue == .always || allowFeature.wrappedValue == .yes },
|
|
set: { yes, _ in allowFeature.wrappedValue = yes ? .yes : .no }
|
|
)
|
|
settingsRow(ChatFeature.timedMessages.icon, color: theme.colors.secondary) {
|
|
Toggle(ChatFeature.timedMessages.text, isOn: allow)
|
|
}
|
|
}
|
|
footer: { featureFooter(.timedMessages, allowFeature).foregroundColor(theme.colors.secondary) }
|
|
}
|
|
|
|
private func featureFooter(_ feature: ChatFeature, _ allowFeature: Binding<FeatureAllowed>) -> some View {
|
|
Text(feature.allowDescription(allowFeature.wrappedValue))
|
|
}
|
|
|
|
private func savePreferences() {
|
|
Task {
|
|
do {
|
|
var p = fromLocalProfile(profile)
|
|
p.preferences = fullPreferencesToPreferences(preferences)
|
|
if let (newProfile, updatedContacts) = try await apiUpdateProfile(profile: p) {
|
|
await MainActor.run {
|
|
chatModel.updateCurrentUser(newProfile, preferences)
|
|
updatedContacts.forEach(chatModel.updateContact)
|
|
currentPreferences = preferences
|
|
}
|
|
}
|
|
} catch {
|
|
logger.error("PreferencesView apiUpdateProfile error: \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct PreferencesView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
PreferencesView(
|
|
profile: LocalProfile(profileId: 1, displayName: "alice", fullName: "", localAlias: ""),
|
|
preferences: FullPreferences.sampleData,
|
|
currentPreferences: FullPreferences.sampleData
|
|
)
|
|
}
|
|
}
|