control fragment toast cleanup
package org.openbot.common;
-import static org.openbot.utils.Constants.PERMISSION_AUDIO;
-import static org.openbot.utils.Constants.PERMISSION_CAMERA;
-import static org.openbot.utils.Constants.PERMISSION_LOCATION;
-
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
@@ -230,33 +226,18 @@ public abstract class ControlsFragment extends Fragment {
BotToControllerEventBus.emitEvent(ConnectionUtils.createStatus("INDICATOR_STOP", value == 0));
}
+ private boolean allGranted = false;
protected final ActivityResultLauncher<String[]> requestPermissionLauncher =
registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(),
result -> {
- result.forEach(
- (permission, granted) -> {
- switch (permission) {
- case PERMISSION_CAMERA:
- if (!granted) {
- PermissionUtils.showCameraPermissionsControllerToast(requireActivity());
- }
- break;
- case PERMISSION_LOCATION:
- if (!granted) {
- PermissionUtils.showLocationPermissionsControllerToast(requireActivity());
- }
- break;
- case PERMISSION_AUDIO:
- if (!granted) {
- PermissionUtils.showAudioPermissionsControllerToast(requireActivity());
- }
- break;
+ result.forEach((permission, granted) -> allGranted = allGranted && granted);
+
+ if (allGranted) phoneController.connect(requireContext());
+ else {
+ PermissionUtils.showControllerPermissionsToast(requireActivity());
}
});
- if (PermissionUtils.hasControllerPermissions(requireActivity()))
- phoneController.connect(requireContext());
- });
@Override
public void onResume() {
