@@ -53,23 +53,30 @@ public class UploadModel {
53
53
private boolean useExtStorage ;
54
54
private Disposable badImageSubscription ;
55
55
56
- @ Inject
57
- SessionManager sessionManager ;
56
+ private SessionManager sessionManager ;
58
57
private Uri currentMediaUri ;
58
+ private FileUtilsWrapper fileUtilsWrapper ;
59
+ private FileProcessor fileProcessor ;
59
60
60
61
@ Inject
61
62
UploadModel (@ Named ("licenses" ) List <String > licenses ,
62
63
@ Named ("default_preferences" ) SharedPreferences prefs ,
63
64
@ Named ("licenses_by_name" ) Map <String , String > licensesByName ,
64
65
Context context ,
65
- MediaWikiApi mwApi ) {
66
+ MediaWikiApi mwApi ,
67
+ SessionManager sessionManager ,
68
+ FileUtilsWrapper fileUtilsWrapper ,
69
+ FileProcessor fileProcessor ) {
66
70
this .licenses = licenses ;
67
71
this .prefs = prefs ;
68
72
this .license = Prefs .Licenses .CC_BY_SA_3 ;
69
73
this .licensesByName = licensesByName ;
70
74
this .context = context ;
71
75
this .mwApi = mwApi ;
72
76
this .contentResolver = context .getContentResolver ();
77
+ this .sessionManager = sessionManager ;
78
+ this .fileUtilsWrapper = fileUtilsWrapper ;
79
+ this .fileProcessor = fileProcessor ;
73
80
useExtStorage = this .prefs .getBoolean ("useExternalStorage" , false );
74
81
}
75
82
@@ -84,17 +91,17 @@ void receive(List<Uri> mediaUri, String mimeType, String source, SimilarImageInt
84
91
.map (filePath -> {
85
92
long fileCreatedDate = getFileCreatedDate (currentMediaUri );
86
93
Uri uri = Uri .fromFile (new File (filePath ));
87
- FileProcessor fp = new FileProcessor (filePath , context .getContentResolver (), context );
88
- UploadItem item = new UploadItem (uri , mimeType , source , fp .processFileCoordinates (similarImageInterface ),
89
- FileUtils .getFileExt (filePath ), null ,fileCreatedDate );
94
+ fileProcessor . initFileDetails (filePath , context .getContentResolver ());
95
+ UploadItem item = new UploadItem (uri , mimeType , source , fileProcessor .processFileCoordinates (similarImageInterface ),
96
+ fileUtilsWrapper .getFileExt (filePath ), null ,fileCreatedDate );
90
97
Single .zip (
91
98
Single .fromCallable (() ->
92
- new FileInputStream (filePath ))
93
- .map (FileUtils ::getSHA1 )
99
+ fileUtilsWrapper . getFileInputStream (filePath ))
100
+ .map (fileUtilsWrapper ::getSHA1 )
94
101
.map (mwApi ::existingFile )
95
102
.map (b -> b ? ImageUtils .IMAGE_DUPLICATE : ImageUtils .IMAGE_OK ),
96
103
Single .fromCallable (() ->
97
- new FileInputStream (filePath ))
104
+ fileUtilsWrapper . getFileInputStream (filePath ))
98
105
.map (file -> BitmapRegionDecoder .newInstance (file , false ))
99
106
.map (ImageUtils ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
100
107
(dupe , dark ) -> dupe | dark )
@@ -113,24 +120,24 @@ void receiveDirect(Uri media, String mimeType, String source, String wikidataEnt
113
120
long fileCreatedDate = getFileCreatedDate (media );
114
121
String filePath = this .cacheFileUpload (media );
115
122
Uri uri = Uri .fromFile (new File (filePath ));
116
- FileProcessor fp = new FileProcessor (filePath , context .getContentResolver (), context );
117
- UploadItem item = new UploadItem (uri , mimeType , source , fp .processFileCoordinates (similarImageInterface ),
118
- FileUtils .getFileExt (filePath ), wikidataEntityIdPref ,fileCreatedDate );
123
+ fileProcessor . initFileDetails (filePath , context .getContentResolver ());
124
+ UploadItem item = new UploadItem (uri , mimeType , source , fileProcessor .processFileCoordinates (similarImageInterface ),
125
+ fileUtilsWrapper .getFileExt (filePath ), wikidataEntityIdPref ,fileCreatedDate );
119
126
item .title .setTitleText (title );
120
127
item .descriptions .get (0 ).setDescriptionText (desc );
121
128
//TODO figure out if default descriptions in other languages exist
122
129
item .descriptions .get (0 ).setLanguageCode ("en" );
123
130
Single .zip (
124
131
Single .fromCallable (() ->
125
- new FileInputStream (filePath ))
126
- .map (FileUtils ::getSHA1 )
132
+ fileUtilsWrapper . getFileInputStream (filePath ))
133
+ .map (fileUtilsWrapper ::getSHA1 )
127
134
.map (mwApi ::existingFile )
128
135
.map (b -> b ? ImageUtils .IMAGE_DUPLICATE : ImageUtils .IMAGE_OK ),
129
136
Single .fromCallable (() ->
130
- new FileInputStream (filePath ))
137
+ fileUtilsWrapper . getFileInputStream (filePath ))
131
138
.map (file -> BitmapRegionDecoder .newInstance (file , false ))
132
139
.map (ImageUtils ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
133
- (dupe , dark ) -> dupe | dark ).subscribe (item .imageQuality ::onNext );
140
+ (dupe , dark ) -> dupe | dark ).subscribe (item .imageQuality ::onNext , Timber :: e );
134
141
items .add (item );
135
142
items .get (0 ).selected = true ;
136
143
items .get (0 ).first = true ;
@@ -239,7 +246,7 @@ public void next() {
239
246
updateItemState ();
240
247
}
241
248
242
- public void setCurrentTitleAndDescriptions (Title title , List <Description > descriptions ) {
249
+ void setCurrentTitleAndDescriptions (Title title , List <Description > descriptions ) {
243
250
setCurrentUploadTitle (title );
244
251
setCurrentUploadDescriptions (descriptions );
245
252
}
@@ -337,9 +344,9 @@ private String cacheFileUpload(Uri media) {
337
344
try {
338
345
String copyPath ;
339
346
if (useExtStorage )
340
- copyPath = FileUtils .createExternalCopyPathAndCopy (media , contentResolver );
347
+ copyPath = fileUtilsWrapper .createExternalCopyPathAndCopy (media , contentResolver );
341
348
else
342
- copyPath = FileUtils .createCopyPathAndCopy (media , context );
349
+ copyPath = fileUtilsWrapper .createCopyPathAndCopy (media , context );
343
350
Timber .i ("File path is " + copyPath );
344
351
return copyPath ;
345
352
} catch (IOException e ) {
@@ -362,6 +369,9 @@ void subscribeBadPicture(Consumer<Integer> consumer) {
362
369
badImageSubscription = getCurrentItem ().imageQuality .subscribe (consumer , Timber ::e );
363
370
}
364
371
372
+ public List <UploadItem > getItems () {
373
+ return items ;
374
+ }
365
375
366
376
@ SuppressWarnings ("WeakerAccess" )
367
377
static class UploadItem {
0 commit comments