mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Refactor onRequestPermissionsResult to be simpler (#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).
This commit is contained in:
parent
ab783a445f
commit
5f3510226a
1 changed files with 13 additions and 19 deletions
|
|
@ -470,28 +470,22 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
|||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case LOCATION_REQUEST: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Timber.d("Location permission given");
|
||||
((ContributionsFragment)contributionsActivityPagerAdapter
|
||||
.getItem(0)).locationManager.registerLocationManager();
|
||||
} else {
|
||||
// If nearby fragment is visible and location permission is not given, send user back to contrib fragment
|
||||
if (!isContributionsFragmentVisible) {
|
||||
viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION);
|
||||
String[] permissions, int[] grantResults) {
|
||||
if (requestCode == LOCATION_REQUEST) {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Timber.d("Location permission given");
|
||||
((ContributionsFragment)contributionsActivityPagerAdapter
|
||||
.getItem(0)).locationManager.registerLocationManager();
|
||||
} else {
|
||||
// If nearby fragment is visible and location permission is not given, send user back to contrib fragment
|
||||
if (!isContributionsFragmentVisible) {
|
||||
viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION);
|
||||
|
||||
// TODO: If contrib fragment is visible and location permission is not given, display permission request button
|
||||
}
|
||||
// TODO: If contrib fragment is visible and location permission is not given, display permission request button
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue