-
Notifications
You must be signed in to change notification settings - Fork 8
Support in-progress download restoration #907
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
Merged
shubham7109
merged 20 commits into
feature-branches/offline-map-areas
from
shubham/in-progress-download-restoration
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fef98ee
wired functionality
shubham7109 1466f51
added minor UI cleanups
shubham7109 6733784
wired in OnDemand cancellation, and update list
shubham7109 149742b
code comments
shubham7109 e7e269f
add preplanned onDownloadDeleted support
shubham7109 4d6d42e
bottom sheet cleanup
shubham7109 42fe994
prototyping restoration
shubham7109 1ff1c27
prototyping DisposableEffect
shubham7109 9e3123b
PR feedback and updated localizations
shubham7109 6b545aa
Merge branch 'shubham/on-demand-functionality' into shubham/in-progre…
shubham7109 53e1fb7
moved JobResultToDestination step to Workers
shubham7109 42184ae
added metadata functionality
shubham7109 62c6860
doc cleanup
shubham7109 cf496de
more doc cleanup
shubham7109 45e7f00
testing minor fixes
shubham7109 1ed6d26
Merge branch 'feature-branches/offline-map-areas' into shubham/in-pro…
shubham7109 14485fd
resolve update from feature branch
shubham7109 d897669
cleanup imports
shubham7109 cf7bb94
update preplanned restored state
shubham7109 bc45420
PR feedback
shubham7109 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
toolkit/offline/src/main/java/com/arcgismaps/toolkit/offline/OfflineMapAreaMetadata.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* | ||
* Copyright 2025 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.offline | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import com.arcgismaps.tasks.offlinemaptask.PreplannedMapArea | ||
import com.arcgismaps.toolkit.offline.ondemand.OnDemandMapAreaConfiguration | ||
import com.arcgismaps.toolkit.offline.workmanager.offlineAreaMetadataJsonFile | ||
import com.arcgismaps.toolkit.offline.workmanager.offlineMapInfoThumbnailFile | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.Transient | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
|
||
/** | ||
* Represents the metadata for an area of an offline map. | ||
* | ||
* @since 200.8.0 | ||
*/ | ||
@Serializable | ||
internal data class OfflineMapAreaMetadata( | ||
val itemId: String, | ||
val title: String, | ||
val description: String, | ||
@Transient val thumbnailImage: Bitmap? = null | ||
) { | ||
|
||
companion object { | ||
/** | ||
* Creates an [OfflineMapAreaMetadata] from a [PreplannedMapArea]. | ||
* | ||
* @since 200.8.0 | ||
*/ | ||
internal fun createPreplannedMetadata(preplannedMapArea: PreplannedMapArea): OfflineMapAreaMetadata { | ||
return OfflineMapAreaMetadata( | ||
itemId = preplannedMapArea.portalItem.itemId, | ||
title = preplannedMapArea.portalItem.title, | ||
thumbnailImage = preplannedMapArea.portalItem.thumbnail?.image?.bitmap, | ||
description = preplannedMapArea.portalItem.description | ||
) | ||
} | ||
|
||
/** | ||
* Creates an [OfflineMapAreaMetadata] from an [OnDemandMapAreaConfiguration]. | ||
* | ||
* @since 200.8.0 | ||
*/ | ||
internal fun createOnDemandMetadata(onDemandMapAreaConfiguration: OnDemandMapAreaConfiguration): OfflineMapAreaMetadata { | ||
return OfflineMapAreaMetadata( | ||
itemId = onDemandMapAreaConfiguration.itemId, | ||
title = onDemandMapAreaConfiguration.title, | ||
thumbnailImage = onDemandMapAreaConfiguration.thumbnail, | ||
description = "" | ||
) | ||
} | ||
|
||
/** | ||
* Creates an [OfflineMapAreaMetadata] from a [directory] on disk, if “metadata.json” exists. | ||
* | ||
* @since 200.8.0 | ||
*/ | ||
internal fun createFromDirectory(directory: File): OfflineMapAreaMetadata? { | ||
val metadataFile = File(directory, offlineAreaMetadataJsonFile) | ||
if (!metadataFile.exists()) { | ||
return null | ||
} | ||
val jsonString = runCatching { metadataFile.readText(Charsets.UTF_8) }.getOrNull() | ||
?: return null | ||
val baseMetadata = runCatching { | ||
Json.decodeFromString(serializer(), jsonString) | ||
}.getOrNull() ?: return null | ||
val thumbnailFile = File(directory, offlineMapInfoThumbnailFile) | ||
val thumbnail: Bitmap? = if (thumbnailFile.exists()) { | ||
BitmapFactory.decodeFile(thumbnailFile.absolutePath) | ||
} else { | ||
null | ||
} | ||
return OfflineMapAreaMetadata( | ||
itemId = baseMetadata.itemId, | ||
thumbnailImage = thumbnail, | ||
title = baseMetadata.title, | ||
description = baseMetadata.description | ||
) | ||
} | ||
|
||
/** | ||
* Returns true if metadata.json is found in the [directory]. | ||
*/ | ||
internal fun isSerializedFilePresent(directory: File): Boolean { | ||
return File(directory, offlineAreaMetadataJsonFile).exists() | ||
} | ||
} | ||
|
||
/** | ||
* Save this OfflineMapAreaMetadata into a [directory] on disk. | ||
* | ||
* @since 200.8.0 | ||
*/ | ||
internal fun saveToDirectory(directory: File) { | ||
if (!directory.exists()) { | ||
directory.mkdirs() | ||
} | ||
val metadataFile = File(directory, offlineAreaMetadataJsonFile) | ||
val jsonString = Json.encodeToString(serializer(), this) | ||
runCatching { metadataFile.writeText(jsonString, Charsets.UTF_8) } | ||
thumbnailImage?.let { bmp -> | ||
val thumbFile = File(directory, offlineMapInfoThumbnailFile) | ||
runCatching { | ||
FileOutputStream(thumbFile).use { out -> | ||
bmp.compress(Bitmap.CompressFormat.PNG, 100, out) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.