[DebugView]添加切换环境入口
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.zhjt.mogo_core_function_devatools.env
|
||||
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import android.os.Process
|
||||
import com.mogo.commons.constants.*
|
||||
import com.mogo.commons.debug.*
|
||||
import com.mogo.eagle.core.function.call.map.*
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.*
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
|
||||
|
||||
object EnvChangeManager {
|
||||
|
||||
private val sp = Utils.getApp().getSharedPreferences("env_change", MODE_PRIVATE)
|
||||
|
||||
private fun updateCityCode(cityCode: String?) {
|
||||
sp.edit().putString("city_code", cityCode).commit()
|
||||
}
|
||||
|
||||
private fun updateNetMode(netMode: Int) {
|
||||
sp.edit().putInt("net_mode", netMode).commit()
|
||||
}
|
||||
|
||||
private fun getConfig() : Pair<String, Int>? {
|
||||
val cityCode = sp.getString("city_code", null)
|
||||
val severType = sp.getInt("net_mode", -1)
|
||||
if (cityCode == null || severType == -1) {
|
||||
return null
|
||||
}
|
||||
return Pair(cityCode, severType)
|
||||
}
|
||||
|
||||
fun getCityName(): String {
|
||||
val cache = getConfig()
|
||||
return if (cache == null) {
|
||||
val cityCode = CallerMapLocationListenerManager.getCurrentLocation()?.cityCode ?: SharedPrefsMgr.getInstance(Utils.getApp()).getString(SharedPrefsConstants.LOCATION_CITY_CODE) ?: "010"
|
||||
updateCityCode(cityCode)
|
||||
when(cityCode) {
|
||||
"010" -> "北京"
|
||||
"0734" -> "衡阳"
|
||||
else -> "未知"
|
||||
}
|
||||
} else {
|
||||
when(cache.first) {
|
||||
"010" -> "北京"
|
||||
"0734" -> "衡阳"
|
||||
else -> "未知"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getNetMode(): String {
|
||||
val cache = getConfig()
|
||||
if (cache == null) {
|
||||
val mode = DebugConfig.getNetMode()
|
||||
updateNetMode(mode)
|
||||
return when(mode) {
|
||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||
DebugConfig.NET_MODE_QA -> "测试"
|
||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
||||
else -> "未知"
|
||||
}
|
||||
} else {
|
||||
return when(cache.second) {
|
||||
DebugConfig.NET_MODE_RELEASE -> "生产"
|
||||
DebugConfig.NET_MODE_QA -> "测试"
|
||||
DebugConfig.NET_MODE_DEMO -> "演示"
|
||||
else -> "未知"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun changeTo(cityCode: String, netMode: Int) {
|
||||
updateCityCode(cityCode)
|
||||
updateNetMode(netMode)
|
||||
restartApp()
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
updateCityCode(null)
|
||||
updateNetMode(-1)
|
||||
restartApp()
|
||||
}
|
||||
|
||||
private fun restartApp() {
|
||||
Utils.getApp().startActivity(Utils.getApp().packageManager.getLaunchIntentForPackage(Utils.getApp().packageName))
|
||||
Process.killProcess(Process.myPid())
|
||||
}
|
||||
|
||||
fun getEnvConfig(): EnvConfig? = getConfig()?.let {
|
||||
EnvConfig(it.first, it.second,
|
||||
if (it.first == "010") 116.397446 else 112.582654,
|
||||
if (it.first == "010") 39.909004 else 26.816478)
|
||||
}
|
||||
|
||||
data class EnvConfig(val cityCode: String, val netMode: Int, val lat: Double, val lon: Double)
|
||||
}
|
||||
Reference in New Issue
Block a user