Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfd1387d9b | ||
|
|
5afec5cf25 | ||
|
|
ec29bdf5bf |
@@ -4,7 +4,6 @@ import android.os.Bundle
|
|||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
@@ -70,45 +69,32 @@ class Server2Activity : BaseActivity() {
|
|||||||
* save server config
|
* save server config
|
||||||
*/
|
*/
|
||||||
fun saveServer(): Boolean {
|
fun saveServer(): Boolean {
|
||||||
var saveSuccess: Boolean
|
|
||||||
val vmess = configs.vmess[edit_index]
|
val vmess = configs.vmess[edit_index]
|
||||||
|
|
||||||
vmess.remarks = et_remarks.text.toString()
|
vmess.remarks = et_remarks.text.toString()
|
||||||
|
|
||||||
if (TextUtils.isEmpty(vmess.remarks)) {
|
if (TextUtils.isEmpty(vmess.remarks)) {
|
||||||
toast(R.string.server_lab_remarks)
|
toast(R.string.server_lab_remarks)
|
||||||
saveSuccess = false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (AngConfigManager.addCustomServer(vmess, edit_index) == 0) {
|
|
||||||
toast(R.string.toast_success)
|
|
||||||
saveSuccess = true
|
|
||||||
} else {
|
|
||||||
toast(R.string.toast_failure)
|
|
||||||
saveSuccess = false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Gson().fromJson<Object>(tv_content.text.toString(), Object::class.java)
|
Gson().fromJson<Object>(tv_content.text.toString(), Object::class.java)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
toast(R.string.toast_malformed_josn)
|
toast(R.string.toast_malformed_josn)
|
||||||
saveSuccess = false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveSuccess) {
|
if (AngConfigManager.addCustomServer(vmess, edit_index) == 0) {
|
||||||
//update config
|
//update config
|
||||||
defaultDPreference.setPrefString(AppConfig.ANG_CONFIG + edit_guid, tv_content.text.toString())
|
defaultDPreference.setPrefString(AppConfig.ANG_CONFIG + edit_guid, tv_content.text.toString())
|
||||||
if (edit_index == configs.index) {
|
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||||
if (!AngConfigManager.genStoreV2rayConfig(edit_index)) {
|
toast(R.string.toast_success)
|
||||||
Log.d(AppConfig.ANG_PACKAGE, "update custom config $edit_index but generate full configuration failed!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finish()
|
finish()
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
toast(R.string.toast_failure)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class Server3Activity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AngConfigManager.addShadowsocksServer(vmess, edit_index) == 0) {
|
if (AngConfigManager.addShadowsocksServer(vmess, edit_index) == 0) {
|
||||||
|
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||||
toast(R.string.toast_success)
|
toast(R.string.toast_success)
|
||||||
finish()
|
finish()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class Server4Activity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AngConfigManager.addSocksServer(vmess, edit_index) == 0) {
|
if (AngConfigManager.addSocksServer(vmess, edit_index) == 0) {
|
||||||
|
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||||
toast(R.string.toast_success)
|
toast(R.string.toast_success)
|
||||||
finish()
|
finish()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ class ServerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AngConfigManager.addServer(vmess, edit_index) == 0) {
|
if (AngConfigManager.addServer(vmess, edit_index) == 0) {
|
||||||
|
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||||
toast(R.string.toast_success)
|
toast(R.string.toast_success)
|
||||||
finish()
|
finish()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ object AngConfigManager {
|
|||||||
angConfig.index = index
|
angConfig.index = index
|
||||||
app.curIndex = index
|
app.curIndex = index
|
||||||
storeConfigFile()
|
storeConfigFile()
|
||||||
if (!genStoreV2rayConfig(index)) {
|
if (!genStoreV2rayConfig()) {
|
||||||
Log.d(AppConfig.ANG_PACKAGE, "set active index $index but generate full configuration failed!")
|
Log.d(AppConfig.ANG_PACKAGE, "set active index $index but generate full configuration failed!")
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@@ -179,35 +179,32 @@ object AngConfigManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun genStoreV2rayConfigIfActive(index: Int) {
|
||||||
|
if (index == configs.index) {
|
||||||
|
if (!genStoreV2rayConfig()) {
|
||||||
|
Log.d(AppConfig.ANG_PACKAGE, "update config $index but generate full configuration failed!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gen and store v2ray config file
|
* gen and store v2ray config file
|
||||||
*/
|
*/
|
||||||
fun genStoreV2rayConfig(index: Int): Boolean {
|
fun genStoreV2rayConfig(): Boolean {
|
||||||
try {
|
try {
|
||||||
if (angConfig.index < 0
|
angConfig.vmess.getOrNull(angConfig.index)?.let {
|
||||||
|| angConfig.vmess.count() <= 0
|
val result = V2rayConfigUtil.getV2rayConfig(app, it)
|
||||||
|| angConfig.index > angConfig.vmess.count() - 1
|
|
||||||
) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
var index2 = angConfig.index
|
|
||||||
if (index >= 0) {
|
|
||||||
index2 = index
|
|
||||||
}
|
|
||||||
|
|
||||||
val result = V2rayConfigUtil.getV2rayConfig(app, angConfig.vmess[index2])
|
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG, result.content)
|
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG, result.content)
|
||||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_GUID, currConfigGuid())
|
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_GUID, currConfigGuid())
|
||||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_NAME, currConfigName())
|
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_NAME, currConfigName())
|
||||||
return true
|
return true
|
||||||
} else {
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun currGeneratedV2rayConfig(): String {
|
fun currGeneratedV2rayConfig(): String {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
|||||||
AppConfig.PREF_V2RAY_ROUTING_BLOCKED,
|
AppConfig.PREF_V2RAY_ROUTING_BLOCKED,
|
||||||
AppConfig.PREF_V2RAY_ROUTING_DIRECT -> {
|
AppConfig.PREF_V2RAY_ROUTING_DIRECT -> {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
if (!AngConfigManager.genStoreV2rayConfig(AngConfigManager.configs.index)) {
|
if (!AngConfigManager.genStoreV2rayConfig()) {
|
||||||
Log.d(AppConfig.ANG_PACKAGE, "$key changed but generate full configuration failed!")
|
Log.d(AppConfig.ANG_PACKAGE, "$key changed but generate full configuration failed!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user