修改规约后清除相关的配置文件

serial
Matthew 1 year ago
parent c37e43d6a7
commit 8c4f7faee1

@ -248,10 +248,45 @@ public class MainActivity extends AppCompatActivity {
this.binding.btnSaveCfg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
public void onClick(final View view) {
MicroPhotoContext.AppConfig appCfg = MicroPhotoContext.getMpAppConfig(getApplicationContext());
String protocolStr = MainActivity.this.binding.protocol.getSelectedItem().toString();
int protocol = MicroPhotoContext.DEFAULT_PROTOCOL;
String[] parts = protocolStr.split("-");
if (parts != null) {
protocol = Integer.parseInt(parts[0]);
}
if (appCfg.protocol != protocol) {
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setTitle(R.string.confirm_change_protocol);
builder.setMessage(R.string.confirm_change_protocol_text);
builder.setCancelable(true);
builder.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
retrieveAndSaveAppConfig();
MicroPhotoContext.removeMpConfigFiles(getApplicationContext());
MicroPhotoService.updateConfigs(MainActivity.this.getApplicationContext());
}
});
builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
} else {
retrieveAndSaveAppConfig();
MicroPhotoService.updateConfigs(MainActivity.this.getApplicationContext());
}
retrieveAndSaveAppConfig();
MicroPhotoService.updateConfigs(MainActivity.this.getApplicationContext());
}
});

@ -13,6 +13,9 @@
<string name="confirm_reboot">重启设备</string>
<string name="text_confirm_reboot">确认重启设备吗?</string>
<string name="confirm_change_protocol">修改规约</string>
<string name="confirm_change_protocol_text">修改规约后,图像参数、采样参数、拍照时间表、短视频参数将被清除,确认要修改吗?</string>
<string name="activity_channel_title">通道设置</string>
<string name="osd_left_top">左上 OSD</string>

@ -39,4 +39,21 @@ public class FileUtils {
return true;
}
public static boolean DeleteFilesInPath(String path) {
File pathFile = new File(path);
if (!pathFile.exists() || !pathFile.isDirectory()) {
return false;
}
for (File f : pathFile.listFiles()) {
if (!f.isFile()) {
continue;
}
f.delete();
}
return true;
}
}

@ -140,6 +140,30 @@ public class MicroPhotoContext {
return path;
}
public static void removeMpConfigFiles(Context context) {
String appPath = buildMpAppDir(context);
File path = new File(appPath + "data/imgparams/");
if (path.exists() && path.isDirectory()) {
FileUtils.DeleteFilesInPath(path.getAbsolutePath());
}
path = new File(appPath + "data/schedules/");
if (path.exists() && path.isDirectory()) {
FileUtils.DeleteFilesInPath(path.getAbsolutePath());
}
path = new File(appPath + "data/videoparams/");
if (path.exists() && path.isDirectory()) {
FileUtils.DeleteFilesInPath(path.getAbsolutePath());
}
path = new File(appPath + "data/sampling");
if (path.exists() && path.isFile()) {
path.delete();
}
}
public static String buildMpAppDir(Context contxt) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath();

Loading…
Cancel
Save