From 631005e56598f42fe97c47f3f8d9fd14ecfbfa79 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 23 Oct 2019 22:43:10 -0700 Subject: [PATCH] CameraX cleanup. --- .../thoughtcrime/securesms/mediasend/CameraXFragment.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java b/src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java index 7465f545f4..7d63dae892 100644 --- a/src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java +++ b/src/org/thoughtcrime/securesms/mediasend/CameraXFragment.java @@ -101,7 +101,7 @@ public class CameraXFragment extends Fragment implements CameraFragment { this.camera = view.findViewById(R.id.camerax_camera); this.controlsContainer = view.findViewById(R.id.camerax_controls_container); - camera.bindToLifecycle(this); + camera.bindToLifecycle(getViewLifecycleOwner()); camera.setCameraLensFacing(CameraXUtil.toLensFacing(TextSecurePreferences.getDirectCaptureCameraId(requireContext()))); onOrientationChanged(getResources().getConfiguration().orientation); @@ -122,8 +122,6 @@ public class CameraXFragment extends Fragment implements CameraFragment { @Override public void onDestroyView() { super.onDestroyView(); - CameraX.unbindAll(); - closeVideoFileDescriptor(); } @@ -353,7 +351,7 @@ public class CameraXFragment extends Fragment implements CameraFragment { public void onCaptureSuccess(ImageProxy image, int rotationDegrees) { flashHelper.endFlash(); - SimpleTask.run(CameraXFragment.this.getLifecycle(), () -> { + SimpleTask.run(CameraXFragment.this.getViewLifecycleOwner().getLifecycle(), () -> { stopwatch.split("captured"); try { return CameraXUtil.toJpeg(image, rotationDegrees, camera.getCameraLensFacing() == CameraX.LensFacing.FRONT); @@ -388,6 +386,7 @@ public class CameraXFragment extends Fragment implements CameraFragment { if (videoFileDescriptor != null) { try { videoFileDescriptor.close(); + videoFileDescriptor = null; } catch (IOException e) { Log.w(TAG, "Failed to close video file descriptor", e); }