Skip to content

Commit

Permalink
Merge branch 'dev' into 3858-batch-download-activities
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticviking authored Feb 28, 2025
2 parents 6f40eeb + 6400e02 commit 3576b86
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- mobile-android
jobs:
build-android:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
EXPORT_DIR: ${{ 'export' }}
steps:
Expand All @@ -22,7 +22,7 @@ jobs:
name: Setup Java
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
#
- name: Setup Android SDK
uses: android-actions/setup-android@v3
Expand Down
3 changes: 1 addition & 2 deletions app/src/UI/Overlay/TileCache/TileCacheDownloadProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const TileCacheDownloadProgress = () => {
</section>
);
}

return (
<section>
<table>
Expand All @@ -34,7 +33,7 @@ const TileCacheDownloadProgress = () => {
<tbody>
{Object.keys(downloadProgress).map((k) => (
<tr key={k}>
<td>{downloadProgress[k].repository}</td>
<td>{downloadProgress[k].description ?? downloadProgress[k].repository}</td>
<td>{downloadProgress[k].message}</td>
<td>
<LinearProgress variant={'determinate'} value={downloadProgress[k].normalizedProgress * 100} />
Expand Down
1 change: 0 additions & 1 deletion app/src/UI/Overlay/TileCache/tileCache.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
border-collapse: collapse;
border: 1pt solid lightgray;
border-radius: 5pt;
table-layout: fixed;
word-wrap: break-word;

tbody tr:nth-child(odd) {
Expand Down
46 changes: 30 additions & 16 deletions app/src/state/actions/cache/TileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { createAction, createAsyncThunk, nanoid } from '@reduxjs/toolkit';
import { GeoJSON } from 'geojson';
import DownloadActions from '../downloads/DownloadActions';
import { TileCacheServiceFactory } from 'utils/tile-cache/context';
import { TileCacheProgressCallbackParameters, RepositoryBoundingBoxSpec } from 'utils/tile-cache';
import { TileCacheProgressCallbackParameters, RepositoryBoundingBoxSpec, RepositoryStatus } from 'utils/tile-cache';
import { RootState } from 'state/reducers/rootReducer';

class TileCache {
static readonly PREFIX = 'TileCache';
Expand Down Expand Up @@ -42,25 +43,38 @@ class TileCache {
bounds: RepositoryBoundingBoxSpec;
id?: string;
},
{ dispatch }
{ dispatch, getState }
) => {
await dispatch(DownloadActions.request());
const service = await TileCacheServiceFactory.getPlatformInstance();
const id = spec.id ?? `tile-cache-${nanoid()}`;
await service.download(
{
id: id,
maxZoom: spec.maxZoom,
bounds: spec.bounds,
dispatch(
TileCache.downloadProgressEvent({
repository: id,
description: spec.description,
tileURL: (x, y, z) =>
`https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/${z}/${y}/${x}`
},
(p) => {
dispatch(TileCache.downloadProgressEvent(p));
}
message: RepositoryStatus.QUEUED,
aborted: false,
normalizedProgress: 0,
totalTiles: 0,
processedTiles: 0
})
);

await dispatch(DownloadActions.request());
const downloadInQueue = !!(getState() as RootState)?.TileCache?.downloadProgress?.[id];
const service = await TileCacheServiceFactory.getPlatformInstance();
if (downloadInQueue) {
await service.download(
{
id: id,
maxZoom: spec.maxZoom,
bounds: spec.bounds,
description: spec.description,
tileURL: (x, y, z) =>
`https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/${z}/${y}/${x}`
},
(p) => {
dispatch(TileCache.downloadProgressEvent(p));
}
);
}
return await service.listRepositories();
}
);
Expand Down
3 changes: 3 additions & 0 deletions app/src/state/reducers/tile_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ function createTileCacheReducer() {

if (TileCache.deleteRepository.pending.match(action)) {
draft.loading = true;
if (Object.prototype.hasOwnProperty.call(draft.downloadProgress, action.meta.arg)) {
delete draft.downloadProgress[action.meta.arg];
}
} else if (TileCache.deleteRepository.fulfilled.match(action)) {
draft.loading = false;
draft.repositories = action.payload;
Expand Down
11 changes: 7 additions & 4 deletions app/src/utils/tile-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export interface RepositoryMetadata {
enum RepositoryStatus {
DOWNLOADING = 'DOWNLOADING',
DELETING = 'DELETING',
READY = 'READY',
FAILED = 'FAILED',
READY = 'READY',
QUEUED = 'QUEUED',
UNKNOWN = 'UNKNOWN'
}
interface TilePromise {
Expand All @@ -53,12 +54,13 @@ interface TilePromise {
}

export interface TileCacheProgressCallbackParameters {
repository: string;
message: string;
aborted: boolean;
description?: string;
message: string;
normalizedProgress: number;
totalTiles: number;
processedTiles: number;
repository: string;
totalTiles: number;
}

export interface RepositoryStatistics {
Expand Down Expand Up @@ -189,6 +191,7 @@ abstract class TileCacheService extends BaseCacheService<
if (progressCallback) {
progressCallback({
repository: spec.id,
description: spec.description,
message: abort ? `Aborting` : `${processedTiles.toLocaleString()}/${totalTiles.toLocaleString()} Tiles`,
aborted: abort,
normalizedProgress: processedTiles / totalTiles,
Expand Down

0 comments on commit 3576b86

Please sign in to comment.