Page MenuHomeMusing Studio

No OneTemporary

diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift
index 32df675..d2e7925 100644
--- a/Shared/PostList/PostListView.swift
+++ b/Shared/PostList/PostListView.swift
@@ -1,131 +1,139 @@
import SwiftUI
struct PostListView: View {
@EnvironmentObject var model: WriteFreelyModel
@Environment(\.managedObjectContext) var moc
@State var selectedCollection: WFACollection?
@State var showAllPosts: Bool = false
var body: some View {
#if os(iOS)
GeometryReader { geometry in
PostListFilteredView(filter: selectedCollection?.alias, showAllPosts: showAllPosts)
.navigationTitle(
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
)
)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: {
createNewLocalDraft()
}, label: {
Image(systemName: "square.and.pencil")
})
}
ToolbarItem(placement: .bottomBar) {
HStack {
Button(action: {
model.isPresentingSettingsView = true
}, label: {
Image(systemName: "gear")
})
.padding(.leading)
Spacer()
Text(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.foregroundColor(.secondary)
Spacer()
Button(action: {
reloadFromServer()
}, label: {
Image(systemName: "arrow.clockwise")
})
.disabled(!model.account.isLoggedIn || !model.hasNetworkConnection)
}
.padding()
.frame(width: geometry.size.width)
}
}
}
#else //if os(macOS)
PostListFilteredView(filter: selectedCollection?.alias, showAllPosts: showAllPosts)
.navigationTitle(
showAllPosts ? "All Posts" : selectedCollection?.title ?? (
model.account.server == "https://write.as" ? "Anonymous" : "Drafts"
)
)
.navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.toolbar {
Button(action: {
createNewLocalDraft()
}, label: {
Image(systemName: "square.and.pencil")
})
Button(action: {
reloadFromServer()
}, label: {
Image(systemName: "arrow.clockwise")
})
.disabled(!model.account.isLoggedIn || !model.hasNetworkConnection)
}
#endif
}
private func pluralizedPostCount(for posts: [WFAPost]) -> String {
if posts.count == 1 {
return "1 post"
} else {
return "\(posts.count) posts"
}
}
private func showPosts(for collection: WFACollection?) -> [WFAPost] {
if showAllPosts {
return model.posts.userPosts
} else {
if let selectedCollection = collection {
return model.posts.userPosts.filter { $0.collectionAlias == selectedCollection.alias }
} else {
return model.posts.userPosts.filter { $0.collectionAlias == nil }
}
}
}
private func reloadFromServer() {
DispatchQueue.main.async {
model.fetchUserCollections()
model.fetchUserPosts()
}
}
private func createNewLocalDraft() {
let managedPost = WFAPost(context: LocalStorageManager.persistentContainer.viewContext)
managedPost.createdDate = Date()
managedPost.title = ""
managedPost.body = ""
managedPost.status = PostStatus.local.rawValue
+ switch model.preferences.font {
+ case 1:
+ managedPost.appearance = "sans"
+ case 2:
+ managedPost.appearance = "wrap"
+ default:
+ managedPost.appearance = "serif"
+ }
if let languageCode = Locale.current.languageCode {
managedPost.language = languageCode
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
}
if let selectedCollectionAlias = selectedCollection?.alias {
managedPost.collectionAlias = selectedCollectionAlias
}
DispatchQueue.main.async {
LocalStorageManager().saveContext()
}
model.selectedPost = managedPost
}
}
struct PostListView_Previews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.persistentContainer.viewContext
let model = WriteFreelyModel()
return PostListView()
.environment(\.managedObjectContext, context)
.environmentObject(model)
}
}
diff --git a/Shared/Preferences/PreferencesView.swift b/Shared/Preferences/PreferencesView.swift
index 26168e3..1522450 100644
--- a/Shared/Preferences/PreferencesView.swift
+++ b/Shared/Preferences/PreferencesView.swift
@@ -1,28 +1,56 @@
import SwiftUI
struct PreferencesView: View {
@ObservedObject var preferences: PreferencesModel
var body: some View {
- #if os(iOS)
- Picker(selection: $preferences.appearance, label: Text("Appearance")) {
- Text("System").tag(0)
- Text("Light").tag(1)
- Text("Dark").tag(2)
- }
- .pickerStyle(SegmentedPickerStyle())
- #elseif os(macOS)
- Picker(selection: $preferences.appearance, label: Text("Appearance")) {
- Text("System").tag(0)
- Text("Light").tag(1)
- Text("Dark").tag(2)
+ VStack {
+ VStack {
+ Text("Choose the preferred appearance for the app.")
+ .font(.caption)
+ .foregroundColor(.secondary)
+ Picker(selection: $preferences.appearance, label: Text("Appearance")) {
+ Text("System").tag(0)
+ Text("Light").tag(1)
+ Text("Dark").tag(2)
+ }
+ .pickerStyle(SegmentedPickerStyle())
+ }
+ .padding(.bottom)
+
+ VStack {
+ Text("Choose the default font for new posts.")
+ .font(.caption)
+ .foregroundColor(.secondary)
+ Picker(selection: $preferences.font, label: Text("Default Font")) {
+ Text("Serif").tag(0)
+ Text("Sans-Serif").tag(1)
+ Text("Monospace").tag(2)
+ }
+ .pickerStyle(SegmentedPickerStyle())
+ .padding(.bottom)
+ switch preferences.font {
+ case 1:
+ Text("Sample Text")
+ .frame(width: 240, height: 50, alignment: .center)
+ .font(.custom("OpenSans-Regular", size: 20))
+ case 2:
+ Text("Sample Text")
+ .frame(width: 240, height: 50, alignment: .center)
+ .font(.custom("Hack-Regular", size: 20))
+ default:
+ Text("Sample Text")
+ .frame(width: 240, height: 50, alignment: .center)
+ .font(.custom("Lora", size: 20))
+ }
+ }
+ .padding(.bottom)
}
- #endif
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
PreferencesView(preferences: PreferencesModel())
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Mar 12, 11:58 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3653767

Event Timeline