diff --git a/AgileWorks/AgileWorks.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme b/AgileWorks/AgileWorks.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme index f4fd053830708006e397ba949dc01dd3ecd295ba..dc3e129052c54d4d1125541627d7f92c76e52d8e 100644 --- a/AgileWorks/AgileWorks.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme +++ b/AgileWorks/AgileWorks.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme @@ -86,7 +86,7 @@ + isEnabled = "YES"> Int?{ + for (index, item) in entry.approvalItems.enumerated() { + if item.code == "REQUEST_APPROVAL" { + return index + } + } + return nil + } + + var body: some View { + //API取得成功 + if entry.message == nil { + if let num = findApproval() { //「承認依頼」項目あり + ApprovalItemView(approvalItem: entry.approvalItems[num], message: entry.message) + }else { //「承認依頼」項目なし + ApprovalItemView(approvalItem: ApprovalItem(code: "", name: "", count: 0), message: "-") + } + }else { + //APIサーバーエラー + if entry.message == "-" { + ApprovalItemView(approvalItem: ApprovalItem(code: "", name: "", count: 0), message: "-") + }else {//ログイン・コネクションエラー + FailureWidgetView(entry: entry) + } + } + } +} + //書類状況を表示するための各BOXビュー -struct ApplovalsBoxView : View { +struct StatusBoxView : View { var entry: Provider.Entry //書類状態の種類をカウント @@ -166,26 +199,48 @@ struct FailureWidgetView : View { } } -@main -struct WidgetExtension: Widget { - let kind: String = "WidgetExtension" +//状況確認ウィジェット +struct StatusCheckWidget: Widget { + let kind: String = "StatusCheck" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in - ApprovalsWidgetView(entry: entry) + StatusCheckWidgetView(entry: entry) } - .configurationDisplayName("My Widget") - .description("This is an example widget.") + .configurationDisplayName(localizadString(key: "StatusCheckWidgetName", comment: "")) + .description(localizadString(key: "StatusCheckWidgetDescription", comment: "")) .supportedFamilies([.systemLarge]) } } +//承認待ちウィジェット +struct ApprovalWidget: Widget { + let kind: String = "Approval" + + var body: some WidgetConfiguration { + StaticConfiguration(kind: kind, provider: Provider()) { entry in + ApprovalWidgetView(entry: entry) + } + .configurationDisplayName(localizadString(key: "ApprovalWidgetName", comment: "")) + .description(localizadString(key: "ApprovalWidgetDescription", comment: "")) + .supportedFamilies([.systemSmall]) + } +} +@main +struct WidgetExtension: WidgetBundle { + @WidgetBundleBuilder + var body: some Widget { + StatusCheckWidget() + ApprovalWidget() + } +} + struct WidgetExtension_Previews: PreviewProvider { static var previews: some View { - //ApprovalsWidgetView(entry: SimpleEntry(date: Date(), approvalItems: previewItems(), message: nil)) - // .previewContext(WidgetPreviewContext(family: .systemLarge)) - ApprovalsWidgetView(entry: SimpleEntry(date: Date(), approvalItems: previewItems(), message: nil)) + StatusCheckWidgetView(entry: SimpleEntry(date: Date(), approvalItems: previewItems(), message: nil)) .previewContext(WidgetPreviewContext(family: .systemLarge)) + ApprovalWidgetView(entry: SimpleEntry(date: Date(), approvalItems: previewItems(), message: nil)) + .previewContext(WidgetPreviewContext(family: .systemSmall)) } } @@ -236,3 +291,4 @@ func errorMessageNSError(error: Error) -> String? { return nil } } +