更新了配置界面Activity

This commit is contained in:
free will committed 2021-07-28 15:42:30 +08:00
1 parent ceffcef5e2
commit e3ad010e01
1 file changed
+43 -7
@@ -32,10 +32,16 @@ public class SettingActivity extends MINVpnBaseActivity<SettingActivityPresenter
// 界面变量区
private EasyBar easyBar;
private CircularProgressButton btnSaveSetting;
// 第一跳路由
private ClearAbleEditText etIpAddress;
private ClearAbleEditText etPort;
private ClearAbleEditText etFirstRouterPrefix;
// VPN Server
private ClearAbleEditText etServicePrefix;
// VMS
private ClearAbleEditText etBlockChainIp;
private ClearAbleEditText etVMSTCPPort;
private ClearAbleEditText etVMSSSLPort;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -44,10 +50,16 @@ public class SettingActivity extends MINVpnBaseActivity<SettingActivityPresenter
// 初始化组件变量
easyBar=findViewById(R.id.easyBar);
btnSaveSetting=findViewById(R.id.btnSaveSetting);
// 第一跳路由
etIpAddress=findViewById(R.id.etIpAddress);
etPort=findViewById(R.id.etPort);
etFirstRouterPrefix=findViewById(R.id.etFirstRouterPrefix);
// VPN Server
etServicePrefix=findViewById(R.id.etServicePrefix);
// VMS
etBlockChainIp=findViewById(R.id.etBlockChainIp);
etVMSTCPPort=findViewById(R.id.etVMSTCPPort);
etVMSSSLPort=findViewById(R.id.etVMSSSLPort);
initView();
}
@@ -73,8 +85,11 @@ public class SettingActivity extends MINVpnBaseActivity<SettingActivityPresenter
// 获取本地设置数据,填充到文本框
etIpAddress.setText(MINVpnSettingAPI.INSTANCE.getMirIpAddress());
etPort.setText(String.valueOf(MINVpnSettingAPI.INSTANCE.getMirPort()));
etFirstRouterPrefix.setText(MINVpnSettingAPI.INSTANCE.getFirstRouterPrefix());
etServicePrefix.setText(MINVpnSettingAPI.INSTANCE.getServicePrefix());
etBlockChainIp.setText(MINVpnSettingAPI.INSTANCE.getBlockChainIpAddress());
etVMSTCPPort.setText(String.valueOf(MINVpnSettingAPI.INSTANCE.getBcTcpPort()));
etVMSSSLPort.setText(String.valueOf(MINVpnSettingAPI.INSTANCE.getBcSslPort()));
// 设置按钮的监听(点击动作)
btnSaveSetting.setOnClickListener(v->{
@@ -86,31 +101,52 @@ public class SettingActivity extends MINVpnBaseActivity<SettingActivityPresenter
btnSaveSetting.revertAnimation();
return;
}
String mirPort= Objects.requireNonNull(etPort.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isPort(mirPort)){
showWarning("请输入有效的接入端口号");
btnSaveSetting.revertAnimation();
return;
}
String firstPrefix= Objects.requireNonNull(etFirstRouterPrefix.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isndnPrefix(firstPrefix)){
showWarning("请输入有效的MIN接入服务前缀");
btnSaveSetting.revertAnimation();
return;
}
String servicePrefix= Objects.requireNonNull(etServicePrefix.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isndnPrefix(servicePrefix)){
showWarning("请输入有效的VPN服务前缀");
btnSaveSetting.revertAnimation();
return;
}
String blockChainIpAddress = Objects.requireNonNull(etBlockChainIp.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isIPAddr(blockChainIpAddress)){
showWarning("请输入有效的区块链IP地址");
btnSaveSetting.revertAnimation();
return;
}
String servicePrefix= Objects.requireNonNull(etServicePrefix.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isndnPrefix(servicePrefix)){
showWarning("请输入有效的服务前缀");
String tcpPort= Objects.requireNonNull(etVMSTCPPort.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isPort(tcpPort)){
showWarning("请输入有效的VMS-TCP端口号");
btnSaveSetting.revertAnimation();
return;
}
String mirPort= Objects.requireNonNull(etPort.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isPort(mirPort)){
showWarning("请输入有效的端口号");
String sslPort= Objects.requireNonNull(etVMSSSLPort.getText()).toString();
if(!AccountValidatorRegexUtil.INSTANCE.isPort(sslPort)){
showWarning("请输入有效的VMS-SSL端口号");
btnSaveSetting.revertAnimation();
return;
}
boolean isEncrypted=true;
// 将属性字段更新到MINVpnAPI
MINVpnSettingAPI.INSTANCE.updateBlockChainIpAddress(blockChainIpAddress);
MINVpnSettingAPI.INSTANCE.updateMirIpAddress(mirIpAddress);
MINVpnSettingAPI.INSTANCE.updateMirPort(Integer.parseInt(mirPort));
MINVpnSettingAPI.INSTANCE.updateFirstRouterPrefix(firstPrefix);
MINVpnSettingAPI.INSTANCE.updateServicePrefix(servicePrefix);
MINVpnSettingAPI.INSTANCE.updateBlockChainIpAddress(blockChainIpAddress);
MINVpnSettingAPI.INSTANCE.updateBcTcpPort(Integer.parseInt(tcpPort));
MINVpnSettingAPI.INSTANCE.updateBcSslPort(Integer.parseInt(sslPort));
MINVpnSettingAPI.INSTANCE.updateEncryptedConfig(isEncrypted);
System.out.println(MINVpnSettingAPI.INSTANCE);