Bluetooth settings: handle missing permissions

fixes #1637
This commit is contained in:
michel
2023-07-11 22:20:59 +02:00
committed by Dennis Guse
parent 565ef7f12b
commit 77719f5bcd
@@ -2,14 +2,17 @@ package de.dennisguse.opentracks.settings;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.settings.bluetooth.BluetoothLeSensorPreference;
import de.dennisguse.opentracks.util.PermissionRequester;
public class SensorsSettingsFragment extends PreferenceFragmentCompat {
@@ -30,6 +33,13 @@ public class SensorsSettingsFragment extends PreferenceFragmentCompat {
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference instanceof BluetoothLeSensorPreference) {
if(!PermissionRequester.BLUETOOTH.hasPermission(preference.getContext())) {
// TODO: maybe use requestPermissionsIfNeeded here or disable preferences at all
FragmentActivity activity = getActivity();
Toast.makeText(activity, getString(R.string.permission_bluetooth_failed), Toast.LENGTH_LONG).show();
return;
}
DialogFragment dialogFragment = ((BluetoothLeSensorPreference) preference).createInstance();
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(getParentFragmentManager(), getClass().getSimpleName());