Default posting visibility

This commit is contained in:
Lumaa 2024-03-08 14:28:54 +01:00
parent 81793f9842
commit 9f9307b053
4 changed files with 120 additions and 20 deletions

View File

@ -12,15 +12,17 @@ class UserPreferences: Codable, ObservableObject {
var profilePictureShape: ProfilePictureShape = .circle
var browserType: BrowserType = .inApp
var defaultVisibility: Visibility = .pub
// Experimental
var showExperimental: Bool = false
var experimental: UserPreferences.Experimental
init(displayedName: DisplayedName = .username, profilePictureShape: ProfilePictureShape = .circle, browserType: BrowserType = .inApp, showExperimental: Bool = false, experimental: UserPreferences.Experimental = .init()) {
init(displayedName: DisplayedName = .username, profilePictureShape: ProfilePictureShape = .circle, browserType: BrowserType = .inApp, defaultVisibility: Visibility = .pub, showExperimental: Bool = false, experimental: UserPreferences.Experimental = .init()) {
self.displayedName = displayedName
self.profilePictureShape = profilePictureShape
self.browserType = browserType
self.defaultVisibility = defaultVisibility
self.showExperimental = showExperimental
self.experimental = experimental

View File

@ -696,7 +696,20 @@
}
},
"coming-soon" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Coming Soon"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Bientôt"
}
}
}
},
"discovery" : {
"localizations" : {
@ -1466,6 +1479,22 @@
}
}
},
"setting.privacy.default-visibility" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Default posting visibility"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Visibilité par défaut des publications"
}
}
}
},
"setting.support" : {
"localizations" : {
"en" : {
@ -1572,7 +1601,7 @@
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Supprimer"
}
}
@ -3015,4 +3044,4 @@
}
},
"version" : "1.0"
}
}

View File

@ -17,6 +17,7 @@ struct PostingView: View {
@State private var hasKeyboard: Bool = true
@State private var visibility: Visibility = .pub
@State private var pref: UserPreferences = .defaultPreferences
@State private var selectingPhotos: Bool = false
@State private var mediaContainers: [MediaContainer] = []
@ -161,6 +162,9 @@ struct PostingView: View {
}
}
.onAppear {
self.pref = try! UserPreferences.loadAsCurrent()!
self.visibility = pref.defaultVisibility
if !initialString.isEmpty && editId == nil {
viewModel.append(text: initialString + " ") // add space for quick typing
} else {

View File

@ -4,35 +4,100 @@ import SwiftUI
import Nuke
struct PrivacyView: View {
@ObservedObject private var userPreferences: UserPreferences = .defaultPreferences
@EnvironmentObject private var navigator: Navigator
@Environment(\.dismiss) private var dismiss
@State private var clearedCache: Bool = false
var body: some View {
List {
//TODO: Visibilty, Blocklist & Mutelist
//TODO: Blocklist & Mutelist
HStack {
Text("settings.privacy.clear-cache")
Spacer()
Button {
let cache = ImagePipeline.shared.cache
cache.removeAll()
withAnimation(.spring) {
clearedCache = true
Picker(LocalizedStringKey("setting.privacy.default-visibility"), selection: $userPreferences.defaultVisibility) {
ForEach(Visibility.allCases, id: \.self) { visibility in
switch (visibility) {
case .pub:
Text("status.posting.visibility.public")
case .priv:
Text("status.posting.visibility.private")
case .unlisted:
Text("status.posting.visibility.unlisted")
case .direct:
Text("status.posting.visibility.direct")
}
} label: {
Text(clearedCache ? "settings.privacy.cleared" : "settings.privacy.clear")
.foregroundStyle(clearedCache ? Color(uiColor: UIColor.label) : Color(uiColor: UIColor.systemBackground))
}
.buttonStyle(LargeButton(filled: true, filledColor: clearedCache ? Color.green : Color(uiColor: UIColor.label), height: 7.5))
.disabled(clearedCache)
}
.pickerStyle(.inline)
.listRowThreaded()
Spacer()
.frame(height: 30)
.listRowThreaded()
Section {
HStack {
Text("settings.privacy.clear-cache")
Spacer()
Button {
let cache = ImagePipeline.shared.cache
cache.removeAll()
withAnimation(.spring) {
clearedCache = true
}
} label: {
Text(clearedCache ? "settings.privacy.cleared" : "settings.privacy.clear")
.foregroundStyle(clearedCache ? Color(uiColor: UIColor.label) : Color(uiColor: UIColor.systemBackground))
}
.buttonStyle(LargeButton(filled: true, filledColor: clearedCache ? Color.green : Color(uiColor: UIColor.label), height: 7.5))
.disabled(clearedCache)
}
}
.listRowThreaded()
}
.listThreaded()
.navigationTitle(Text("privacy"))
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden()
.onAppear {
loadOld()
}
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button {
loadOld()
dismiss()
} label: {
Text("settings.cancel")
}
}
ToolbarItem(placement: .primaryAction) {
Button {
do {
try userPreferences.saveAsCurrent()
dismiss()
} catch {
print(error)
}
} label: {
Text("settings.done")
}
}
}
}
private func loadOld() {
do {
let oldPreferences = try UserPreferences.loadAsCurrent() ?? UserPreferences.defaultPreferences
userPreferences.defaultVisibility = oldPreferences.defaultVisibility
} catch {
print(error)
dismiss()
}
}
}