1
1
package fr .free .nrw .commons .upload ;
2
2
3
3
import static fr .free .nrw .commons .contributions .ContributionController .ACTION_INTERNAL_UPLOADS ;
4
+ import static fr .free .nrw .commons .utils .PermissionUtils .PERMISSIONS_STORAGE ;
4
5
import static fr .free .nrw .commons .wikidata .WikidataConstants .PLACE_OBJECT ;
5
6
6
7
import android .Manifest ;
56
57
import io .reactivex .android .schedulers .AndroidSchedulers ;
57
58
import io .reactivex .disposables .CompositeDisposable ;
58
59
import io .reactivex .schedulers .Schedulers ;
60
+ import java .security .Permission ;
59
61
import java .util .ArrayList ;
60
62
import java .util .Collections ;
61
63
import java .util .HashMap ;
@@ -146,20 +148,19 @@ protected void onCreate(Bundle savedInstanceState) {
146
148
compositeDisposable = new CompositeDisposable ();
147
149
init ();
148
150
nearbyPopupAnswers = new HashMap <>();
149
-
150
151
PermissionUtils .checkPermissionsAndPerformAction (this ,
151
- Manifest . permission . WRITE_EXTERNAL_STORAGE ,
152
- this ::receiveSharedItems ,
153
- R .string .storage_permission_title ,
154
- R .string .write_storage_permission_rationale_for_image_share );
152
+ PERMISSIONS_STORAGE ,
153
+ this ::receiveSharedItems ,
154
+ R .string .storage_permission_title ,
155
+ R .string .write_storage_permission_rationale_for_image_share );
155
156
//getting the current dpi of the device and if it is less than 320dp i.e. overlapping
156
157
//threshold, thumbnails automatically minimizes
157
158
DisplayMetrics metrics = getResources ().getDisplayMetrics ();
158
159
float dpi = (metrics .widthPixels )/(metrics .density );
159
160
if (dpi <=321 ) {
160
161
onRlContainerTitleClicked ();
161
162
}
162
- if (PermissionUtils .hasPermission (this , Manifest .permission .ACCESS_FINE_LOCATION )) {
163
+ if (PermissionUtils .hasPermission (this , new String []{ Manifest .permission .ACCESS_FINE_LOCATION } )) {
163
164
locationManager .registerLocationManager ();
164
165
}
165
166
locationManager .requestLocationUpdatesFromProvider (LocationManager .GPS_PROVIDER );
@@ -181,7 +182,7 @@ private void initProgressDialog() {
181
182
182
183
private void initThumbnailsRecyclerView () {
183
184
rvThumbnails .setLayoutManager (new LinearLayoutManager (this ,
184
- LinearLayoutManager .HORIZONTAL , false ));
185
+ LinearLayoutManager .HORIZONTAL , false ));
185
186
thumbnailsAdapter = new ThumbnailsAdapter (() -> currentSelectedPosition );
186
187
rvThumbnails .setAdapter (thumbnailsAdapter );
187
188
@@ -193,7 +194,7 @@ private void initViewPager() {
193
194
vpUpload .addOnPageChangeListener (new ViewPager .OnPageChangeListener () {
194
195
@ Override
195
196
public void onPageScrolled (int position , float positionOffset ,
196
- int positionOffsetPixels ) {
197
+ int positionOffsetPixels ) {
197
198
198
199
}
199
200
@@ -238,29 +239,31 @@ protected void onResume() {
238
239
*/
239
240
protected void checkBlockStatus () {
240
241
compositeDisposable .add (userClient .isUserBlockedFromCommons ()
241
- .subscribeOn (Schedulers .io ())
242
- .observeOn (AndroidSchedulers .mainThread ())
243
- .filter (result -> result )
244
- .subscribe (result -> DialogUtil .showAlertDialog (
245
- this ,
246
- getString (R .string .block_notification_title ),
247
- getString (R .string .block_notification ),
248
- getString (R .string .ok ),
249
- this ::finish ,
250
- true )));
242
+ .subscribeOn (Schedulers .io ())
243
+ .observeOn (AndroidSchedulers .mainThread ())
244
+ .filter (result -> result )
245
+ .subscribe (result -> DialogUtil .showAlertDialog (
246
+ this ,
247
+ getString (R .string .block_notification_title ),
248
+ getString (R .string .block_notification ),
249
+ getString (R .string .ok ),
250
+ this ::finish ,
251
+ true )));
251
252
}
252
253
253
254
private void checkStoragePermissions () {
254
- PermissionUtils .checkPermissionsAndPerformAction (this ,
255
- Manifest .permission .WRITE_EXTERNAL_STORAGE ,
255
+ final boolean hasAllPermissions = PermissionUtils .hasPermission (this , PERMISSIONS_STORAGE );
256
+ if (!hasAllPermissions ) {
257
+ PermissionUtils .checkPermissionsAndPerformAction (this ,
258
+ PERMISSIONS_STORAGE ,
256
259
() -> {
257
260
//TODO handle this
258
261
},
259
262
R .string .storage_permission_title ,
260
263
R .string .write_storage_permission_rationale_for_image_share );
264
+ }
261
265
}
262
266
263
-
264
267
@ Override
265
268
protected void onStop () {
266
269
super .onStop ();
@@ -328,7 +331,7 @@ public void onUploadMediaDeleted(int index) {
328
331
@ Override
329
332
public void updateTopCardTitle () {
330
333
tvTopCardTitle .setText (getResources ()
331
- .getQuantityString (R .plurals .upload_count_title , uploadableFiles .size (), uploadableFiles .size ()));
334
+ .getQuantityString (R .plurals .upload_count_title , uploadableFiles .size (), uploadableFiles .size ()));
332
335
}
333
336
334
337
@ Override
@@ -370,13 +373,13 @@ private void receiveSharedItems() {
370
373
} else {
371
374
//Show thumbnails
372
375
if (uploadableFiles .size ()
373
- > 1 ) {//If there is only file, no need to show the image thumbnails
376
+ > 1 ) {//If there is only file, no need to show the image thumbnails
374
377
thumbnailsAdapter .setUploadableFiles (uploadableFiles );
375
378
} else {
376
379
llContainerTopCard .setVisibility (View .GONE );
377
380
}
378
381
tvTopCardTitle .setText (getResources ()
379
- .getQuantityString (R .plurals .upload_count_title , uploadableFiles .size (), uploadableFiles .size ()));
382
+ .getQuantityString (R .plurals .upload_count_title , uploadableFiles .size (), uploadableFiles .size ()));
380
383
381
384
fragments = new ArrayList <>();
382
385
/* Suggest users to turn battery optimisation off when uploading more than a few files.
@@ -419,7 +422,7 @@ private void receiveSharedItems() {
419
422
UploadMediaDetailFragment uploadMediaDetailFragment = new UploadMediaDetailFragment ();
420
423
421
424
LocationPermissionsHelper locationPermissionsHelper = new LocationPermissionsHelper (
422
- this , locationManager , null );
425
+ this , locationManager , null );
423
426
if (locationPermissionsHelper .isLocationAccessToAppsTurnedOn ()) {
424
427
currLocation = locationManager .getLastLocation ();
425
428
}
@@ -525,8 +528,8 @@ private float getLocationDifference(LatLng currLocation, LatLng prevLocation) {
525
528
}
526
529
float [] distance = new float [2 ];
527
530
Location .distanceBetween (
528
- currLocation .getLatitude (), currLocation .getLongitude (),
529
- prevLocation .getLatitude (), prevLocation .getLongitude (), distance );
531
+ currLocation .getLatitude (), currLocation .getLongitude (),
532
+ prevLocation .getLatitude (), prevLocation .getLongitude (), distance );
530
533
return distance [0 ];
531
534
}
532
535
@@ -670,5 +673,4 @@ public void onBackPressed() {
670
673
this ::finish
671
674
);
672
675
}
673
-
674
676
}
0 commit comments