1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-15 13:14:22 +02:00

use requireContext instead of getContext, see issue #619

This commit is contained in:
oliexdev
2020-08-31 16:52:37 +02:00
parent 2e8e93aa73
commit 1a995be74a

View File

@@ -134,7 +134,7 @@ public class BluetoothSettingsFragment extends Fragment {
deviceListView.removeAllViews();
foundDevices.clear();
central = new BluetoothCentral(getContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
central = new BluetoothCentral(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
central.scanForPeripherals();
txtSearching.setVisibility(View.VISIBLE);
@@ -152,9 +152,9 @@ public class BluetoothSettingsFragment extends Fragment {
txtSearching.setText(R.string.label_bluetooth_searching_finished);
progressBar.setVisibility(View.GONE);
BluetoothDeviceView notSupported = new BluetoothDeviceView(getContext());
notSupported.setDeviceName(getContext().getString(R.string.label_scale_not_supported));
notSupported.setSummaryText(getContext().getString(R.string.label_click_to_help_add_support));
BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext());
notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported));
notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support));
notSupported.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -188,10 +188,10 @@ public class BluetoothSettingsFragment extends Fragment {
return;
}
BluetoothDeviceView deviceView = new BluetoothDeviceView(getContext());
BluetoothDeviceView deviceView = new BluetoothDeviceView(requireContext());
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getContext(), device.getName());
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(requireContext(), device.getName());
if (btDevice != null) {
Timber.d("Found supported device %s (driver: %s)",
formatDeviceName(device), btDevice.driverName());
@@ -203,7 +203,7 @@ public class BluetoothSettingsFragment extends Fragment {
Timber.d("Found unsupported device %s",
formatDeviceName(device));
deviceView.setIcon(R.drawable.ic_bluetooth_device_not_supported);
deviceView.setSummaryText(getContext().getString(R.string.label_bt_device_no_support));
deviceView.setSummaryText(requireContext().getString(R.string.label_bt_device_no_support));
deviceView.setEnabled(false);
if (OpenScale.DEBUG_MODE) {
@@ -222,7 +222,7 @@ public class BluetoothSettingsFragment extends Fragment {
}
private void getDebugInfo(final BluetoothDevice device) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setTitle("Fetching info")
.setMessage("Please wait while we fetch extended info from your scale...")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@@ -320,7 +320,7 @@ public class BluetoothSettingsFragment extends Fragment {
public void setIcon(int resId) {
deviceIcon.setImageResource(resId);
int tintColor = ColorUtil.getTintColor(getContext());
int tintColor = ColorUtil.getTintColor(requireContext());
deviceIcon.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
}
@@ -342,7 +342,7 @@ public class BluetoothSettingsFragment extends Fragment {
public void onClick(View view) {
BluetoothDevice device = foundDevices.get(getDeviceAddress());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
prefs.edit()
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
@@ -379,7 +379,7 @@ public class BluetoothSettingsFragment extends Fragment {
startBluetoothDiscovery();
}
} else {
Toast.makeText(getContext(), R.string.permission_not_granted, Toast.LENGTH_SHORT).show();
Toast.makeText(requireContext(), R.string.permission_not_granted, Toast.LENGTH_SHORT).show();
}
break;
}