Commit 07a61c4c authored by sugita mamoru's avatar sugita mamoru

チャットをSharingDataを参照して表示するようにした

parent 4780c488
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "swStartBack@2x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
import SwiftUI import SwiftUI
struct ChatView: View { struct ChatView: View {
@State var isEmargency: Bool = false @ObservedObject var message = SharingData.message
@State var isShowMember: Bool = false @State var isShowMember: Bool = false
var body: some View { var body: some View {
ZStack { ZStack {
if isEmargency{ if message.mode == 1{
LinearGradient(gradient: Gradient(colors: [.chatEmargencyColor1, .chatEmargencyColor2]), startPoint: .top, endPoint: .bottom) LinearGradient(gradient: Gradient(colors: [.chatEmargencyColor1, .chatEmargencyColor2]), startPoint: .top, endPoint: .bottom)
.ignoresSafeArea() .ignoresSafeArea()
} }
...@@ -23,15 +23,28 @@ struct ChatView: View { ...@@ -23,15 +23,28 @@ struct ChatView: View {
ScrollView(.vertical) { ScrollView(.vertical) {
Spacer() Spacer()
.frame(height: 20) .frame(height: 20)
OtherChatContentView()
MyChatContentView() ForEach(message.messages, id: \.messageId) { msg in
if msg.fromId != String(SharingData.my.id){
//自分のメッセージ
MyChatContentView(message: msg)
.padding(.bottom, 24)
}else{
//他人のメッセージ
OtherChatContentView(message: msg)
.padding(.bottom, 24)
}
}
} }
HStack { HStack {
Spacer() Spacer()
VStack{ VStack{
Button{ Button{
isEmargency.toggle() if message.mode == 0{
message.mode = 1
}else{
message.mode = 0
}
}label: { }label: {
Image(systemName: "exclamationmark.triangle.fill") Image(systemName: "exclamationmark.triangle.fill")
.foregroundColor(.white) .foregroundColor(.white)
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
import SwiftUI import SwiftUI
struct MyChatContentView: View { struct MyChatContentView: View {
var message : ChatMessage
var body: some View { var body: some View {
HStack { HStack {
Spacer() Spacer()
VStack(alignment: .trailing, spacing: 6) { VStack(alignment: .trailing, spacing: 6) {
Text("テキストメッセージテキストメッセージテキストメッセージテキストメッセージテキストメッセージテキストメッセージ") Text(message.message)
.font(FontStyle.DefaultText.font) .font(FontStyle.DefaultText.font)
.foregroundColor(ColorSet.BodyChat.color) .foregroundColor(ColorSet.BodyChat.color)
.padding(15) .padding(15)
...@@ -20,7 +21,7 @@ struct MyChatContentView: View { ...@@ -20,7 +21,7 @@ struct MyChatContentView: View {
.cornerRadius(10, corners: [.tl, .tr, .bl]) .cornerRadius(10, corners: [.tl, .tr, .bl])
HStack(spacing: 0){ HStack(spacing: 0){
Text("yyyy/MM/dd hh:mm") Text(DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd hh:mm", errFormat: ""))
.padding(.trailing, 8) .padding(.trailing, 8)
Image(systemName: "eye.fill") Image(systemName: "eye.fill")
...@@ -29,7 +30,7 @@ struct MyChatContentView: View { ...@@ -29,7 +30,7 @@ struct MyChatContentView: View {
.frame(width: 17, height: 17) .frame(width: 17, height: 17)
.padding(.trailing, 4) .padding(.trailing, 4)
Text("1") Text(String(message.viewer.count))
} }
.font(FontStyle.DateText.font) .font(FontStyle.DateText.font)
.foregroundColor(ColorSet.BodyDescriptiion.color) .foregroundColor(ColorSet.BodyDescriptiion.color)
...@@ -41,5 +42,25 @@ struct MyChatContentView: View { ...@@ -41,5 +42,25 @@ struct MyChatContentView: View {
} }
#Preview { #Preview {
MyChatContentView() MyChatContentView(message: ChatMessage(
shipId: 10000003,
messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
))
} }
...@@ -8,14 +8,15 @@ ...@@ -8,14 +8,15 @@
import SwiftUI import SwiftUI
struct OtherChatContentView: View { struct OtherChatContentView: View {
var message : ChatMessage
var body: some View { var body: some View {
HStack { HStack {
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {
Text("Taro") Text(message.from)
.font(FontStyle.EmphasisText.font) .font(FontStyle.EmphasisText.font)
.foregroundColor(ColorSet.Body.color) .foregroundColor(ColorSet.Body.color)
VStack(alignment: .leading, spacing: 10) { VStack(alignment: .leading, spacing: 10) {
Text("テキストメッセージテキストメッセージテキストメッセージテキストメッセージテキストメッセージテキストメッセージ") Text(message.message)
.font(FontStyle.DefaultText.font) .font(FontStyle.DefaultText.font)
.foregroundColor(ColorSet.BodyChat.color) .foregroundColor(ColorSet.BodyChat.color)
.padding(15) .padding(15)
...@@ -23,7 +24,7 @@ struct OtherChatContentView: View { ...@@ -23,7 +24,7 @@ struct OtherChatContentView: View {
.cornerRadius(10, corners: [.tl, .tr, .br]) .cornerRadius(10, corners: [.tl, .tr, .br])
HStack(alignment: .top){ HStack(alignment: .top){
Text("yyyy/MM/dd hh:mm") Text(DateTextLib.ISO86012FormatText(message.time, format: "yyyy/MM/dd hh:mm", errFormat: ""))
.font(FontStyle.DateText.font) .font(FontStyle.DateText.font)
.foregroundColor(ColorSet.ChatDate.color) .foregroundColor(ColorSet.ChatDate.color)
} }
...@@ -37,5 +38,25 @@ struct OtherChatContentView: View { ...@@ -37,5 +38,25 @@ struct OtherChatContentView: View {
} }
#Preview { #Preview {
OtherChatContentView() OtherChatContentView(message: ChatMessage(
shipId: 10000003,
messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
))
} }
...@@ -9,10 +9,10 @@ import Foundation ...@@ -9,10 +9,10 @@ import Foundation
struct ResGetMessages: Codable { struct ResGetMessages: Codable {
var mode: Int // 0:通常 , 1:Warning中 var mode: Int // 0:通常 , 1:Warning中
var messages: [message]? var messages: [ChatMessage]?
} }
struct message: Codable { struct ChatMessage: Codable {
var shipId: UInt var shipId: UInt
var messageId: String //各メッセージ固有ID var messageId: String //各メッセージ固有ID
var type: Int //0:テキスト , 1:スタンプ , 2:画像 var type: Int //0:テキスト , 1:スタンプ , 2:画像
...@@ -22,11 +22,11 @@ struct message: Codable { ...@@ -22,11 +22,11 @@ struct message: Codable {
var fromId: String //ユーザーID var fromId: String //ユーザーID
var message: String //テキスト時:テキスト , 画像時:サムネイルのUri var message: String //テキスト時:テキスト , 画像時:サムネイルのUri
var stampId: Int //スタンプ番号 0:Fire~ var stampId: Int //スタンプ番号 0:Fire~
var viewer: [view] //閲覧者情報 var viewer: [Viewer] //閲覧者情報
} }
struct view: Codable { struct Viewer: Codable {
var time: String //確認日時 var time: String //確認日時
var location: Int //1:Shore , 2:Ship var location: Int //1:Shore , 2:Ship
var id: Int //ユーザーID var id: String //ユーザーID
} }
...@@ -68,12 +68,14 @@ class DateTextLib: NSObject { ...@@ -68,12 +68,14 @@ class DateTextLib: NSObject {
// サーバとの通信に使う // サーバとの通信に使う
static func Date2ISO8601Text(_ date: Date ) -> String { static func Date2ISO8601Text(_ date: Date ) -> String {
let formatter = ISO8601DateFormatter() let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
let dateString = formatter.string(from: date) let dateString = formatter.string(from: date)
return dateString return dateString
} }
/// ISO8601文字列をDate型に変換 /// ISO8601文字列をDate型に変換
static func ISO8601Text2Date(_ dateString: String? ) -> Date? { static func ISO8601Text2Date(_ dateString: String? ) -> Date? {
let formatter = ISO8601DateFormatter() let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
let setDate = formatter.date(from: dateString ?? "") let setDate = formatter.date(from: dateString ?? "")
return setDate return setDate
} }
...@@ -81,6 +83,7 @@ class DateTextLib: NSObject { ...@@ -81,6 +83,7 @@ class DateTextLib: NSObject {
/// unixTime(整数値,秒)を最終的にISO8601文字列にする /// unixTime(整数値,秒)を最終的にISO8601文字列にする
static func UnixTime2ISO8601Text(_ unixTime: Int64 ) -> String { static func UnixTime2ISO8601Text(_ unixTime: Int64 ) -> String {
let formatter = ISO8601DateFormatter() let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
let timeInterval = TimeInterval(integerLiteral: unixTime ) let timeInterval = TimeInterval(integerLiteral: unixTime )
let unixDate = Date(timeIntervalSince1970: timeInterval) let unixDate = Date(timeIntervalSince1970: timeInterval)
let unixStr = formatter.string(from: unixDate ) let unixStr = formatter.string(from: unixDate )
...@@ -90,6 +93,7 @@ class DateTextLib: NSObject { ...@@ -90,6 +93,7 @@ class DateTextLib: NSObject {
/// ISO8601文字列をunixint(整数値,秒)に変換 /// ISO8601文字列をunixint(整数値,秒)に変換
static func ISO8601Text2UnixTime(_ unixStr: String? ) -> Int64 { static func ISO8601Text2UnixTime(_ unixStr: String? ) -> Int64 {
let formatter = ISO8601DateFormatter() let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
var unixTime : Int64 = 0 var unixTime : Int64 = 0
if let setDate = formatter.date(from: unixStr ?? "") { if let setDate = formatter.date(from: unixStr ?? "") {
let unixinterval :Double = setDate.timeIntervalSince1970 let unixinterval :Double = setDate.timeIntervalSince1970
......
...@@ -12,6 +12,7 @@ import UIKit ...@@ -12,6 +12,7 @@ import UIKit
struct MapRepresentable: UIViewControllerRepresentable{ struct MapRepresentable: UIViewControllerRepresentable{
@ObservedObject var ecaData = SharingData.eca @ObservedObject var ecaData = SharingData.eca
@ObservedObject var my = SharingData.my
@State var mapVC = MapViewController() @State var mapVC = MapViewController()
func makeUIViewController(context: Context) -> some UIViewController { func makeUIViewController(context: Context) -> some UIViewController {
...@@ -24,8 +25,8 @@ struct MapRepresentable: UIViewControllerRepresentable{ ...@@ -24,8 +25,8 @@ struct MapRepresentable: UIViewControllerRepresentable{
mapVC.updateEcaLine(line: ecaArea.points) mapVC.updateEcaLine(line: ecaArea.points)
} }
if let mylocation = SharingData.my.location { if let mylocation = my.location {
mapVC.updateOwnShip(location: mylocation, bearing: SharingData.my.heading) mapVC.updateOwnShip(location: mylocation, bearing: my.heading)
if let ecaArea = ecaArea{ if let ecaArea = ecaArea{
mapVC.updateEcaSwitchingLine(center: mylocation, notice: ecaArea.swNotice, start: ecaArea.swStart, finish: ecaArea.swFinish) mapVC.updateEcaSwitchingLine(center: mylocation, notice: ecaArea.swNotice, start: ecaArea.swStart, finish: ecaArea.swFinish)
...@@ -64,7 +65,7 @@ class MapViewController : UIViewController{ ...@@ -64,7 +65,7 @@ class MapViewController : UIViewController{
func addImage(){ func addImage(){
do{ do{
if let image = UIImage(named: "account"){ if let image = UIImage(named: "ownShip"){
try mapView.mapboxMap.style.addImage(image, id: IconImage.OwnShip.rawValue) try mapView.mapboxMap.style.addImage(image, id: IconImage.OwnShip.rawValue)
} }
if let image = UIImage(named: "swNoticeBack"){ if let image = UIImage(named: "swNoticeBack"){
...@@ -84,9 +85,7 @@ class MapViewController : UIViewController{ ...@@ -84,9 +85,7 @@ class MapViewController : UIViewController{
addImage() addImage()
let point = Point(LocationCoordinate2D(latitude: 0, longitude: 0)) let point = Point(LocationCoordinate2D(latitude: 0, longitude: 0))
var feature = Feature(geometry: point) ownShipSymbol.source.data = .feature(Feature(geometry: point))
// feature.properties = [PropertyKey.IconImage.rawValue: .string(IconImage.OwnShip.rawValue)]
ownShipSymbol.source.data = .feature(feature)
var ownShipSymbolLayer = SymbolLayer(id: ownShipSymbol.layerId) var ownShipSymbolLayer = SymbolLayer(id: ownShipSymbol.layerId)
ownShipSymbolLayer.source = ownShipSymbol.sourceId ownShipSymbolLayer.source = ownShipSymbol.sourceId
ownShipSymbolLayer.iconImage = .expression(Exp(.get) { ownShipSymbolLayer.iconImage = .expression(Exp(.get) {
......
...@@ -46,7 +46,7 @@ struct EcaSettingView: View { ...@@ -46,7 +46,7 @@ struct EcaSettingView: View {
fileprivate struct SliderView: View { fileprivate struct SliderView: View {
init(param: Binding<Float>, title: String, min: Float = 1, max: Float = 10) { init(param: Binding<Float>, title: String, min: Float = 1, max: Float = 10) {
var thumb = UIImage(systemName: "circle.fill") let thumb = UIImage(systemName: "circle.fill")
UISlider.appearance().setThumbImage(thumb, for: .normal) UISlider.appearance().setThumbImage(thumb, for: .normal)
UISlider.appearance().maximumTrackTintColor = UIColor(ColorSet.Slidebar.color) UISlider.appearance().maximumTrackTintColor = UIColor(ColorSet.Slidebar.color)
self._param = param self._param = param
......
...@@ -11,7 +11,6 @@ class PDFDownloadManager{ ...@@ -11,7 +11,6 @@ class PDFDownloadManager{
static let main = PDFDownloadManager() static let main = PDFDownloadManager()
func downloadFile(urlString: String, fileName: String) -> URL?{ func downloadFile(urlString: String, fileName: String) -> URL?{
let semaphore = DispatchSemaphore(value: 0)
guard let url = URL(string: urlString) else { return nil } guard let url = URL(string: urlString) else { return nil }
guard let resDocPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else { return nil } guard let resDocPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else { return nil }
var filePath: URL? = resDocPath.appendingPathComponent(fileName) var filePath: URL? = resDocPath.appendingPathComponent(fileName)
......
...@@ -11,7 +11,7 @@ class SharingData{ ...@@ -11,7 +11,7 @@ class SharingData{
static var my = My() static var my = My()
class My: ObservableObject { class My: ObservableObject {
@Published var location: CLLocationCoordinate2D? = nil @Published var location: CLLocationCoordinate2D? = .init(latitude: 0, longitude: 0)
@Published var gps: CLLocationCoordinate2D? = nil @Published var gps: CLLocationCoordinate2D? = nil
@Published var server: CLLocationCoordinate2D? = nil @Published var server: CLLocationCoordinate2D? = nil
@Published var speed: Double = 0.0 @Published var speed: Double = 0.0
...@@ -24,6 +24,10 @@ class SharingData{ ...@@ -24,6 +24,10 @@ class SharingData{
@Published var shipName: String = "" @Published var shipName: String = ""
@Published var imo: Int = 0 @Published var imo: Int = 0
@Published var mmsi: Int = 0 @Published var mmsi: Int = 0
func setLocation(_ location: CLLocationCoordinate2D?){
self.location = location
}
func reset() { func reset() {
location = nil location = nil
...@@ -44,7 +48,53 @@ class SharingData{ ...@@ -44,7 +48,53 @@ class SharingData{
static var message = Message() static var message = Message()
class Message: ObservableObject { class Message: ObservableObject {
@Published var mode: Int = 0 // 0:通常 , 1:Warning中 @Published var mode: Int = 0 // 0:通常 , 1:Warning中
@Published var messages: [message] = [] @Published var messages: [ChatMessage] = [
ChatMessage(
shipId: 10000003,
messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
),
ChatMessage(
shipId: 10000001,
messageId: "92c2dfb5-f5ed-4943-98a3-a848d7f9a962",
type: 0,
time: "2023-10-06T01:51:01.872Z",
location: 1,
from: "はだだ",
fromId: "487420489",
message: "999",
stampId: 0,
viewer: [
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 1,
id: ""),
Viewer(
time: "2023-10-06T01:51:12.973Z",
location: 2,
id: "")
]
),
]
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment