前言
在上一篇幅《Android实现动态切换环境配置3.0版本》基础上进行了以下调整:
1、静态各环境的列表实现,每个环境下包含的各服务器地址信息是放在一个list集合中,可通过配置JSON串进行调整。
2、手动输入URL的页面实现,以列表方式实现,并且每一项都可以进行信息的重新编辑,也可通过配置JSON串进行数据调整。
其它部分的功能保持不变。
先上图
具体实现部分并不复杂,不再进行详细表述。
apk 开发版安装包地址:https://download.csdn.net/download/Silence1515/37369892
apk 生产版安装包地址:https://download.csdn.net/download/Silence1515/37369909
项目工程地址:https://download.csdn.net/download/Silence1515/37369941
注意:
在没有对应的缓存数据的情况下,首次初始化环境配置时,默认使用的某个环境,可能会与UI列表显示的默认环境不一致,这是由于在没有缓存数据时,配置数据是根据打包环境的development来确认的。如果不同版本阶段的开发使用的默认环境不一样,可以在代码里进行调整来保证一致性,在EnvConfigHelper和ServerUrlConfigListFragment中调整,具体查看其中的注释说明。
json 示例
EnvConfigWrapper的json示例:
{
"allServerUrlDetails": {
"mServerUrlConfigList": [
{
"isChecked": false,
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/product/"
}
},
{
"isChecked": false,
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/image"
}
},
{
"isChecked": false,
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/h5"
}
}
],
"modeOfEnv": "devPilotRun",
"configId": "dev_pilot_run_server_url_details",
"groupId": "server_url_details",
"isChecked": true,
"isGroup": true,
"isRequired": true,
"labelName": "开发试运行环境",
"viewType": 1
},
"switchConfigMap": {
"skip_login": {
"configId": "skip_login",
"groupId": "skip_login",
"isChecked": false,
"isGroup": false,
"isRequired": false,
"labelName": "是否跳过登录(选中代表是)",
"viewType": 2
},
"ignore_service_1": {
"configId": "ignore_service_1",
"groupId": "ignore_service_1",
"isChecked": false,
"isGroup": false,
"isRequired": false,
"labelName": "是否忽略验证业务一(选中代表是)",
"viewType": 2
},
"skip_ad_page": {
"configId": "skip_ad_page",
"groupId": "skip_ad_page",
"isChecked": true,
"isGroup": false,
"isRequired": false,
"labelName": "是否跳过广告页(选中代表是)",
"viewType": 2
},
"force_service_1": {
"configId": "force_service_1",
"groupId": "force_service_1",
"isChecked": false,
"isGroup": false,
"isRequired": false,
"labelName": "是否强制验证业务一(选中代表是)",
"viewType": 2
},
"use_mock_user": {
"configId": "use_mock_user",
"groupId": "use_mock_user",
"isChecked": false,
"isGroup": false,
"isRequired": false,
"labelName": "是否启动Mock用户(选中代表是)",
"viewType": 2
},
"start_service_1": {
"configId": "start_service_1",
"groupId": "start_service_1",
"isChecked": true,
"isGroup": false,
"isRequired": false,
"labelName": "是否开启使用业务一(选中代表是)",
"viewType": 2
},
"disable_service_1": {
"configId": "disable_service_1",
"groupId": "disable_service_1",
"isChecked": true,
"isGroup": false,
"isRequired": false,
"labelName": "是否关闭业务一(选中代表是)",
"viewType": 2
}
},
"urlConfigDetailsInputSelectedMap": {
"image": {
"isChecked": true,
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "input",
"urlStr": "https://developer.android.google.cn/guide/"
}
}
}
}
静态环境配置的json示例:
[
{
"configId": "dev_test_server_1_url_details",
"groupId": "server_url_details",
"modeOfEnv": "devTestServer_1",
"labelName": "开发测试环境_1(测试服务器)",
"isChecked": true,
"isRequired": true,
"isGroup": true,
"viewType": 1,
"mServerUrlConfigList": [
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.10:8080/testserver_1/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.11:8080/testserver_1/image"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.12:8080/testserver_1/h5"
},
"isChecked": false
}
]
},
{
"configId": "dev_test_server_2_url_details",
"groupId": "server_url_details",
"labelName": "开发测试环境_2(测试服务器)",
"modeOfEnv": "devTestServer_2",
"isChecked": false,
"isRequired": true,
"isGroup": true,
"viewType": 1,
"mServerUrlConfigList": [
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.20:8080/testserver_2/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.21:8080/testserver_2/image"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.22:8080/testserver_2/h5"
},
"isChecked": false
}
]
},
{
"configId": "dev_test_local_server_url_details",
"groupId": "server_url_details",
"labelName": "开发本地测试环境(本地地址)",
"modeOfEnv": "devTestLocal",
"isChecked": false,
"isRequired": true,
"isGroup": true,
"viewType": 1,
"mServerUrlConfigList": [
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.30:8080/test_local/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.31:8080/test_local/image"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://192.168.10.32:8080/test_local/h5"
},
"isChecked": false
}
]
},
{
"configId": "dev_pilot_run_server_url_details",
"groupId": "server_url_details",
"labelName": "开发试运行环境",
"modeOfEnv": "devPilotRun",
"isChecked": false,
"isRequired": true,
"isGroup": true,
"viewType": 1,
"mServerUrlConfigList": [
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/product/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/image"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/h5"
},
"isChecked": false
}
]
},
{
"configId": "dev_product_server_url_details",
"groupId": "server_url_details",
"modeOfEnv": "devProduct",
"labelName": "开发生产环境",
"isChecked": false,
"isRequired": true,
"isGroup": true,
"viewType": 1,
"mServerUrlConfigList": [
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/product/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/image"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "default",
"urlStr": "http://blog.csdn.net/Silence1515/h5"
},
"isChecked": false
}
]
}
]
手输URL的json示例:
[
{
"typeId": "api",
"typeName": "api服务器地址",
"urlHistoryBean": {
"type": "input",
"urlStr": "https://www.baidu.com/"
},
"isChecked": false
},
{
"typeId": "image",
"typeName": "image服务器地址",
"urlHistoryBean": {
"type": "input",
"urlStr": "https://developer.android.google.cn/guide/"
},
"isChecked": false
},
{
"typeId": "h5",
"typeName": "h5服务器地址",
"urlHistoryBean": {
"type": "input",
"urlStr": "https://developer.android.google.cn/"
},
"isChecked": false
}
]
开关配置项的json示例:
[
{
"configId": "skip_login",
"groupId": "skip_login",
"labelName": "是否跳过登录(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "skip_ad_page",
"groupId": "skip_ad_page",
"labelName": "是否跳过广告页(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "use_mock_user",
"groupId": "use_mock_user",
"labelName": "是否启动Mock用户(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "ignore_service_1",
"groupId": "ignore_service_1",
"labelName": "是否忽略验证业务一(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "start_service_1",
"groupId": "start_service_1",
"labelName": "是否开启使用业务一(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "force_service_1",
"groupId": "force_service_1",
"labelName": "是否强制验证业务一(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
},
{
"configId": "disable_service_1",
"groupId": "disable_service_1",
"labelName": "是否关闭业务一(选中代表是)",
"isChecked": false,
"isRequired": false,
"isGroup": false,
"viewType": 2
}
]
手输URL历史记录的json示例:
[
{
"type": "default",
"urlStr": "https://blog.csdn.net/Silence1515/product/"
},
{
"type": "default",
"urlStr": "http://192.168.10.10:8080/testserver_1/"
},
{
"type": "default",
"urlStr": "http://192.168.10.30:8080/test_local/"
},
{
"type": "default",
"urlStr": "https://history.url.temp.dd.com.cn:998"
}
]
mocke用户的json示例:
[
{
"isChecked": "false",
"userInfo": {
"userId": 789097,
"username": "Cyra",
"token": "53j6456jj46re54j5235j425"
}
},
{
"isChecked": "false",
"userInfo": {
"userId": 4567865,
"username": "Mia",
"token": "0895f9f5dkvfdlvfldkfdkv"
}
}
]