Browse Source

Update views on a timer

master
Peter Hajas 3 years ago
parent
commit
e9c88407ba
  1. 6
      Kordophone/Kordophone.xcodeproj/project.pbxproj
  2. 4
      Kordophone/Shared/ConversationList.swift
  3. 4
      Kordophone/Shared/ConversationView.swift
  4. 12
      Kordophone/Shared/IntervalUpdater.swift

6
Kordophone/Kordophone.xcodeproj/project.pbxproj

@ -19,6 +19,8 @@
4F48B6B1282AD977001B669B /* ConversationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F48B6AF282AD977001B669B /* ConversationView.swift */; };
4F48B6B3282AF3A6001B669B /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F48B6B2282AF3A6001B669B /* MessageView.swift */; };
4F48B6B4282AF3A6001B669B /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F48B6B2282AF3A6001B669B /* MessageView.swift */; };
4F48B6B6282B6DB4001B669B /* IntervalUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F48B6B5282B6DB4001B669B /* IntervalUpdater.swift */; };
4F48B6B7282B6DB4001B669B /* IntervalUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F48B6B5282B6DB4001B669B /* IntervalUpdater.swift */; };
4F8A65FC280A93B0007A7431 /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8A65FB280A93B0007A7431 /* Tests_iOS.swift */; };
4F8A65FE280A93B0007A7431 /* Tests_iOSLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8A65FD280A93B0007A7431 /* Tests_iOSLaunchTests.swift */; };
4F8A6608280A93B0007A7431 /* Tests_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8A6607280A93B0007A7431 /* Tests_macOS.swift */; };
@ -56,6 +58,7 @@
4F48B6AC282A3D00001B669B /* ConversationRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationRow.swift; sourceTree = "<group>"; };
4F48B6AF282AD977001B669B /* ConversationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationView.swift; sourceTree = "<group>"; };
4F48B6B2282AF3A6001B669B /* MessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageView.swift; sourceTree = "<group>"; };
4F48B6B5282B6DB4001B669B /* IntervalUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntervalUpdater.swift; sourceTree = "<group>"; };
4F8A65E3280A93AE007A7431 /* KordophoneApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KordophoneApp.swift; sourceTree = "<group>"; };
4F8A65E4280A93AE007A7431 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
4F8A65E5280A93AF007A7431 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -137,6 +140,7 @@
isa = PBXGroup;
children = (
4F8A65E3280A93AE007A7431 /* KordophoneApp.swift */,
4F48B6B5282B6DB4001B669B /* IntervalUpdater.swift */,
4F8A65E4280A93AE007A7431 /* ContentView.swift */,
4F48B6A6282A3559001B669B /* LoginView.swift */,
4F48B6A9282A365B001B669B /* ConversationList.swift */,
@ -352,6 +356,7 @@
files = (
4F48B6AA282A365B001B669B /* ConversationList.swift in Sources */,
4F48B6A7282A3559001B669B /* LoginView.swift in Sources */,
4F48B6B6282B6DB4001B669B /* IntervalUpdater.swift in Sources */,
4F8A660D280A93B0007A7431 /* ContentView.swift in Sources */,
4F48B6AD282A3D00001B669B /* ConversationRow.swift in Sources */,
4F8A660B280A93B0007A7431 /* KordophoneApp.swift in Sources */,
@ -366,6 +371,7 @@
files = (
4F48B6AB282A365B001B669B /* ConversationList.swift in Sources */,
4F48B6A8282A3559001B669B /* LoginView.swift in Sources */,
4F48B6B7282B6DB4001B669B /* IntervalUpdater.swift in Sources */,
4F8A660E280A93B0007A7431 /* ContentView.swift in Sources */,
4F48B6AE282A3D00001B669B /* ConversationRow.swift in Sources */,
4F8A660C280A93B0007A7431 /* KordophoneApp.swift in Sources */,

4
Kordophone/Shared/ConversationList.swift

@ -32,6 +32,7 @@ struct ConversationListWrapper : View {
@State private var conversations = [Conversation]()
@EnvironmentObject private var connection: Connection
@StateObject private var updater = IntervalUpdater(5)
private func refresh() {
Task {
@ -47,5 +48,8 @@ struct ConversationListWrapper : View {
.onChange(of: connection.authenticated) { newValue in
refresh()
}
.onChange(of: updater.seed) { newValue in
refresh()
}
}
}

4
Kordophone/Shared/ConversationView.swift

@ -59,6 +59,7 @@ struct ConversationViewWrapper : View {
var conversation: Conversation
@State private var messages = [Message]()
@EnvironmentObject private var connection: Connection
@StateObject private var updater = IntervalUpdater(5)
private func refresh() {
Task {
@ -79,5 +80,8 @@ struct ConversationViewWrapper : View {
.onAppear {
refresh()
}
.onChange(of: updater.seed) { newValue in
refresh()
}
}
}

12
Kordophone/Shared/IntervalUpdater.swift

@ -0,0 +1,12 @@
import Foundation
class IntervalUpdater : ObservableObject {
@Published var seed = 0
init(_ interval: TimeInterval) {
Timer.scheduledTimer(withTimeInterval: interval,
repeats: true) { [weak self] _ in
self?.seed += 1
}
}
}
Loading…
Cancel
Save