mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Add even more prompts (specifically for location) - thanks Google Play :/
This commit is contained in:
parent
031898f538
commit
c101ac74df
@ -89,6 +89,8 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
implements NavigationView.OnNavigationItemSelectedListener, GBActivity {
|
implements NavigationView.OnNavigationItemSelectedListener, GBActivity {
|
||||||
|
|
||||||
public static final int MENU_REFRESH_CODE = 1;
|
public static final int MENU_REFRESH_CODE = 1;
|
||||||
|
public static final String ACTION_REQUEST_PERMISSIONS
|
||||||
|
= "nodomain.freeyourgadget.gadgetbridge.activities.controlcenter.requestpermissions";
|
||||||
private static PhoneStateListener fakeStateListener;
|
private static PhoneStateListener fakeStateListener;
|
||||||
|
|
||||||
//needed for KK compatibility
|
//needed for KK compatibility
|
||||||
@ -123,6 +125,9 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
case DeviceService.ACTION_REALTIME_SAMPLES:
|
case DeviceService.ACTION_REALTIME_SAMPLES:
|
||||||
handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||||
break;
|
break;
|
||||||
|
case ACTION_REQUEST_PERMISSIONS:
|
||||||
|
checkAndRequestPermissions(false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -234,6 +239,7 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
filterLocal.addAction(GBApplication.ACTION_NEW_DATA);
|
filterLocal.addAction(GBApplication.ACTION_NEW_DATA);
|
||||||
filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
|
filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
|
||||||
filterLocal.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
|
filterLocal.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
|
||||||
|
filterLocal.addAction(ACTION_REQUEST_PERMISSIONS);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||||
|
|
||||||
refreshPairedDevices();
|
refreshPairedDevices();
|
||||||
@ -250,7 +256,7 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
// Put up a dialog explaining why we need permissions (Polite, but also Play Store policy)
|
// Put up a dialog explaining why we need permissions (Polite, but also Play Store policy)
|
||||||
// When accepted, we open the Activity for Notification access
|
// When accepted, we open the Activity for Notification access
|
||||||
DialogFragment dialog = new NotifyListenerPermissionsDialogFragment();
|
DialogFragment dialog = new NotifyListenerPermissionsDialogFragment();
|
||||||
dialog.show(getSupportFragmentManager(), "PermissionsDialogFragment");
|
dialog.show(getSupportFragmentManager(), "NotifyListenerPermissionsDialogFragment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,11 +269,11 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
// Put up a dialog explaining why we need permissions (Polite, but also Play Store policy)
|
// Put up a dialog explaining why we need permissions (Polite, but also Play Store policy)
|
||||||
// When accepted, we open the Activity for Notification access
|
// When accepted, we open the Activity for Notification access
|
||||||
DialogFragment dialog = new NotifyPolicyPermissionsDialogFragment();
|
DialogFragment dialog = new NotifyPolicyPermissionsDialogFragment();
|
||||||
dialog.show(getSupportFragmentManager(), "PermissionsDialogFragment");
|
dialog.show(getSupportFragmentManager(), "NotifyPolicyPermissionsDialogFragment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check all the other permissions that we need to for Android M + later
|
// Check all the other permissions that we need to for Android M + later
|
||||||
checkAndRequestPermissions();
|
checkAndRequestPermissions(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeLog cl = createChangeLog();
|
ChangeLog cl = createChangeLog();
|
||||||
@ -405,7 +411,7 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
private void checkAndRequestPermissions() {
|
private void checkAndRequestPermissions(boolean showDialogFirst) {
|
||||||
List<String> wantedPermissions = new ArrayList<>();
|
List<String> wantedPermissions = new ArrayList<>();
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED)
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED)
|
||||||
@ -478,15 +484,20 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wantedPermissions.removeAll(shouldNotAsk);
|
wantedPermissions.removeAll(shouldNotAsk);
|
||||||
} else {
|
} else if (!showDialogFirst) {
|
||||||
// Permissions have not been asked yet, but now will be
|
// Permissions have not been asked yet, but now will be
|
||||||
prefs.getPreferences().edit().putBoolean("permissions_asked", true).apply();
|
prefs.getPreferences().edit().putBoolean("permissions_asked", true).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wantedPermissions.isEmpty()) {
|
if (!wantedPermissions.isEmpty()) {
|
||||||
|
if (showDialogFirst) {
|
||||||
|
// Show a dialog - thus will then call checkAndRequestPermissions(false)
|
||||||
|
DialogFragment dialog = new LocationPermissionsDialogFragment();
|
||||||
|
dialog.show(getSupportFragmentManager(), "LocationPermissionsDialogFragment");
|
||||||
|
} else {
|
||||||
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[0]), 0);
|
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[0]), 0);
|
||||||
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,4 +590,25 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called from checkAndRequestPermissions - this puts up a dialog explaining we need permissions, and then calls checkAndRequestPermissions (via an intent) when 'ok' pressed
|
||||||
|
public static class LocationPermissionsDialogFragment extends DialogFragment {
|
||||||
|
ControlCenterv2 controlCenter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
// Use the Builder class for convenient dialog construction
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
Context context = getContext();
|
||||||
|
builder.setMessage(context.getString(R.string.permission_location,
|
||||||
|
getContext().getString(R.string.app_name),
|
||||||
|
getContext().getString(R.string.ok)))
|
||||||
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
Intent intent = new Intent(ACTION_REQUEST_PERMISSIONS);
|
||||||
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1185,8 +1185,9 @@
|
|||||||
<string name="about_additional_contributions">Many thanks to all unlisted contributors for contributing code, translations, support, ideas, motivation, bug reports, money… ✊</string>
|
<string name="about_additional_contributions">Many thanks to all unlisted contributors for contributing code, translations, support, ideas, motivation, bug reports, money… ✊</string>
|
||||||
<string name="about_links">Links</string>
|
<string name="about_links">Links</string>
|
||||||
<string name="permission_granting_mandatory">All these permissions are required and instability might occur if not granted</string>
|
<string name="permission_granting_mandatory">All these permissions are required and instability might occur if not granted</string>
|
||||||
<string name="permission_notification_listener">%1$s needs access to Notifications in order to display them on your watch.\n\nPlease tap \'%2$s\' then \'%1$s\' and enable \'Allow Notification Access\', then tap \'Back\' to return to %1$s</string>
|
<string name="permission_notification_listener">%1$s needs access to Notifications in order to display them on your watch when your phone\'s screen is off.\n\nPlease tap \'%2$s\' then \'%1$s\' and enable \'Allow Notification Access\', then tap \'Back\' to return to %1$s</string>
|
||||||
<string name="permission_notification_policy_access">%1$s needs access to Do Not Disturb settings in order to honour them on your watch.\n\nPlease tap \'%2$s\' then \'%1$s\' and enable \'Allow Do Not Disturb\', then tap \'Back\' to return to %1$s</string>
|
<string name="permission_notification_policy_access">%1$s needs access to Do Not Disturb settings in order to honour them on your watch when your phone\'s screen is off.\n\nPlease tap \'%2$s\' then \'%1$s\' and enable \'Allow Do Not Disturb\', then tap \'Back\' to return to %1$s</string>
|
||||||
|
<string name="permission_location">%1$s needs access to your location in the background to allow it to stay connected to your watch even when your screen is off.\n\nPlease tap \'%2$s\' to agree.</string>
|
||||||
<string name="error_version_check_extreme_caution">CAUTION: Error when checking version information! You should not continue! Saw version name \"%s\"</string>
|
<string name="error_version_check_extreme_caution">CAUTION: Error when checking version information! You should not continue! Saw version name \"%s\"</string>
|
||||||
<string name="require_location_provider">Location must be enabled</string>
|
<string name="require_location_provider">Location must be enabled</string>
|
||||||
<string name="companiondevice_pairing">CompanionDevice Pairing</string>
|
<string name="companiondevice_pairing">CompanionDevice Pairing</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user