Commit fabf54a9 authored by shigemi miura's avatar shigemi miura

ログイン変更

アイコン変更
parent d63ac4ca
......@@ -51,7 +51,7 @@
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
buildConfiguration = "Canary"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
......
......@@ -29,16 +29,17 @@ class LoginViewParam: ObservableObject{
}
struct LoginView: View {
@ObservedObject var scannerViewModel = ScannerViewModel()
@StateObject var locationViewModel = LocationViewModel()
@Binding var isLogin: Bool
@State var isQrRead: Bool = false
@State var viewMode: LoginViewMode = .SelectType
@State var isProgressView = false
@State var isAlert = false
@State var alertType: AlertType = .loginFailure
@ObservedObject var scannerViewModel = ScannerViewModel()
@State var loginViewParam = LoginViewParam()
@State var timer :Timer?
@StateObject var locationViewModel = LocationViewModel()
let sessionLogin = SessionLogin()
var body: some View {
......@@ -66,9 +67,9 @@ struct LoginView: View {
case .SelectType:
LoginTypeSelectView(isQrRead: $scannerViewModel.isShowing, viewMode: $viewMode)
case .InputIdPassword:
InputIdPassWordView(viewMode: $viewMode, param: $loginViewParam)
InputIdPassWordView(isLogin: $isLogin, viewMode: $viewMode, param: $loginViewParam, isProgressView: $isProgressView, isAlert: $isAlert, alertType: $alertType)
case .InputUserName:
InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode, isProgressView: $isProgressView, isAlert: $isAlert, alertType: $alertType)
InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode)
}
} else {
Text("Login Check").padding()
......@@ -122,15 +123,17 @@ struct LoginView: View {
})
.onAppear() {
LoginCheck()
gpsCheck()
}
.preferredColorScheme(.dark)
}
func LoginCheckQR() -> () {
isProgressView = true
loginViewParam.shipId = Preferences.Id
loginViewParam.password = Preferences.Password
viewMode = .InputUserName
let login = ReqLogin(Id: Preferences.Id, Password: Preferences.Password)
sessionLogin.RequestLogin(login, completion: responseQrLogin)
}
func LoginCheck() -> () {
......@@ -147,20 +150,54 @@ struct LoginView: View {
}
}
func gpsCheck() -> () {
switch locationViewModel.authorizationStatus {
case .notDetermined:
func responseQrLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResLogin.self)
if let res = resjson {
SharingData.my.id = res.id
SharingData.my.shipName = res.shipName
SharingData.my.imo = res.imo
SharingData.my.mmsi = res.mmsi
Preferences.shipId = res.shipId
}
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
viewMode = .InputUserName
// let ecaArea = EcaArea()
// ecaArea.start()
timer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ in
print(debug: "called timer")
let eca = EcaTask()
eca.start()
let message = GetMessage()
message.start()
let route = MonitoringRoute()
route.start()
let ecaList = GetEcaList()
ecaList.start()
let pushHistory = GetPushHistory()
pushHistory.start()
}
timer?.fire()
case .failure(let errorCode):
print(debug: errorCode)
isLogin = false
isAlert = true
alertType = .gpsPermission
case .restricted:
ErrorView(errorText: "位置情報の使用が制限されています。")
case .denied:
ErrorView(errorText: "位置情報を使用できません。")
case .authorizedAlways, .authorizedWhenInUse:
print(debug: "called")
default:
Text("Unexpected status")
alertType = .loginFailure
break
}
isProgressView = false
}
func responseLogin(result: Result<Data, APIError>) {
......@@ -184,7 +221,7 @@ struct LoginView: View {
// let ecaArea = EcaArea()
// ecaArea.start()
timer = Timer.scheduledTimer(withTimeInterval: 60.0 * 10, repeats: true) { _ in
timer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ in
print(debug: "called timer")
let eca = EcaTask()
eca.start()
......
......@@ -9,10 +9,17 @@ import SwiftUI
import Combine
struct InputIdPassWordView: View {
@Binding var isLogin: Bool
@Binding var viewMode : LoginViewMode
@Binding var param : LoginViewParam
@Binding var isProgressView : Bool
@Binding var isAlert : Bool
@Binding var alertType: AlertType
@State private var isUserNmaeEmpty = false
@State private var isIdPassWordEmpty = false
@State var timer :Timer?
let sessionLogin = SessionLogin()
var body: some View {
VStack{
......@@ -65,7 +72,10 @@ struct InputIdPassWordView: View {
if param.shipId.isEmpty || param.password.isEmpty {
isIdPassWordEmpty = true
} else {
viewMode = .InputUserName
isAlert = false
isProgressView = true
let login = ReqLogin(Id: param.shipId, Password: param.password)
sessionLogin.RequestLogin(login, completion: responseLogin)
}
}, label: {
Text("Sign In")
......@@ -77,7 +87,7 @@ struct InputIdPassWordView: View {
})
.alert(isPresented: $isIdPassWordEmpty, content: {
Alert(title: Text("error"),
message: Text("Ship Id or Password is incorrect.")
message: Text("Ship ID or Password is incorrect.")
)
})
.padding(.top, 40)
......@@ -86,8 +96,58 @@ struct InputIdPassWordView: View {
.background(ColorSet.LoginBk02.color)
.padding(.horizontal, 30)
}
func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResLogin.self)
if let res = resjson {
SharingData.my.id = res.id
SharingData.my.shipName = res.shipName
SharingData.my.imo = res.imo
SharingData.my.mmsi = res.mmsi
Preferences.shipId = res.shipId
}
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
viewMode = .InputUserName
// let ecaArea = EcaArea()
// ecaArea.start()
timer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ in
print(debug: "called timer")
let eca = EcaTask()
eca.start()
let message = GetMessage()
message.start()
let route = MonitoringRoute()
route.start()
let ecaList = GetEcaList()
ecaList.start()
let pushHistory = GetPushHistory()
pushHistory.start()
}
timer?.fire()
case .failure(let errorCode):
print(debug: errorCode)
isLogin = false
isAlert = true
alertType = .loginFailure
break
}
isProgressView = false
}
}
#Preview {
InputIdPassWordView(viewMode: .constant(.InputIdPassword), param: .constant(LoginViewParam()))
InputIdPassWordView(isLogin: .constant(false), viewMode: .constant(.InputIdPassword), param: .constant(LoginViewParam()), isProgressView: .constant(false), isAlert: .constant(false), alertType: .constant(.loginFailure))
}
......@@ -12,16 +12,12 @@ struct InputUserNameView: View {
@Binding var isLogin: Bool
@Binding var param: LoginViewParam
@Binding var viewMode : LoginViewMode
@Binding var isProgressView : Bool
@Binding var isAlert : Bool
@Binding var alertType: AlertType
@State private var isEmptyAlert = false
@State var timer :Timer?
var body: some View {
VStack{
VStack(alignment: .leading, spacing: 0) {
Text(SharingData.my.company)
Text(SharingData.my.shipName)
.font(FontStyle.TitleSBold.font)
.padding(.leading, 10)
.foregroundColor(.white)
......@@ -53,12 +49,8 @@ struct InputUserNameView: View {
if param.userName.isEmpty {
isEmptyAlert = true
} else {
print(debug: "signin: id(\(param.shipId)), pass(\(param.password)), name(\(param.userName))")
isAlert = false
isProgressView = true
let login = ReqLogin(Id: param.shipId, Password: param.password)
sessionLogin.RequestLogin(login, completion: responseLogin)
Preferences.UserName = param.userName
isLogin = true
}
}, label: {
Text("Sign In")
......@@ -78,65 +70,9 @@ struct InputUserNameView: View {
.padding(EdgeInsets(top: 21, leading: 20, bottom: 32, trailing: 20))
.background(ColorSet.LoginBk02.color)
.padding(.horizontal, 30)
}
func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResLogin.self)
if let res = resjson {
SharingData.my.id = res.id
SharingData.my.shipName = res.shipName
SharingData.my.imo = res.imo
SharingData.my.mmsi = res.mmsi
Preferences.shipId = res.shipId
let notification = notificationTags()
notification.addTags()
}
Preferences.Id = param.shipId
Preferences.Password = param.password
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
timer = Timer.scheduledTimer(withTimeInterval: 60.0, repeats: true) { _ in
print(debug: "called timer")
let eca = EcaTask()
eca.start()
let message = GetMessage()
message.start()
let route = MonitoringRoute()
route.start()
let ecaList = GetEcaList()
ecaList.start()
let pushHistory = GetPushHistory()
pushHistory.start()
}
timer?.fire()
isProgressView = false
isLogin = true
isAlert = false
case .failure(let errorCode):
print(debug: errorCode)
isProgressView = false
isLogin = false
isAlert = true
alertType = .loginFailure
break
}
}
}
#Preview {
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword), isProgressView: .constant(false), isAlert: .constant(false), alertType: .constant(.loginFailure))
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword))
}
......@@ -85,7 +85,7 @@ struct TaskSwitchingMenuView: View {
switch ecaAlertType {
case .ecaDelete:
return Alert(title: Text("delete"),
message: Text("eca delete"),
message: Text("Do you delete " + eca.name),
primaryButton: .default(Text("cancel")),
secondaryButton: .cancel(Text("delete"), action: {
if let ecaArea = edittingEcaArea {
......@@ -100,7 +100,7 @@ struct TaskSwitchingMenuView: View {
}))
case .ecaRunningStop:
return Alert(title: Text("stop"),
message: Text("eca running stop"),
message: Text("Do you want to stop " + eca.name),
primaryButton: .default(Text("cancel")),
secondaryButton: .cancel(Text("stop"), action: {
if let ecaArea = edittingEcaArea {
......
......@@ -50,8 +50,10 @@ enum MenuPath: String, Hashable{
}
struct MenuView: View {
@EnvironmentObject private var sceneDelegate: SceneDelegate
@State var path: [MenuPath] = []
@Binding var isSignout: Bool
@Binding var isLogin: Bool
var body: some View {
NavigationStack(path: $path){
......@@ -60,10 +62,10 @@ struct MenuView: View {
HStack {
VStack(alignment: .leading, spacing: 10){
Text("Group")
Text(SharingData.my.shipName)
.font(FontStyle.TitleL.font)
.foregroundColor(ColorSet.Body.color)
Text(SharingData.my.company)
Text(Preferences.UserName)
.font(FontStyle.EmphasisText.font)
.foregroundColor(ColorSet.BodyDescriptiion.color)
}
......@@ -125,23 +127,23 @@ struct MenuView: View {
}
.navigationBarHidden(true)
.background(ColorSet.BackgroundPrimary.color)
}
}
.alert(isPresented: $isSignout) {
return Alert(title: Text("Sign Out"),
message: Text("Are you sure?"),
primaryButton: .default(Text("Yes"), action: {
primaryButton: .default(Text("No")), secondaryButton: .cancel(Text("Yes"), action: {
Preferences.Id = ""
Preferences.Password = ""
Preferences.UserName = ""
}), secondaryButton: .cancel(Text("No")))
isLogin = false
}))
}
}
}
}
#Preview {
MenuView(isSignout: .constant(false))
MenuView(isSignout: .constant(false), isLogin: .constant(false))
}
......@@ -18,10 +18,12 @@ struct MenuContentView: View {
Spacer()
if content.title != "Sign Out" {
Image("ink_01")
.resizable()
.frame(width: 22, height: 22)
}
}
.padding(.vertical, 17)
.padding(.horizontal, 30)
......
......@@ -100,8 +100,8 @@ class AppDelegate: NSObject, UIApplicationDelegate ,MSNotificationHubDelegate, M
let bamTag = "bam-" + shipId
let taskAlertTag = "taskalert-" + shipId
let sailassistTag = "sailassist-" + shipId
// MSNotificationHub.addTags([routeTag, bamTag, taskAlertTag, sailassistTag])
MSNotificationHub.addTags([routeTag])
MSNotificationHub.addTags([routeTag, bamTag, taskAlertTag, sailassistTag])
// MSNotificationHub.addTags([routeTag])
}
}
......
......@@ -46,7 +46,7 @@ struct MainTabView: View {
NotificationView()
.tag(Tab.alert)
MenuView(isSignout: $isSignout)
MenuView(isSignout: $isSignout, isLogin: $isLogin)
.tag(Tab.menu)
}
.hideNativeTabBar()
......
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