Add animation and wait for callback to confirm download
This commit is contained in:
@@ -44,7 +44,7 @@ class ChatRoomExampleContext : ObservableObject
|
||||
@Published var chatroomState = ChatroomExampleState.Unstarted
|
||||
@Published var textToSend: String = "msg to send"
|
||||
@Published var sReceivedMessages : String = ""
|
||||
|
||||
@Published var isDownloading : Bool = false
|
||||
var fileFolderUrl : URL?
|
||||
var fileUrl : URL?
|
||||
|
||||
@@ -52,7 +52,8 @@ class ChatRoomExampleContext : ObservableObject
|
||||
{
|
||||
mChatRoomDelegate.tutorialContext = self
|
||||
mLinphoneCoreDelegate.tutorialContext = self
|
||||
|
||||
mChatMessageDelegate.tutorialContext = self
|
||||
|
||||
// Initialize Linphone Core
|
||||
try? mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil)
|
||||
|
||||
@@ -177,7 +178,6 @@ class ChatRoomExampleContext : ObservableObject
|
||||
content.subtype = "plain"
|
||||
|
||||
mChatMessage = try mChatRoom!.createFileTransferMessage(initialContent: content)
|
||||
mChatMessage!.addDelegate(delegate: self.mChatMessageDelegate)
|
||||
mChatMessage!.send()
|
||||
}catch let error as NSError {
|
||||
print("Unable to create directory",error)
|
||||
@@ -192,6 +192,7 @@ class ChatRoomExampleContext : ObservableObject
|
||||
if (!contentName.isEmpty) {
|
||||
content.filePath = fileFolderUrl!.appendingPathComponent(contentName).path
|
||||
print("Start downloading \(content.name) into \(content.filePath)")
|
||||
isDownloading = true
|
||||
if (!message.downloadContent(content: content)) {
|
||||
print ("Download of \(contentName) failed")
|
||||
}
|
||||
@@ -236,7 +237,6 @@ class LinphoneCoreDelegate: CoreDelegate {
|
||||
}
|
||||
|
||||
class LinphoneChatRoomStateTracker: ChatRoomDelegate {
|
||||
|
||||
var tutorialContext : ChatRoomExampleContext!
|
||||
|
||||
func onConferenceJoined(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
@@ -246,11 +246,12 @@ class LinphoneChatRoomStateTracker: ChatRoomDelegate {
|
||||
}
|
||||
|
||||
class LinphoneChatMessageTracker: ChatMessageDelegate {
|
||||
var tutorialContext : ChatRoomExampleContext!
|
||||
|
||||
func onMsgStateChanged(message msg: ChatMessage, state: ChatMessage.State) {
|
||||
print("MessageTrace - msg state changed: \(state)\n")
|
||||
if (state == ChatMessage.State.FileTransferDone && tutorialContext.isDownloading == true) {
|
||||
tutorialContext.isDownloading = false
|
||||
}
|
||||
}
|
||||
|
||||
func onFileTransferRecv(message: ChatMessage, content: Content, buffer: Buffer) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,18 @@ func getStateAsString(chatroomState : ChatroomExampleState) -> String
|
||||
}
|
||||
}
|
||||
|
||||
struct ActivityIndicator: UIViewRepresentable {
|
||||
func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView
|
||||
{
|
||||
return UIActivityIndicatorView(style: .medium)
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>)
|
||||
{
|
||||
uiView.startAnimating()
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@ObservedObject var tutorialContext : ChatRoomExampleContext
|
||||
@@ -80,6 +92,9 @@ struct ContentView: View {
|
||||
Text(getStateAsString(chatroomState: tutorialContext.chatroomState))
|
||||
.font(.footnote)
|
||||
.foregroundColor((tutorialContext.chatroomState == ChatroomExampleState.Started) ? Color.green : Color .black)
|
||||
if (tutorialContext.chatroomState == ChatroomExampleState.Starting) {
|
||||
ActivityIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(action: {
|
||||
@@ -127,7 +142,6 @@ struct ContentView: View {
|
||||
.frame(width: 120.0, height: 50.0)
|
||||
.background(Color.gray)
|
||||
}.disabled(tutorialContext.chatroomState != ChatroomExampleState.Started)
|
||||
|
||||
Button(action: tutorialContext.downloadLastFileMessage)
|
||||
{
|
||||
Text("Download last files \n received")
|
||||
@@ -136,6 +150,9 @@ struct ContentView: View {
|
||||
.frame(width: 150.0, height: 50.0)
|
||||
.background(Color.gray)
|
||||
}.disabled(tutorialContext.mLastFileMessageReceived == nil)
|
||||
if (tutorialContext.isDownloading) {
|
||||
ActivityIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
|
||||
Reference in New Issue
Block a user