88import android .graphics .BitmapRegionDecoder ;
99import android .net .Uri ;
1010import android .support .annotation .Nullable ;
11- import android .util .Log ;
1211
1312import java .io .File ;
14- import java .io .FileInputStream ;
1513import java .io .IOException ;
1614import java .util .ArrayList ;
1715import java .util .Date ;
2624import fr .free .nrw .commons .contributions .Contribution ;
2725import fr .free .nrw .commons .mwapi .MediaWikiApi ;
2826import fr .free .nrw .commons .settings .Prefs ;
27+ import fr .free .nrw .commons .utils .BitmapRegionDecoderWrapper ;
2928import fr .free .nrw .commons .utils .ImageUtils ;
29+ import fr .free .nrw .commons .utils .ImageUtilsWrapper ;
3030import io .reactivex .Observable ;
3131import io .reactivex .Single ;
3232import io .reactivex .disposables .Disposable ;
@@ -57,6 +57,8 @@ public class UploadModel {
5757 private SessionManager sessionManager ;
5858 private Uri currentMediaUri ;
5959 private FileUtilsWrapper fileUtilsWrapper ;
60+ private ImageUtilsWrapper imageUtilsWrapper ;
61+ private BitmapRegionDecoderWrapper bitmapRegionDecoderWrapper ;
6062 private FileProcessor fileProcessor ;
6163
6264 @ Inject
@@ -67,9 +69,12 @@ public class UploadModel {
6769 MediaWikiApi mwApi ,
6870 SessionManager sessionManager ,
6971 FileUtilsWrapper fileUtilsWrapper ,
72+ ImageUtilsWrapper imageUtilsWrapper ,
73+ BitmapRegionDecoderWrapper bitmapRegionDecoderWrapper ,
7074 FileProcessor fileProcessor ) {
7175 this .licenses = licenses ;
7276 this .prefs = prefs ;
77+ this .bitmapRegionDecoderWrapper = bitmapRegionDecoderWrapper ;
7378 this .license = Prefs .Licenses .CC_BY_SA_3 ;
7479 this .licensesByName = licensesByName ;
7580 this .context = context ;
@@ -78,6 +83,7 @@ public class UploadModel {
7883 this .sessionManager = sessionManager ;
7984 this .fileUtilsWrapper = fileUtilsWrapper ;
8085 this .fileProcessor = fileProcessor ;
86+ this .imageUtilsWrapper = imageUtilsWrapper ;
8187 useExtStorage = this .prefs .getBoolean ("useExternalStorage" , false );
8288 }
8389
@@ -103,8 +109,8 @@ void receive(List<Uri> mediaUri, String mimeType, String source, SimilarImageInt
103109 .map (b -> b ? ImageUtils .IMAGE_DUPLICATE : ImageUtils .IMAGE_OK ),
104110 Single .fromCallable (() ->
105111 fileUtilsWrapper .getFileInputStream (filePath ))
106- .map (file -> BitmapRegionDecoder .newInstance (file , false ))
107- .map (ImageUtils ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
112+ .map (file -> bitmapRegionDecoderWrapper .newInstance (file , false ))
113+ .map (imageUtilsWrapper ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
108114 (dupe , dark ) -> dupe | dark )
109115 .observeOn (Schedulers .io ())
110116 .subscribe (item .imageQuality ::onNext , Timber ::e );
@@ -134,15 +140,14 @@ void receiveDirect(Uri media, String mimeType, String source, String wikidataEnt
134140 .map (fileUtilsWrapper ::getSHA1 )
135141 .map (mwApi ::existingFile )
136142 .map (b -> b ? ImageUtils .IMAGE_DUPLICATE : ImageUtils .IMAGE_OK ),
137- Single .fromCallable (() ->
138- filePath )
139- .map (FileUtils ::getGeolocationOfFile )
140- .map (geoLocation -> ImageUtils .checkImageGeolocationIsDifferent (geoLocation ,wikidataItemLocation ))
143+ Single .fromCallable (() -> filePath )
144+ .map (fileUtilsWrapper ::getGeolocationOfFile )
145+ .map (geoLocation -> imageUtilsWrapper .checkImageGeolocationIsDifferent (geoLocation ,wikidataItemLocation ))
141146 .map (r -> r ? ImageUtils .IMAGE_GEOLOCATION_DIFFERENT : ImageUtils .IMAGE_OK ),
142147 Single .fromCallable (() ->
143148 fileUtilsWrapper .getFileInputStream (filePath ))
144- .map (file -> BitmapRegionDecoder .newInstance (file , false ))
145- .map (ImageUtils ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
149+ .map (file -> bitmapRegionDecoderWrapper .newInstance (file , false ))
150+ .map (imageUtilsWrapper ::checkIfImageIsTooDark ), //Returns IMAGE_DARK or IMAGE_OK
146151 (dupe , wrongGeo , dark ) -> dupe | wrongGeo | dark ).subscribe (item .imageQuality ::onNext );
147152 items .add (item );
148153 items .get (0 ).selected = true ;
0 commit comments