From 60d34c35eb9f49ddfa8ccdb1fbbf601c10df301d Mon Sep 17 00:00:00 2001 From: jiangdg Date: Tue, 30 Aug 2022 09:29:43 +0800 Subject: [PATCH] [fix] some copy error --- app/src/main/AndroidManifest.xml | 2 +- .../jiangdg/ausbc/base/MultiCameraActivity.kt | 22 +++++++------------ .../jiangdg/ausbc/camera/CameraUvcStrategy.kt | 16 +++++++------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 29d49576f..dbd63f6f7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,7 +8,7 @@ - + diff --git a/libausbc/src/main/java/com/jiangdg/ausbc/base/MultiCameraActivity.kt b/libausbc/src/main/java/com/jiangdg/ausbc/base/MultiCameraActivity.kt index af8572cdc..01d6322eb 100644 --- a/libausbc/src/main/java/com/jiangdg/ausbc/base/MultiCameraActivity.kt +++ b/libausbc/src/main/java/com/jiangdg/ausbc/base/MultiCameraActivity.kt @@ -29,20 +29,15 @@ abstract class MultiCameraActivity: BaseActivity() { private val mCameraMap = hashMapOf() override fun initData() { - mCameraClient = MultiCameraClient(requireContext(), object : IDeviceConnectCallBack { + mCameraClient = MultiCameraClient(this, object : IDeviceConnectCallBack { override fun onAttachDev(device: UsbDevice?) { device ?: return - context?.let { - if (mCameraMap.containsKey(device.deviceId)) { - return - } - MultiCameraClient.Camera(it, device).apply { - mCameraMap[device.deviceId] = this - onCameraAttached(this) - } - if (isAutoRequestPermission()) { - mCameraClient?.requestPermission(device) - } + MultiCameraClient.Camera(this@MultiCameraActivity, device).apply { + mCameraMap[device.deviceId] = this + onCameraAttached(this) + } + if (isAutoRequestPermission()) { + mCameraClient?.requestPermission(device) } } @@ -56,10 +51,9 @@ abstract class MultiCameraActivity: BaseActivity() { override fun onConnectDev(device: UsbDevice?, ctrlBlock: USBMonitor.UsbControlBlock?) { device ?: return ctrlBlock ?: return - context ?: return mCameraMap[device.deviceId]?.apply { setUsbControlBlock(ctrlBlock) - onCameraConnected(this) + onCameraDisConnected(this) } } diff --git a/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt b/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt index ba1616dd0..0772535aa 100644 --- a/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt +++ b/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt @@ -110,14 +110,8 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { override fun startPreviewInternal() { try { - createCamera() ?: return - realStartPreview() ?: return - val dev = mDevSettableFuture?.get().apply { - mDevConnectCallBack?.onConnectDev(this) - } - if (Utils.debugCamera) { - Logger.i(TAG, " start preview success!!!, id(${dev?.deviceId})$dev") - } + createCamera() + realStartPreview() } catch (e: Exception) { stopPreview() Logger.e(TAG, " preview failed, err = ${e.localizedMessage}", e) @@ -212,6 +206,12 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { ) ) } + val dev = mDevSettableFuture?.get().apply { + mDevConnectCallBack?.onConnectDev(this) + } + if (Utils.debugCamera) { + Logger.i(TAG, " start preview success!!!, id(${dev?.deviceId})$dev") + } } catch (e: Exception) { postCameraStatus(CameraStatus(CameraStatus.ERROR, e.localizedMessage)) Logger.e(TAG, " startPreview failed. err = ${e.localizedMessage}", e)