summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
blob: fe12dd46c4bc562a16f39900da2249980e11bdeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.mapbox.mapboxsdk.offline;

/**
 * A region's status includes its active/inactive state as well as counts
 * of the number of resources that have completed downloading, their total
 * size in bytes, and the total number of resources that are required.
 * <p>
 * Note that the total required size in bytes is not currently available. A
 * future API release may provide an estimate of this number.
 * </p>
 */
public class OfflineRegionStatus {

  @OfflineRegion.DownloadState
  private int downloadState = OfflineRegion.STATE_INACTIVE;

  /**
   * The number of resources (inclusive of tiles) that have been fully downloaded
   * and are ready for offline access.
   */
  private long completedResourceCount = 0;

  /**
   * The cumulative size, in bytes, of all resources (inclusive of tiles) that have
   * been fully downloaded.
   */
  private long completedResourceSize = 0;

  /**
   * The number of tiles that have been fully downloaded and are ready for
   * offline access.
   */
  private long completedTileCount = 0;

  /**
   * The cumulative size, in bytes, of all tiles that have been fully downloaded.
   */
  private long completedTileSize = 0;

  /**
   * The number of resources that are known to be required for this region. See the
   * documentation for `requiredResourceCountIsPrecise` for an important caveat
   * about this number.
   */
  private long requiredResourceCount = 0;

  /**
   * This property is true when the value of requiredResourceCount is a precise
   * count of the number of required resources, and false when it is merely a lower
   * bound.
   * <p>
   * Specifically, it is false during early phases of an offline download. Once
   * style and tile sources have been downloaded, it is possible to calculate the
   * precise number of required resources, at which point it is set to true.
   * </p>
   */
  private boolean requiredResourceCountIsPrecise = true;

  /*
   * Use setObserver(OfflineRegionObserver observer) to obtain a OfflineRegionStatus object.
   *
   * For JNI use only
   */
  private OfflineRegionStatus(int downloadState, long completedResourceCount,
                              long completedResourceSize, long completedTileCount,
                              long completedTileSize, long requiredResourceCount,
                              boolean requiredResourceCountIsPrecise) {
    this.downloadState = downloadState;
    this.completedResourceCount = completedResourceCount;
    this.completedResourceSize = completedResourceSize;
    this.completedTileCount = completedTileCount;
    this.completedTileSize = completedTileSize;
    this.requiredResourceCount = requiredResourceCount;
    this.requiredResourceCountIsPrecise = requiredResourceCountIsPrecise;
  }

  /**
   * Validates if the region download has completed
   *
   * @return true if download is complete, false if not
   */
  public boolean isComplete() {
    return (completedResourceCount == requiredResourceCount);
  }

  /**
   * Returns the download state.
   * <p>
   * State is defined as
   * </p>
   * <ul>
   * <li>{@link OfflineRegion#STATE_ACTIVE}</li>
   * <li>{@link OfflineRegion#STATE_INACTIVE}</li>
   * </ul>
   *
   * @return the download state.
   */
  @OfflineRegion.DownloadState
  public int getDownloadState() {
    return downloadState;
  }

  /**
   * Get the number of resources (inclusive of tiles) that have been fully downloaded
   * and are ready for offline access.
   *
   * @return the amount of resources that have finished downloading.
   */
  public long getCompletedResourceCount() {
    return completedResourceCount;
  }

  /**
   * The cumulative size, in bytes, of all resources (inclusive of tiles) that have
   * been fully downloaded.
   *
   * @return the size of the resources that have finished downloading
   */
  public long getCompletedResourceSize() {
    return completedResourceSize;
  }

  /**
   * Get the number of tiles that have been fully downloaded and are ready for
   * offline access.
   *
   * @return the completed tile count
   */
  public long getCompletedTileCount() {
    return completedTileCount;
  }

  /**
   * Get the cumulative size, in bytes, of all tiles that have been fully downloaded.
   *
   * @return the completed tile size
   */
  public long getCompletedTileSize() {
    return completedTileSize;
  }

  /**
   * Get the number of resources that are known to be required for this region. See the
   * documentation for `requiredResourceCountIsPrecise` for an important caveat
   * about this number.
   *
   * @return the amount of resources that are required
   */
  public long getRequiredResourceCount() {
    return requiredResourceCount;
  }

  /**
   * Returns when the value of requiredResourceCount is a precise
   * count of the number of required resources, and false when it is merely a lower
   * bound.
   * <p>
   * Specifically, it is false during early phases of an offline download. Once
   * style and tile sources have been downloaded, it is possible to calculate the
   * precise number of required resources, at which point it is set to true.
   * </p>
   *
   * @return True if the required resource count is precise, false if not
   */
  public boolean isRequiredResourceCountPrecise() {
    return requiredResourceCountIsPrecise;
  }

}