Use verifyPermissions for all permission results

pull/127/merge
Alex Baker 8 years ago
parent 5f6c1c62c0
commit fc6e380ab8

@ -6,7 +6,6 @@
package com.todoroo.astrid.gtasks;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.support.annotation.NonNull;
@ -31,6 +30,8 @@ import org.tasks.preferences.PermissionRequestor;
import javax.inject.Inject;
import static org.tasks.PermissionUtil.verifyPermissions;
public class GtasksPreferences extends InjectingPreferenceActivity implements GoogleTaskListSelectionHandler {
private static final String FRAG_TAG_GOOGLE_TASK_LIST_SELECTION = "frag_tag_google_task_list_selection";
@ -121,7 +122,7 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_ACCOUNTS) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
requestLogin();
}
} else {

@ -6,7 +6,6 @@
package com.todoroo.astrid.core;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import android.support.annotation.NonNull;
@ -23,6 +22,8 @@ import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import static org.tasks.PermissionUtil.verifyPermissions;
/**
* Displays the preference screen for users to edit their preferences
*
@ -70,7 +71,7 @@ public class DefaultsPreferences extends InjectingPreferenceActivity {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_CALENDAR) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
startCalendarSelectionActivity();
}
} else {

@ -6,25 +6,20 @@
package com.todoroo.astrid.files;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.widget.Chronometer;
import org.tasks.R;
import org.tasks.dialogs.RecordAudioDialog;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.ActivityPermissionRequestor;
import org.tasks.preferences.PermissionRequestor;
import org.tasks.preferences.Preferences;
import org.tasks.themes.Theme;
import javax.inject.Inject;
import butterknife.BindView;
import static org.tasks.PermissionUtil.verifyPermissions;
import static org.tasks.dialogs.RecordAudioDialog.newRecordAudioDialog;
public class AACRecordingActivity extends InjectingAppCompatActivity implements RecordAudioDialog.RecordAudioDialogCallback {
@ -33,12 +28,9 @@ public class AACRecordingActivity extends InjectingAppCompatActivity implements
public static final String RESULT_OUTFILE = "outfile"; //$NON-NLS-1$
@Inject Preferences preferences;
@Inject ActivityPermissionRequestor permissionRequestor;
@Inject Theme theme;
@BindView(R.id.timer) Chronometer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -66,7 +58,7 @@ public class AACRecordingActivity extends InjectingAppCompatActivity implements
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_MIC) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
showDialog();
} else {
finish();

@ -6,7 +6,6 @@
package com.todoroo.astrid.reminders;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
@ -40,6 +39,7 @@ import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybean;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
import static org.tasks.PermissionUtil.verifyPermissions;
public class ReminderPreferences extends InjectingPreferenceActivity {
@ -117,12 +117,9 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_CONTACTS) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
return;
}
if (verifyPermissions(grantResults)) {
fieldMissedCalls.setChecked(true);
}
fieldMissedCalls.setChecked(true);
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@ -8,7 +8,6 @@ package com.todoroo.astrid.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
@ -58,6 +57,7 @@ import butterknife.OnItemSelected;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static com.todoroo.andlib.utility.DateUtilities.getLongDateStringWithTime;
import static org.tasks.PermissionUtil.verifyPermissions;
import static org.tasks.date.DateTimeUtils.newDateTime;
/**
@ -269,7 +269,7 @@ public class ReminderControlSet extends TaskEditControlFragment {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_LOCATION) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
pickLocation();
}
} else {

@ -4,7 +4,8 @@ import android.content.pm.PackageManager;
public abstract class PermissionUtil {
public static boolean verifyPermissions(int[] grantResults) {
if(grantResults.length < 1){
if(grantResults.length == 0) {
// request canceled
return false;
}

@ -1,7 +1,6 @@
package org.tasks.activities;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -14,7 +13,6 @@ import org.tasks.calendars.CalendarProvider;
import org.tasks.dialogs.AlertDialogBuilder;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.injection.DialogFragmentComponent;
import org.tasks.injection.ForActivity;
import org.tasks.injection.InjectingDialogFragment;
import org.tasks.preferences.FragmentPermissionRequestor;
import org.tasks.preferences.PermissionChecker;
@ -47,7 +45,6 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
@Inject DialogBuilder dialogBuilder;
@Inject CalendarProvider calendarProvider;
@Inject @ForActivity Context context;
@Inject FragmentPermissionRequestor fragmentPermissionRequestor;
@Inject PermissionChecker permissionChecker;
@Inject Theme theme;
@ -114,7 +111,7 @@ public class CalendarSelectionDialog extends InjectingDialogFragment {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_CALENDAR) {
if (grantResults.length > 0 && !verifyPermissions(grantResults)) {
if (!verifyPermissions(grantResults)) {
handler.cancel();
}
} else {

@ -2,7 +2,6 @@ package org.tasks.files;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
@ -20,6 +19,8 @@ import java.io.File;
import javax.inject.Inject;
import static org.tasks.PermissionUtil.verifyPermissions;
public class FileExplore extends InjectingAppCompatActivity {
private static final int REQUEST_PICKER = 1000;
@ -79,12 +80,10 @@ public class FileExplore extends InjectingAppCompatActivity {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_FILE_WRITE) {
if (grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
launchPicker();
} else {
finish();
}
if (verifyPermissions(grantResults)) {
launchPicker();
} else {
finish();
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

@ -1,7 +1,6 @@
package org.tasks.preferences;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.speech.tts.TextToSpeech;
@ -21,6 +20,8 @@ import javax.inject.Inject;
import timber.log.Timber;
import static org.tasks.PermissionUtil.verifyPermissions;
public class MiscellaneousPreferences extends InjectingPreferenceActivity {
private static final int REQUEST_CODE_FILES_DIR = 2;
@ -143,7 +144,7 @@ public class MiscellaneousPreferences extends InjectingPreferenceActivity {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_CALENDAR) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
calendarReminderPreference.setChecked(true);
}
} else {

@ -5,7 +5,6 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@ -44,6 +43,7 @@ import timber.log.Timber;
import static android.support.v4.content.ContextCompat.getColor;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.tasks.PermissionUtil.verifyPermissions;
public class CalendarControlSet extends TaskEditControlFragment {
@ -289,11 +289,11 @@ public class CalendarControlSet extends TaskEditControlFragment {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_CODE_OPEN_EVENT) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
openCalendarEvent();
}
} else if (requestCode == REQUEST_CODE_CLEAR_EVENT) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (verifyPermissions(grantResults)) {
clear();
}
} else {

Loading…
Cancel
Save