mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
ios: chat preferences, UI and types (#1360)
This commit is contained in:
committed by
GitHub
parent
07e8c1d76e
commit
faceeb6fce
@@ -99,6 +99,16 @@ struct ChatInfoView: View {
|
||||
}
|
||||
}
|
||||
|
||||
Section("Preferences") {
|
||||
NavigationLink {
|
||||
ContactPreferencesView()
|
||||
.navigationBarTitle("Contact preferences")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
} label: {
|
||||
Text("Contact preferences")
|
||||
}
|
||||
}
|
||||
|
||||
Section("Servers") {
|
||||
networkStatusRow()
|
||||
.onTapGesture {
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// ContactPreferencesView.swift
|
||||
// SimpleX (iOS)
|
||||
//
|
||||
// Created by Evgeny on 13/11/2022.
|
||||
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
struct ContactPreferencesView: View {
|
||||
@State var allowFullDeletion = ContactFeatureAllowed.yes
|
||||
@State var allowVoice = ContactFeatureAllowed.yes
|
||||
@State var prefs = ContactUserPreferences(
|
||||
fullDelete: ContactUserPreference(
|
||||
enabled: FeatureEnabled(forUser: true, forContact: true),
|
||||
userPreference: .user(preference: Preference(allow: .yes)),
|
||||
contactPreference: Preference(allow: .no)
|
||||
),
|
||||
voice: ContactUserPreference(
|
||||
enabled: FeatureEnabled(forUser: true, forContact: true),
|
||||
userPreference: .user(preference: Preference(allow: .yes)),
|
||||
contactPreference: Preference(allow: .no)
|
||||
)
|
||||
)
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
featureSection(.fullDelete, .yes, prefs.fullDelete, $allowFullDeletion)
|
||||
featureSection(.voice, .yes, prefs.voice, $allowVoice)
|
||||
|
||||
Section {
|
||||
HStack {
|
||||
Text("Reset")
|
||||
Spacer()
|
||||
Text("Save")
|
||||
}
|
||||
.foregroundColor(.accentColor)
|
||||
.disabled(true)
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func featureSection(_ feature: Feature, _ userDefault: FeatureAllowed, _ pref: ContactUserPreference, _ allowFeature: Binding<ContactFeatureAllowed>) -> some View {
|
||||
let enabled = FeatureEnabled.enabled(
|
||||
user: Preference(allow: allowFeature.wrappedValue.allowed),
|
||||
contact: pref.contactPreference
|
||||
)
|
||||
return Section {
|
||||
Picker("You allow", selection: allowFeature) {
|
||||
ForEach(ContactFeatureAllowed.values(userDefault)) { allow in
|
||||
Text(allow.text)
|
||||
}
|
||||
}
|
||||
.frame(height: 36)
|
||||
HStack {
|
||||
Text("Contact allows")
|
||||
Spacer()
|
||||
Text(pref.contactPreference.allow.text)
|
||||
}
|
||||
} header: {
|
||||
HStack {
|
||||
Image(systemName: "\(feature.icon).fill")
|
||||
.foregroundColor(enabled.forUser ? .green : enabled.forContact ? .yellow : .red)
|
||||
Text(feature.text)
|
||||
}
|
||||
} footer: {
|
||||
Text(feature.enabledDescription(enabled))
|
||||
.frame(height: 36, alignment: .topLeading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContactPreferencesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContactPreferencesView()
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ struct DatabaseView: View {
|
||||
|
||||
Section {
|
||||
Picker("Delete messages after", selection: $chatItemTTL) {
|
||||
ForEach([ChatItemTTL.none, ChatItemTTL.month, ChatItemTTL.week, ChatItemTTL.day]) { ttl in
|
||||
ForEach(ChatItemTTL.values) { ttl in
|
||||
Text(ttl.deleteAfterText).tag(ttl)
|
||||
}
|
||||
if case .seconds = chatItemTTL {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// 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 {
|
||||
@State var allowFullDeletion = FeatureAllowed.yes
|
||||
@State var allowVoice = FeatureAllowed.yes
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
featureSection(.fullDelete, $allowFullDeletion)
|
||||
featureSection(.voice, $allowVoice)
|
||||
|
||||
Section {
|
||||
HStack {
|
||||
Text("Reset")
|
||||
Spacer()
|
||||
Text("Save")
|
||||
}
|
||||
.foregroundColor(.accentColor)
|
||||
.disabled(true)
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func featureSection(_ feature: Feature, _ allowFeature: Binding<FeatureAllowed>) -> some View {
|
||||
Section {
|
||||
settingsRow(feature.icon) {
|
||||
Picker(feature.text, selection: allowFeature) {
|
||||
ForEach(FeatureAllowed.values) { allow in
|
||||
Text(allow.text)
|
||||
}
|
||||
}
|
||||
.frame(height: 36)
|
||||
}
|
||||
} footer: {
|
||||
Text(feature.allowDescription(allowFeature.wrappedValue))
|
||||
.frame(height: 36, alignment: .topLeading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PreferencesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PreferencesView()
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,13 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
Section("Settings") {
|
||||
NavigationLink {
|
||||
PreferencesView()
|
||||
.navigationTitle("Your preferences")
|
||||
} label: {
|
||||
settingsRow("list.bullet") { Text("Chat preferences") }
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
NotificationsView()
|
||||
.navigationTitle("Notifications")
|
||||
|
||||
Reference in New Issue
Block a user