8
8
import android .graphics .BitmapFactory ;
9
9
import android .net .Uri ;
10
10
import android .os .Bundle ;
11
- import android .widget .Toast ;
12
-
13
11
import androidx .core .app .NotificationCompat ;
14
12
import androidx .core .app .NotificationManagerCompat ;
15
-
16
- import java .io .File ;
17
- import java .io .FileInputStream ;
18
- import java .io .FileNotFoundException ;
19
- import java .io .IOException ;
20
- import java .io .InputStream ;
21
- import java .util .HashSet ;
22
- import java .util .Set ;
23
- import java .util .regex .Matcher ;
24
- import java .util .regex .Pattern ;
25
-
26
- import javax .inject .Inject ;
27
-
28
13
import fr .free .nrw .commons .BuildConfig ;
29
14
import fr .free .nrw .commons .CommonsApplication ;
30
15
import fr .free .nrw .commons .HandlerService ;
40
25
import fr .free .nrw .commons .wikidata .WikidataEditService ;
41
26
import io .reactivex .Observable ;
42
27
import io .reactivex .schedulers .Schedulers ;
28
+ import java .io .File ;
29
+ import java .io .IOException ;
30
+ import java .util .HashSet ;
31
+ import java .util .Set ;
32
+ import java .util .regex .Matcher ;
33
+ import java .util .regex .Pattern ;
34
+ import javax .inject .Inject ;
43
35
import timber .log .Timber ;
44
36
45
37
public class UploadService extends HandlerService <Contribution > {
@@ -80,7 +72,7 @@ public UploadService() {
80
72
super ("UploadService" );
81
73
}
82
74
83
- private class NotificationUpdateProgressListener implements MediaWikiApi .ProgressListener {
75
+ protected class NotificationUpdateProgressListener implements MediaWikiApi .ProgressListener {
84
76
85
77
String notificationTag ;
86
78
boolean notificationTitleChanged ;
@@ -202,29 +194,20 @@ private NotificationCompat.Builder getNotificationBuilder(String channelId) {
202
194
203
195
@ SuppressLint ("CheckResult" )
204
196
private void uploadContribution (Contribution contribution ) {
205
- InputStream fileInputStream ;
206
197
Uri localUri = contribution .getLocalUri ();
207
198
if (localUri == null || localUri .getPath () == null ) {
208
199
Timber .d ("localUri/path is null" );
209
200
return ;
210
201
}
211
202
String notificationTag = localUri .toString ();
212
- File file1 ;
213
- try {
214
- file1 = new File (localUri .getPath ());
215
- fileInputStream = new FileInputStream (file1 );
216
- } catch (FileNotFoundException e ) {
217
- Timber .d ("File not found" );
218
- Toast fileNotFound = Toast .makeText (this , R .string .upload_failed , Toast .LENGTH_LONG );
219
- fileNotFound .show ();
220
- return ;
221
- }
203
+ File localFile = new File (localUri .getPath ());
222
204
223
205
Timber .d ("Before execution!" );
224
206
curNotification .setContentTitle (getString (R .string .upload_progress_notification_title_start , contribution .getDisplayTitle ()))
225
207
.setContentText (getResources ().getQuantityString (R .plurals .uploads_pending_notification_indicator , toUpload , toUpload ))
226
208
.setTicker (getString (R .string .upload_progress_notification_title_in_progress , contribution .getDisplayTitle ()));
227
- notificationManager .notify (notificationTag , NOTIFICATION_UPLOAD_IN_PROGRESS , curNotification .build ());
209
+ notificationManager
210
+ .notify (notificationTag , NOTIFICATION_UPLOAD_IN_PROGRESS , curNotification .build ());
228
211
229
212
String filename = contribution .getFilename ();
230
213
@@ -235,7 +218,9 @@ private void uploadContribution(Contribution contribution) {
235
218
);
236
219
237
220
Observable .fromCallable (() -> "Temp_" + contribution .hashCode () + filename )
238
- .flatMap (stashFilename -> uploadClient .uploadFileToStash (getApplicationContext (), stashFilename , file1 ))
221
+ .flatMap (stashFilename -> uploadClient
222
+ .uploadFileToStash (getApplicationContext (), stashFilename , localFile ,
223
+ notificationUpdater ))
239
224
.subscribeOn (Schedulers .io ())
240
225
.observeOn (Schedulers .io ())
241
226
.doFinally (() -> {
@@ -250,7 +235,7 @@ private void uploadContribution(Contribution contribution) {
250
235
}
251
236
})
252
237
.flatMap (uploadStash -> {
253
- notificationManager .cancel (NOTIFICATION_UPLOAD_IN_PROGRESS );
238
+ notificationManager .cancel (notificationTag , NOTIFICATION_UPLOAD_IN_PROGRESS );
254
239
255
240
Timber .d ("Stash upload response 1 is %s" , uploadStash .toString ());
256
241
@@ -293,7 +278,7 @@ private void uploadContribution(Contribution contribution) {
293
278
}
294
279
}, throwable -> {
295
280
Timber .w (throwable , "Exception during upload" );
296
- notificationManager .cancel (NOTIFICATION_UPLOAD_IN_PROGRESS );
281
+ notificationManager .cancel (notificationTag , NOTIFICATION_UPLOAD_IN_PROGRESS );
297
282
showFailedNotification (contribution );
298
283
});
299
284
}
0 commit comments