From 5baef90c27593ec8408cd9d411b61b5ee6577cbf Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Mon, 30 Sep 2024 16:04:19 -0700 Subject: [PATCH 1/7] Refactor selection UI --- .../Offline/PreplannedListItemView.swift | 10 ++++++++-- .../Offline/PreplannedMapModel.swift | 14 +++++++++++++- .../PreplannedMapModelStatusTests.swift | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index 451883cc8..f38043260 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -64,7 +64,7 @@ struct PreplannedListItemView: View { deleteButton } .onTapGesture { - if model.status.isDownloaded { + if model.status.isDownloaded || model.status.isOpened { metadataViewIsPresented = true } } @@ -75,6 +75,9 @@ struct PreplannedListItemView: View { } .task { await model.load() + if isSelected { + model.openPreplannedMapArea() + } } .onAppear { downloadState = .init(model.status) @@ -120,6 +123,7 @@ struct PreplannedListItemView: View { Task { if let map = await model.map { selectedMap = map + model.openPreplannedMapArea() } } } label: { @@ -175,7 +179,7 @@ struct PreplannedListItemView: View { Image(systemName: "clock.badge.xmark") Text("Packaging") case .packaged: - Text("Package ready for download") + Text("Ready to download") case .packageFailure: Image(systemName: "exclamationmark.circle") Text("Packaging failed") @@ -186,6 +190,8 @@ struct PreplannedListItemView: View { case .downloadFailure: Image(systemName: "exclamationmark.circle") Text("Download failed") + case .opened: + Text("Currently open") } } .font(.caption2) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift index 13cf9481d..daea2a7dc 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift @@ -181,6 +181,11 @@ class PreplannedMapModel: ObservableObject, Identifiable { Task { await load() } } + /// Sets the status to opened. + func openPreplannedMapArea() { + status = .opened + } + /// Sets the job property of this instance, starts the job, observes it, and /// when it's done, updates the status, removes the job from the job manager, /// and fires a user notification. @@ -223,6 +228,8 @@ extension PreplannedMapModel { case downloadFailure(Error) /// Downloaded mobile map package failed to load. case mmpkLoadFailure(Error) + /// Preplanned map area is currently open. + case opened /// A Boolean value indicating whether the model is in a state /// where it needs to be loaded or reloaded. @@ -239,7 +246,7 @@ extension PreplannedMapModel { var allowsDownload: Bool { switch self { case .notLoaded, .loading, .loadFailure, .packaging, .packageFailure, - .downloading, .downloaded, .mmpkLoadFailure: + .downloading, .downloaded, .mmpkLoadFailure, .opened: false case .packaged, .downloadFailure: true @@ -260,6 +267,11 @@ extension PreplannedMapModel { var isDownloaded: Bool { if case .downloaded = self { true } else { false } } + + /// A Boolean value indicating whether the preplanned map area is opened. + var isOpened: Bool { + if case .opened = self { true } else { false } + } } } diff --git a/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift b/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift index 413111cc4..17a50b01a 100644 --- a/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift +++ b/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift @@ -30,6 +30,7 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloadFailure(CancellationError()).needsToBeLoaded) XCTAssertTrue(Status.loadFailure(CancellationError()).needsToBeLoaded) XCTAssertTrue(Status.packageFailure.needsToBeLoaded) + XCTAssertTrue(Status.opened.needsToBeLoaded) } func testAllowsDownload() { @@ -43,6 +44,7 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertFalse(Status.downloaded.allowsDownload) XCTAssertTrue(Status.downloadFailure(CancellationError()).allowsDownload) XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).allowsDownload) + XCTAssertFalse(Status.opened.allowsDownload) } func testIsDownloaded() { @@ -56,6 +58,21 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloaded.isDownloaded) XCTAssertFalse(Status.downloadFailure(CancellationError()).isDownloaded) XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).isDownloaded) + XCTAssertFalse(Status.opened.isDownloaded) + } + + func testIsOpened() { + XCTAssertFalse(Status.notLoaded.isOpened) + XCTAssertFalse(Status.loading.isOpened) + XCTAssertFalse(Status.loadFailure(CancellationError()).isOpened) + XCTAssertFalse(Status.packaging.isOpened) + XCTAssertFalse(Status.packaged.isOpened) + XCTAssertFalse(Status.packageFailure.isOpened) + XCTAssertFalse(Status.downloading.isOpened) + XCTAssertFalse(Status.downloaded.isOpened) + XCTAssertFalse(Status.downloadFailure(CancellationError()).isOpened) + XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).isOpened) + XCTAssertTrue(Status.opened.isOpened) } func testAllowsRemoval() { @@ -69,5 +86,6 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloaded.allowsRemoval) XCTAssertTrue(Status.downloadFailure(CancellationError()).allowsRemoval) XCTAssertTrue(Status.mmpkLoadFailure(CancellationError()).allowsRemoval) + XCTAssertFalse(Status.opened.allowsRemoval) } } From 873a23c1cbe33442d7f4c90025fc3101441715c6 Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Mon, 30 Sep 2024 16:07:29 -0700 Subject: [PATCH 2/7] Add download state --- .../Components/Offline/PreplannedListItemView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index f38043260..b97a9411d 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -29,7 +29,7 @@ struct PreplannedListItemView: View { /// The download state of the preplanned map model. fileprivate enum DownloadState { - case notDownloaded, downloading, downloaded + case notDownloaded, downloading, downloaded, opened } /// The current download state of the preplanned map model. @@ -118,7 +118,7 @@ struct PreplannedListItemView: View { @ViewBuilder private var downloadButton: some View { switch downloadState { - case .downloaded: + case .downloaded, .opened: Button { Task { if let map = await model.map { From a2143b3103181f16111fcc3af7e0bec7205d14b5 Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Mon, 30 Sep 2024 16:08:37 -0700 Subject: [PATCH 3/7] Update PreplannedListItemView.swift --- .../Components/Offline/PreplannedListItemView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index b97a9411d..4e92e8f5e 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -206,6 +206,7 @@ private extension PreplannedListItemView.DownloadState { self = switch state { case .downloaded: .downloaded case .downloading: .downloading + case .opened: .opened default: .notDownloaded } } From 080cd7c0c9ba8118a3ad2124fc8e038c3ce911ad Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Tue, 1 Oct 2024 09:21:43 -0700 Subject: [PATCH 4/7] Revert "Update PreplannedListItemView.swift" This reverts commit a2143b3103181f16111fcc3af7e0bec7205d14b5. --- .../Components/Offline/PreplannedListItemView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index 4e92e8f5e..b97a9411d 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -206,7 +206,6 @@ private extension PreplannedListItemView.DownloadState { self = switch state { case .downloaded: .downloaded case .downloading: .downloading - case .opened: .opened default: .notDownloaded } } From 2fcaf604f0628c98eaed2e0bf92fc505215dbd82 Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Tue, 1 Oct 2024 09:21:49 -0700 Subject: [PATCH 5/7] Revert "Add download state" This reverts commit 873a23c1cbe33442d7f4c90025fc3101441715c6. --- .../Components/Offline/PreplannedListItemView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index b97a9411d..f38043260 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -29,7 +29,7 @@ struct PreplannedListItemView: View { /// The download state of the preplanned map model. fileprivate enum DownloadState { - case notDownloaded, downloading, downloaded, opened + case notDownloaded, downloading, downloaded } /// The current download state of the preplanned map model. @@ -118,7 +118,7 @@ struct PreplannedListItemView: View { @ViewBuilder private var downloadButton: some View { switch downloadState { - case .downloaded, .opened: + case .downloaded: Button { Task { if let map = await model.map { From eaa9a4f2377fa7a94b20ab4a7af68f2a35ddb200 Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Tue, 1 Oct 2024 09:21:57 -0700 Subject: [PATCH 6/7] Revert "Refactor selection UI" This reverts commit 5baef90c27593ec8408cd9d411b61b5ee6577cbf. --- .../Offline/PreplannedListItemView.swift | 10 ++-------- .../Offline/PreplannedMapModel.swift | 14 +------------- .../PreplannedMapModelStatusTests.swift | 18 ------------------ 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index f38043260..451883cc8 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -64,7 +64,7 @@ struct PreplannedListItemView: View { deleteButton } .onTapGesture { - if model.status.isDownloaded || model.status.isOpened { + if model.status.isDownloaded { metadataViewIsPresented = true } } @@ -75,9 +75,6 @@ struct PreplannedListItemView: View { } .task { await model.load() - if isSelected { - model.openPreplannedMapArea() - } } .onAppear { downloadState = .init(model.status) @@ -123,7 +120,6 @@ struct PreplannedListItemView: View { Task { if let map = await model.map { selectedMap = map - model.openPreplannedMapArea() } } } label: { @@ -179,7 +175,7 @@ struct PreplannedListItemView: View { Image(systemName: "clock.badge.xmark") Text("Packaging") case .packaged: - Text("Ready to download") + Text("Package ready for download") case .packageFailure: Image(systemName: "exclamationmark.circle") Text("Packaging failed") @@ -190,8 +186,6 @@ struct PreplannedListItemView: View { case .downloadFailure: Image(systemName: "exclamationmark.circle") Text("Download failed") - case .opened: - Text("Currently open") } } .font(.caption2) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift index daea2a7dc..13cf9481d 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedMapModel.swift @@ -181,11 +181,6 @@ class PreplannedMapModel: ObservableObject, Identifiable { Task { await load() } } - /// Sets the status to opened. - func openPreplannedMapArea() { - status = .opened - } - /// Sets the job property of this instance, starts the job, observes it, and /// when it's done, updates the status, removes the job from the job manager, /// and fires a user notification. @@ -228,8 +223,6 @@ extension PreplannedMapModel { case downloadFailure(Error) /// Downloaded mobile map package failed to load. case mmpkLoadFailure(Error) - /// Preplanned map area is currently open. - case opened /// A Boolean value indicating whether the model is in a state /// where it needs to be loaded or reloaded. @@ -246,7 +239,7 @@ extension PreplannedMapModel { var allowsDownload: Bool { switch self { case .notLoaded, .loading, .loadFailure, .packaging, .packageFailure, - .downloading, .downloaded, .mmpkLoadFailure, .opened: + .downloading, .downloaded, .mmpkLoadFailure: false case .packaged, .downloadFailure: true @@ -267,11 +260,6 @@ extension PreplannedMapModel { var isDownloaded: Bool { if case .downloaded = self { true } else { false } } - - /// A Boolean value indicating whether the preplanned map area is opened. - var isOpened: Bool { - if case .opened = self { true } else { false } - } } } diff --git a/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift b/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift index 17a50b01a..413111cc4 100644 --- a/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift +++ b/Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift @@ -30,7 +30,6 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloadFailure(CancellationError()).needsToBeLoaded) XCTAssertTrue(Status.loadFailure(CancellationError()).needsToBeLoaded) XCTAssertTrue(Status.packageFailure.needsToBeLoaded) - XCTAssertTrue(Status.opened.needsToBeLoaded) } func testAllowsDownload() { @@ -44,7 +43,6 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertFalse(Status.downloaded.allowsDownload) XCTAssertTrue(Status.downloadFailure(CancellationError()).allowsDownload) XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).allowsDownload) - XCTAssertFalse(Status.opened.allowsDownload) } func testIsDownloaded() { @@ -58,21 +56,6 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloaded.isDownloaded) XCTAssertFalse(Status.downloadFailure(CancellationError()).isDownloaded) XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).isDownloaded) - XCTAssertFalse(Status.opened.isDownloaded) - } - - func testIsOpened() { - XCTAssertFalse(Status.notLoaded.isOpened) - XCTAssertFalse(Status.loading.isOpened) - XCTAssertFalse(Status.loadFailure(CancellationError()).isOpened) - XCTAssertFalse(Status.packaging.isOpened) - XCTAssertFalse(Status.packaged.isOpened) - XCTAssertFalse(Status.packageFailure.isOpened) - XCTAssertFalse(Status.downloading.isOpened) - XCTAssertFalse(Status.downloaded.isOpened) - XCTAssertFalse(Status.downloadFailure(CancellationError()).isOpened) - XCTAssertFalse(Status.mmpkLoadFailure(CancellationError()).isOpened) - XCTAssertTrue(Status.opened.isOpened) } func testAllowsRemoval() { @@ -86,6 +69,5 @@ class PreplannedMapModelStatusTests: XCTestCase { XCTAssertTrue(Status.downloaded.allowsRemoval) XCTAssertTrue(Status.downloadFailure(CancellationError()).allowsRemoval) XCTAssertTrue(Status.mmpkLoadFailure(CancellationError()).allowsRemoval) - XCTAssertFalse(Status.opened.allowsRemoval) } } From 74f0192aba6c06917815d779c2a3dd426437f638 Mon Sep 17 00:00:00 2001 From: Destiny Hochhalter Date: Tue, 1 Oct 2024 09:45:39 -0700 Subject: [PATCH 7/7] Remove opened status from model --- .../Offline/PreplannedListItemView.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift index 451883cc8..383e8a79d 100644 --- a/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift +++ b/Sources/ArcGISToolkit/Components/Offline/PreplannedListItemView.swift @@ -56,7 +56,11 @@ struct PreplannedListItemView: View { downloadButton } descriptionView - statusView + if isSelected { + openStatusView + } else { + statusView + } } } .contentShape(.rect) @@ -163,6 +167,14 @@ struct PreplannedListItemView: View { } } + private var openStatusView: some View { + HStack(spacing: 4) { + Text("Currently open") + } + .font(.caption2) + .foregroundStyle(.tertiary) + } + @ViewBuilder private var statusView: some View { HStack(spacing: 4) { switch model.status { @@ -175,7 +187,7 @@ struct PreplannedListItemView: View { Image(systemName: "clock.badge.xmark") Text("Packaging") case .packaged: - Text("Package ready for download") + Text("Ready to download") case .packageFailure: Image(systemName: "exclamationmark.circle") Text("Packaging failed")