mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-12 10:32:36 +00:00
improve code check score
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
4041d3f09b
commit
56d57c0b37
@ -33,6 +33,7 @@ import android.view.Surface;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.databinding.ActivityTakePictureBinding;
|
||||
import com.nextcloud.talk.models.TakePictureViewModel;
|
||||
import com.nextcloud.talk.utils.FileUtils;
|
||||
@ -64,7 +65,7 @@ public class TakePhotoActivity extends AppCompatActivity {
|
||||
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
|
||||
private OrientationEventListener orientationEventListener;
|
||||
|
||||
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.ROOT);
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.ROOT);
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -81,17 +82,34 @@ public class TakePhotoActivity extends AppCompatActivity {
|
||||
final ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
|
||||
final Preview preview = getPreview();
|
||||
final ImageCapture imageCapture = getImageCapture();
|
||||
final Camera camera = cameraProvider.bindToLifecycle(this, viewModel.getCameraSelector(), imageCapture, preview);
|
||||
final Camera camera = cameraProvider.bindToLifecycle(
|
||||
this,
|
||||
viewModel.getCameraSelector(),
|
||||
imageCapture,
|
||||
preview);
|
||||
|
||||
viewModel.getCameraSelectorToggleButtonImageResource().observe(this, res -> binding.switchCamera.setImageDrawable(ContextCompat.getDrawable(this, res)));
|
||||
viewModel.getTorchToggleButtonImageResource().observe(this, res -> binding.toggleTorch.setImageDrawable(ContextCompat.getDrawable(this, res)));
|
||||
viewModel.isTorchEnabled().observe(this, enabled -> camera.getCameraControl().enableTorch(enabled));
|
||||
viewModel.getCameraSelectorToggleButtonImageResource()
|
||||
.observe(
|
||||
this,
|
||||
res -> binding.switchCamera.setImageDrawable(ContextCompat.getDrawable(this, res)));
|
||||
viewModel.getTorchToggleButtonImageResource()
|
||||
.observe(
|
||||
this,
|
||||
res -> binding.toggleTorch.setImageDrawable(ContextCompat.getDrawable(this, res)));
|
||||
viewModel.isTorchEnabled()
|
||||
.observe(
|
||||
this,
|
||||
enabled -> camera.getCameraControl().enableTorch(enabled));
|
||||
|
||||
binding.toggleTorch.setOnClickListener((v) -> viewModel.toggleTorchEnabled());
|
||||
binding.switchCamera.setOnClickListener((v) -> {
|
||||
viewModel.toggleCameraSelector();
|
||||
cameraProvider.unbindAll();
|
||||
cameraProvider.bindToLifecycle(this, viewModel.getCameraSelector(), imageCapture, preview);
|
||||
cameraProvider.bindToLifecycle(
|
||||
this,
|
||||
viewModel.getCameraSelector(),
|
||||
imageCapture,
|
||||
preview);
|
||||
});
|
||||
} catch (IllegalArgumentException | ExecutionException | InterruptedException e) {
|
||||
Log.e(TAG, "Error taking picture", e);
|
||||
@ -130,12 +148,17 @@ public class TakePhotoActivity extends AppCompatActivity {
|
||||
final String photoFileName = dateFormat.format(new Date())+ ".jpg";
|
||||
try {
|
||||
final File photoFile = FileUtils.getTempCacheFile(this, "photos/" + photoFileName);
|
||||
final ImageCapture.OutputFileOptions options = new ImageCapture.OutputFileOptions.Builder(photoFile).build();
|
||||
imageCapture.takePicture(options, ContextCompat.getMainExecutor(this), new ImageCapture.OnImageSavedCallback() {
|
||||
final ImageCapture.OutputFileOptions options =
|
||||
new ImageCapture.OutputFileOptions.Builder(photoFile).build();
|
||||
imageCapture.takePicture(
|
||||
options,
|
||||
ContextCompat.getMainExecutor(this),
|
||||
new ImageCapture.OnImageSavedCallback() {
|
||||
|
||||
@Override
|
||||
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
||||
final Uri savedUri = Uri.fromFile(photoFile);
|
||||
Log.i(TAG, "onImageSaved - savedUri:" + savedUri.toString());
|
||||
Log.i(TAG, "onImageSaved - savedUri:" + savedUri);
|
||||
setResult(RESULT_OK, new Intent().setDataAndType(savedUri, "image/jpeg"));
|
||||
finish();
|
||||
}
|
||||
@ -143,14 +166,15 @@ public class TakePhotoActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onError(@NonNull ImageCaptureException e) {
|
||||
Log.e(TAG, "Error", e);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
photoFile.delete();
|
||||
|
||||
if(!photoFile.delete()) {
|
||||
Log.w(TAG, "Deleting picture failed");
|
||||
}
|
||||
binding.takePhoto.setEnabled(true);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// TODO replace string with placeholder
|
||||
Toast.makeText(this, "Error taking picture", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, R.string.take_photo_error_deleting_picture, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -39,7 +39,8 @@ public class TakePictureViewModel extends ViewModel {
|
||||
@NonNull
|
||||
private CameraSelector cameraSelector = DEFAULT_BACK_CAMERA;
|
||||
@NonNull
|
||||
private final MutableLiveData<Integer> cameraSelectorToggleButtonImageResource = new MutableLiveData<>(R.drawable.ic_baseline_camera_front_24);
|
||||
private final MutableLiveData<Integer> cameraSelectorToggleButtonImageResource =
|
||||
new MutableLiveData<>(R.drawable.ic_baseline_camera_front_24);
|
||||
@NonNull
|
||||
private final MutableLiveData<Boolean> torchEnabled = new MutableLiveData<>(false);
|
||||
|
||||
@ -77,4 +78,3 @@ public class TakePictureViewModel extends ViewModel {
|
||||
: R.drawable.ic_baseline_flash_on_24);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ import autodagger.AutoInjector;
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class MagicPeerConnectionWrapper {
|
||||
private static String TAG = "MagicPeerConnectionWrapper";
|
||||
private static final String TAG = "MagicPeerConWrapper";
|
||||
|
||||
private List<IceCandidate> iceCandidates = new ArrayList<>();
|
||||
private PeerConnection peerConnection;
|
||||
@ -129,7 +129,6 @@ public class MagicPeerConnectionWrapper {
|
||||
EventBus.getDefault().post(new WebSocketCommunicationEvent("peerReadyForRequestingOffer", hashMap));
|
||||
} else if (!hasMCU && hasInitiated) {
|
||||
peerConnection.createOffer(magicSdpObserver, sdpConstraints);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,7 +177,6 @@ public class MagicPeerConnectionWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sendNickChannelData(DataChannelMessageNick dataChannelMessage) {
|
||||
ByteBuffer buffer;
|
||||
if (magicDataChannel != null) {
|
||||
@ -186,7 +184,7 @@ public class MagicPeerConnectionWrapper {
|
||||
buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes());
|
||||
magicDataChannel.send(new DataChannel.Buffer(buffer, false));
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Failed to send channel data, attempting regular " + dataChannelMessage.toString());
|
||||
Log.d(TAG, "Failed to send channel data, attempting regular " + dataChannelMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,7 +196,7 @@ public class MagicPeerConnectionWrapper {
|
||||
buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes());
|
||||
magicDataChannel.send(new DataChannel.Buffer(buffer, false));
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Failed to send channel data, attempting regular " + dataChannelMessage.toString());
|
||||
Log.d(TAG, "Failed to send channel data, attempting regular " + dataChannelMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -477,4 +477,5 @@
|
||||
<string name="take_photo">Take a photo</string>
|
||||
<string name="take_photo_switch_camera">Switch camera</string>
|
||||
<string name="take_photo_toggle_torch">Toggle torch</string>
|
||||
<string name="take_photo_error_deleting_picture">Error taking picture</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user