Skip to content

Commit 47498cd

Browse files
committed
"Delete all files from device implemented and tested"
1 parent ab78f9a commit 47498cd

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,22 @@ private void handleWebSocketMsg(@NotNull WsMessageContext wsMessageContext){
407407

408408
break;
409409

410-
411410
case "STATUS" :
412411
String status = softwaresyncStatusTextView.getText().toString();
413412
Log.i(TAG,"handling the message in STATUS:" + status );
414413
wsMessageContext.send(status);
415414
break;
416415

416+
case "DELETE_ALL" :
417+
Log.i(TAG,"handling the message in DELETE_ALL" );
418+
deleteAllFiles();
419+
((SoftwareSyncLeader) softwareSyncController.softwareSync)
420+
.broadcastRpc(
421+
SoftwareSyncController.METHOD_EMPTY_DEVICE,
422+
"0");
423+
424+
break;
425+
417426
}
418427
}
419428

@@ -1109,6 +1118,32 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput,
11091118
// return isVideoRecording;
11101119
// }
11111120

1121+
public void deleteAllFiles() {
1122+
File sdcard = Environment.getExternalStorageDirectory();
1123+
String videoFilePath = sdcard.getAbsolutePath()+ "/RecSync/VID/";
1124+
String csvFilePath = sdcard.getAbsolutePath()+ "/RecSync/";
1125+
File path = new File(videoFilePath);
1126+
File fileList[] = path.listFiles();
1127+
Log.i(TAG,"Video File Path:"+videoFilePath );
1128+
Log.i(TAG,"No of files to delete: "+fileList.length );
1129+
String filename;
1130+
for(int i=0; i< fileList.length; i++){
1131+
filename = fileList[i].getName();
1132+
try{
1133+
Log.i(TAG,"inside deleteall" );
1134+
File vFile = new File(videoFilePath + filename);
1135+
vFile.delete();
1136+
Log.i(TAG,"csv_file_path : " + csvFilePath + filename.split("\\.")[0] + ".csv" );
1137+
File csvFile = new File(csvFilePath + filename.split("\\.")[0] + ".csv");
1138+
csvFile.delete();
1139+
}catch (Exception e){
1140+
e.printStackTrace();
1141+
}
1142+
1143+
}
1144+
}
1145+
1146+
11121147
public void sendFilesToServer(String payload){
11131148
try {
11141149

app/src/main/java/com/googleresearch/capturesync/SoftwareSyncController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class SoftwareSyncController implements Closeable {
6363
public static final int METHOD_START_RECORDING = 200_003;
6464
public static final int METHOD_STOP_RECORDING = 200_004;
6565
public static final int METHOD_UPLOAD_RECORDED_FILES = 200_005;
66+
public static final int METHOD_EMPTY_DEVICE = 200_006;
6667

6768
private long upcomingTriggerTimeNs;
6869

@@ -219,6 +220,14 @@ private void setupSoftwareSync() {
219220
);
220221
});
221222

223+
clientRpcs.put(
224+
METHOD_EMPTY_DEVICE,
225+
payload -> {
226+
Log.v(TAG, "Deleting All Recordings and Related Files");
227+
context.runOnUiThread(
228+
() -> context.deleteAllFiles()
229+
);
230+
});
222231

223232
clientRpcs.put(
224233
SyncConstants.METHOD_MSG_OFFSET_UPDATED,

remote_control/remote_control.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,29 @@ def stopBtn(self):
5252
def statusBtn(self):
5353
try:
5454
self.ws.send("STATUS")
55+
message = self.ws.recv()
56+
self.status_label.setPlainText(message)
5557
except Exception as e:
5658
self.show_popup()
57-
with open('last_prefix.txt','w+') as file:
58-
file.writelines(self.download_prefix_text.toPlainText())
59-
message = self.ws.recv()
60-
self.status_label.setPlainText(message)
59+
with open('last_prefix.txt','w+') as file:
60+
file.writelines(self.download_prefix_text.toPlainText())
61+
sys.exit()
62+
63+
def delete_all_btn(self):
64+
msgBox = QMessageBox()
65+
msgBox.setText("Are you sure you want to delete all the recordings and related files ?")
66+
msgBox.setInformativeText("This action cannot be reversed !!!")
67+
msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
68+
msgBox.setDefaultButton(QMessageBox.Cancel)
69+
ret = msgBox.exec()
70+
if ret == QMessageBox.Ok:
71+
try:
72+
self.ws.send("DELETE_ALL")
73+
except Exception as e:
74+
self.show_popup()
75+
with open('last_prefix.txt','w+') as file:
76+
file.writelines(self.download_prefix_text.toPlainText())
77+
sys.exit()
6178

6279
def clearStatusBtn(self):
6380
self.status_label.setPlainText("")
@@ -77,14 +94,11 @@ def isPrefix(self, prefix_text):
7794
return True
7895

7996
def setupUi(self, MainWindow):
80-
81-
#
8297
# Setup the WEB SOCKET
8398
self.ws = websocket.WebSocket()
84-
#self.ws.connect("ws://172.16.62.107:7867/remotecon")
99+
85100
self.ws.connect("ws://192.168.5.2:7867/remotecon", ping_interval=1)
86101

87-
#
88102
# Setup the GUI
89103
MainWindow.setObjectName("MainWindow")
90104
MainWindow.resize(800, 800)
@@ -130,6 +144,14 @@ def setupUi(self, MainWindow):
130144
self.download_btn.setFont(font)
131145
self.download_btn.setObjectName("pushButton_4")
132146
self.download_btn.clicked.connect(self.downloadBtn)
147+
148+
self.delete_btn = QtWidgets.QPushButton(self.centralwidget)
149+
self.delete_btn.setGeometry(QtCore.QRect(280, 520, 161, 50))
150+
self.delete_btn.setFont(font)
151+
self.delete_btn.setObjectName("pushButton_6")
152+
self.delete_btn.clicked.connect(self.delete_all_btn)
153+
154+
133155
self.status_label = QtWidgets.QPlainTextEdit(self.centralwidget)
134156
self.status_label.setGeometry(QtCore.QRect(173, 280, 381, 91))
135157
self.status_label.setObjectName("plainTextEdit")
@@ -159,6 +181,8 @@ def retranslateUi(self, MainWindow):
159181
self.status_btn.setText(_translate("MainWindow", "Status"))
160182
self.status_clear_btn.setText(_translate("MainWindow", "X"))
161183
self.status_clear_btn.setStyleSheet('QPushButton {;color: red;}')
184+
self.delete_btn.setText(_translate("MainWindow", "Empty Device"))
185+
self.delete_btn.setStyleSheet('QPushButton {;background-color: red;}')
162186
self.api_input.setPlaceholderText(_translate("MainWindow", "Please enter the api endpoint where you want the files to be uploaded."))
163187
self.download_prefix_text.setPlaceholderText(_translate("MainWindow", " Enter Session Prefix"))
164188
self.download_btn.setText(_translate("MainWindow", "Download"))

0 commit comments

Comments
 (0)