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