Skip to content

Commit

Permalink
Bluetooth settings: handle missing permissions
Browse files Browse the repository at this point in the history
fixes #1637
  • Loading branch information
khao-soi authored and dennisguse committed Jul 15, 2023
1 parent 565ef7f commit 77719f5
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

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 {

Expand All @@ -30,6 +33,13 @@ public void onStart() {
@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());
Expand Down

0 comments on commit 77719f5

Please sign in to comment.