Skip to content

Commit 45a38cc

Browse files
committed
merged refactor branch
1 parent 252f91d commit 45a38cc

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

app/src/main/java/com/fpvout/digiview/MainActivity.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import androidx.appcompat.app.AppCompatActivity;
3737
import androidx.core.view.WindowInsetsCompat;
3838
import androidx.core.view.WindowInsetsControllerCompat;
39-
import androidx.preference.PreferenceManager;
40-
4139
import androidx.core.app.ActivityCompat;
4240
import io.sentry.SentryLevel;
4341
import io.sentry.android.core.SentryAndroid;
@@ -67,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements UsbDeviceListener
6765
VideoReaderExoplayer mVideoReader;
6866
boolean usbConnected = false;
6967
SurfaceView fpvView;
70-
DVR recorder;
68+
DVR dvr;
7169
private GestureDetector gestureDetector;
7270
private ScaleGestureDetector scaleGestureDetector;
7371
private SharedPreferences sharedPreferences;
@@ -90,11 +88,11 @@ protected void onCreate(Bundle savedInstanceState) {
9088

9189
recordButton = findViewById(R.id.recordbt);
9290
recordButton.setOnClickListener(view -> {
93-
if (recorder != null) {
94-
if (recorder.isRecording()) {
95-
recorder.stop();
91+
if (dvr != null) {
92+
if (dvr.isRecording()) {
93+
dvr.stop();
9694
} else {
97-
recorder.start();
95+
dvr.start();
9896
}
9997
} else {
10098
Toast.makeText(this, this.getText(R.string.no_dvr_video), Toast.LENGTH_LONG).show();
@@ -135,7 +133,6 @@ protected void onCreate(Bundle savedInstanceState) {
135133
mVideoReader.setVideoWaitingEventListener(() -> showOverlay(R.string.waiting_for_video, OverlayStatus.Connected));
136134

137135
mUsbMaskConnection = new UsbMaskConnection();
138-
139136
if (!usbConnected) {
140137
usbDevice = UsbMaskConnection.searchDevice(usbManager, getApplicationContext());
141138
if (usbDevice != null) {
@@ -307,13 +304,13 @@ public void usbDeviceDetached() {
307304
private void connect() {
308305
usbConnected = true;
309306
// Init DVR recorder
310-
recorder = DVR .getInstance(this, true);
307+
dvr = DVR.getInstance(this, true);
311308
try {
312-
recorder.init(mVideoReader);
309+
dvr.init(mVideoReader);
313310
} catch (IOException e) {
314311
e.printStackTrace();
315312
}
316-
mUsbMaskConnection.setUsbDevice(usbManager, usbDevice, recorder);
313+
mUsbMaskConnection.setUsbDevice(usbManager, usbDevice, dvr);
317314
mVideoReader.setUsbMaskConnection(mUsbMaskConnection);
318315
overlayView.hide();
319316
mVideoReader.start();
@@ -334,7 +331,8 @@ public void onResume() {
334331
updateVideoZoom();
335332

336333
if(checkStoragePermission()) {
337-
if (searchDevice()) {
334+
usbDevice = UsbMaskConnection.searchDevice(usbManager, getApplicationContext());
335+
if (usbDevice != null) {
338336
connect();
339337
} else {
340338
showOverlay(R.string.waiting_for_usb_device, OverlayStatus.Connected);

app/src/main/java/com/fpvout/digiview/UsbMaskConnection.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public class UsbMaskConnection {
2727
AndroidUSBInputStream mInputStream;
2828
AndroidUSBOutputStream mOutputStream;
2929
private boolean ready = false;
30+
private DVR dvr;
3031

3132
public UsbMaskConnection() {
33+
3234
}
3335

3436
public static UsbDevice searchDevice(UsbManager usbManager, Context c) {
@@ -76,14 +78,15 @@ public boolean isReady() {
7678
return ready;
7779
}
7880

79-
public void setUsbDevice(UsbManager usbManager, UsbDevice d) {
81+
public void setUsbDevice(UsbManager usbManager, UsbDevice d, DVR _dvr) {
82+
dvr = _dvr;
8083
usbConnection = usbManager.openDevice(d);
8184
usbInterface = d.getInterface(3);
8285

8386
usbConnection.claimInterface(usbInterface, true);
8487

8588
mOutputStream = new AndroidUSBOutputStream(usbInterface.getEndpoint(0), usbConnection);
86-
mInputStream = new AndroidUSBInputStream(usbInterface.getEndpoint(1), usbInterface.getEndpoint(0), usbConnection);
89+
mInputStream = new AndroidUSBInputStream(usbInterface.getEndpoint(1), usbInterface.getEndpoint(0), usbConnection, dvr);
8790
ready = true;
8891
}
8992
}

0 commit comments

Comments
 (0)