Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline: Refactor selection UI #894

Open
wants to merge 3 commits into
base: OfflineMapAreasView
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,7 +64,7 @@ struct PreplannedListItemView: View {
deleteButton
}
.onTapGesture {
if model.status.isDownloaded {
if model.status.isDownloaded || model.status.isOpened {
metadataViewIsPresented = true
}
}
Expand All @@ -75,6 +75,9 @@ struct PreplannedListItemView: View {
}
.task {
await model.load()
if isSelected {
model.openPreplannedMapArea()
}
}
.onAppear {
downloadState = .init(model.status)
Expand Down Expand Up @@ -115,11 +118,12 @@ struct PreplannedListItemView: View {

@ViewBuilder private var downloadButton: some View {
switch downloadState {
case .downloaded:
case .downloaded, .opened:
Button {
Task {
if let map = await model.map {
selectedMap = map
model.openPreplannedMapArea()
}
}
} label: {
Expand Down Expand Up @@ -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")
Expand All @@ -186,6 +190,8 @@ struct PreplannedListItemView: View {
case .downloadFailure:
Image(systemName: "exclamationmark.circle")
Text("Download failed")
case .opened:
Text("Currently open")
}
}
.font(.caption2)
Expand All @@ -200,6 +206,7 @@ private extension PreplannedListItemView.DownloadState {
self = switch state {
case .downloaded: .downloaded
case .downloading: .downloading
case .opened: .opened
default: .notDownloaded
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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 }
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Tests/ArcGISToolkitTests/PreplannedMapModelStatusTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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)
}
}