Skip to content

Commit 5f35102

Browse files
Deskananeslihanturan
authored andcommitted
Refactor onRequestPermissionsResult to be simpler (commons-app#2965)
onRequestPermissionsResult has a switch statement with a single case, and a functionally empty default; this patch refactors it into an if statement to simplify the code. This patch also changes a C-style array declaration (String permissions[]) to the more standard Java style (String[] permissions).
1 parent ab783a4 commit 5f35102

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -470,28 +470,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
470470

471471
@Override
472472
public void onRequestPermissionsResult(int requestCode,
473-
String permissions[], int[] grantResults) {
474-
switch (requestCode) {
475-
case LOCATION_REQUEST: {
476-
// If request is cancelled, the result arrays are empty.
477-
if (grantResults.length > 0
478-
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
479-
Timber.d("Location permission given");
480-
((ContributionsFragment)contributionsActivityPagerAdapter
481-
.getItem(0)).locationManager.registerLocationManager();
482-
} else {
483-
// If nearby fragment is visible and location permission is not given, send user back to contrib fragment
484-
if (!isContributionsFragmentVisible) {
485-
viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION);
473+
String[] permissions, int[] grantResults) {
474+
if (requestCode == LOCATION_REQUEST) {
475+
// If request is cancelled, the result arrays are empty.
476+
if (grantResults.length > 0
477+
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
478+
Timber.d("Location permission given");
479+
((ContributionsFragment)contributionsActivityPagerAdapter
480+
.getItem(0)).locationManager.registerLocationManager();
481+
} else {
482+
// If nearby fragment is visible and location permission is not given, send user back to contrib fragment
483+
if (!isContributionsFragmentVisible) {
484+
viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION);
486485

487-
// TODO: If contrib fragment is visible and location permission is not given, display permission request button
488-
}
486+
// TODO: If contrib fragment is visible and location permission is not given, display permission request button
489487
}
490-
return;
491488
}
492-
493-
default:
494-
return;
495489
}
496490
}
497491

0 commit comments

Comments
 (0)