7
7
import androidx .annotation .IntDef ;
8
8
import androidx .annotation .NonNull ;
9
9
10
+ import org .mozilla .vrbrowser .R ;
10
11
import org .mozilla .vrbrowser .ui .adapters .Language ;
11
12
import org .mozilla .vrbrowser .utils .LocaleUtils ;
12
13
@@ -37,6 +38,7 @@ public class Download {
37
38
private String mDescription ;
38
39
private @ Status int mStatus ;
39
40
private long mLastModified ;
41
+ private String mReason ;
40
42
41
43
public static Download from (Cursor cursor ) {
42
44
Download download = new Download ();
@@ -69,6 +71,7 @@ public static Download from(Cursor cursor) {
69
71
download .mSizeBytes = cursor .getLong (cursor .getColumnIndex (DownloadManager .COLUMN_TOTAL_SIZE_BYTES ));
70
72
download .mDownloadedBytes = cursor .getLong (cursor .getColumnIndex (DownloadManager .COLUMN_BYTES_DOWNLOADED_SO_FAR ));
71
73
download .mLastModified = cursor .getLong (cursor .getColumnIndex (DownloadManager .COLUMN_LAST_MODIFIED_TIMESTAMP ));
74
+ download .mReason = cursor .getString (cursor .getColumnIndex (DownloadManager .COLUMN_REASON ));
72
75
return download ;
73
76
}
74
77
@@ -140,7 +143,7 @@ public double getProgress() {
140
143
141
144
public String getFilename () {
142
145
try {
143
- File f = new File (new URL (mOutputFile ).getPath ());
146
+ File f = new File (new URL (mUri ).getPath ());
144
147
return f .getName ();
145
148
146
149
} catch (Exception e ) {
@@ -153,30 +156,51 @@ public String getFilename() {
153
156
}
154
157
}
155
158
159
+ public String getReason () {
160
+ return mReason ;
161
+ }
162
+
156
163
@ NonNull
157
164
public static String progressString (@ NonNull Context context , @ NonNull Download download ) {
165
+
158
166
Language language = LocaleUtils .getDisplayLanguage (context );
159
- if (download .mStatus == RUNNING ) {
160
- if (download .mSizeBytes < MEGABYTE ) {
161
- return String .format (language .getLocale (), "%.2f/%.2fKb (%d%%)" ,
162
- ((double )download .mDownloadedBytes / (double )KILOBYTE ),
163
- ((double )download .mSizeBytes / (double )KILOBYTE ),
164
- (download .mDownloadedBytes *100 )/download .mSizeBytes );
167
+ switch (download .mStatus ) {
168
+ case Download .RUNNING :
169
+ if (download .mSizeBytes < MEGABYTE ) {
170
+ return String .format (language .getLocale (), "%.2f/%.2fKb (%d%%)" ,
171
+ ((double )download .mDownloadedBytes / (double )KILOBYTE ),
172
+ ((double )download .mSizeBytes / (double )KILOBYTE ),
173
+ (download .mDownloadedBytes *100 )/download .mSizeBytes );
165
174
166
- } else {
167
- return String .format (language .getLocale (), "%.2f/%.2fMB (%d%%)" ,
168
- ((double )download .mDownloadedBytes / (double )MEGABYTE ),
169
- ((double )download .mSizeBytes / (double )MEGABYTE ),
170
- (download .mDownloadedBytes *100 )/download .mSizeBytes );
171
- }
175
+ } else {
176
+ return String .format (language .getLocale (), "%.2f/%.2fMB (%d%%)" ,
177
+ ((double )download .mDownloadedBytes / (double )MEGABYTE ),
178
+ ((double )download .mSizeBytes / (double )MEGABYTE ),
179
+ (download .mDownloadedBytes *100 )/download .mSizeBytes );
180
+ }
172
181
173
- } else {
174
- if (download .mSizeBytes < MEGABYTE ) {
175
- return String .format (language .getLocale (), "%.2fKb" , ((double )download .mSizeBytes / (double )KILOBYTE ));
182
+ case Download . SUCCESSFUL :
183
+ if (download .mSizeBytes < MEGABYTE ) {
184
+ return String .format (language .getLocale (), "%.2fKb" , ((double )download .mSizeBytes / (double )KILOBYTE ));
176
185
177
- } else {
178
- return String .format (language .getLocale (), "%.2fMB" , ((double )download .mSizeBytes / (double )MEGABYTE ));
179
- }
186
+ } else {
187
+ return String .format (language .getLocale (), "%.2fMB" , ((double )download .mSizeBytes / (double )MEGABYTE ));
188
+ }
189
+
190
+ case Download .FAILED :
191
+ return context .getString (R .string .download_status_failed );
192
+
193
+ case Download .PAUSED :
194
+ return context .getString (R .string .download_status_paused );
195
+
196
+ case Download .PENDING :
197
+ return context .getString (R .string .download_status_pending );
198
+
199
+ case Download .UNAVAILABLE :
200
+ return context .getString (R .string .download_status_unavailable );
201
+
202
+ default :
203
+ return context .getString (R .string .download_status_unknown_error );
180
204
}
181
205
}
182
206
}
0 commit comments