Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03eeeb9b62 | ||
|
|
038daf5fda | ||
|
|
bfd1387d9b | ||
|
|
5afec5cf25 | ||
|
|
ec29bdf5bf |
@@ -1,12 +1,13 @@
|
||||
# v2rayNG
|
||||
|
||||
A V2Ray client for Android
|
||||
A V2Ray client for Android, support [Xray core](https://github.com/XTLS/Xray-core) and [v2fly core](https://github.com/v2fly/v2ray-core)
|
||||
|
||||
[](https://developer.android.com/about/versions/jelly-bean#android-4.2)
|
||||
[](https://kotlinlang.org)
|
||||
[](https://github.com/2dust/v2rayNG/commits/master)
|
||||
[](https://www.codefactor.io/repository/github/2dust/v2rayng)
|
||||
[](https://github.com/2dust/v2rayNG/releases)
|
||||
[](https://t.me/v2rayn)
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=com.v2ray.ang">
|
||||
<img alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png" width="165" height="64" />
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.text.Editable
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.gson.Gson
|
||||
@@ -70,45 +69,32 @@ class Server2Activity : BaseActivity() {
|
||||
* save server config
|
||||
*/
|
||||
fun saveServer(): Boolean {
|
||||
var saveSuccess: Boolean
|
||||
val vmess = configs.vmess[edit_index]
|
||||
|
||||
vmess.remarks = et_remarks.text.toString()
|
||||
|
||||
if (TextUtils.isEmpty(vmess.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 {
|
||||
Gson().fromJson<Object>(tv_content.text.toString(), Object::class.java)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toast(R.string.toast_malformed_josn)
|
||||
saveSuccess = false
|
||||
return false
|
||||
}
|
||||
|
||||
if (saveSuccess) {
|
||||
if (AngConfigManager.addCustomServer(vmess, edit_index) == 0) {
|
||||
//update config
|
||||
defaultDPreference.setPrefString(AppConfig.ANG_CONFIG + edit_guid, tv_content.text.toString())
|
||||
if (edit_index == configs.index) {
|
||||
if (!AngConfigManager.genStoreV2rayConfig(edit_index)) {
|
||||
Log.d(AppConfig.ANG_PACKAGE, "update custom config $edit_index but generate full configuration failed!")
|
||||
}
|
||||
}
|
||||
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||
toast(R.string.toast_success)
|
||||
finish()
|
||||
return true
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ class Server3Activity : BaseActivity() {
|
||||
}
|
||||
|
||||
if (AngConfigManager.addShadowsocksServer(vmess, edit_index) == 0) {
|
||||
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||
toast(R.string.toast_success)
|
||||
finish()
|
||||
return true
|
||||
|
||||
@@ -96,6 +96,7 @@ class Server4Activity : BaseActivity() {
|
||||
}
|
||||
|
||||
if (AngConfigManager.addSocksServer(vmess, edit_index) == 0) {
|
||||
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||
toast(R.string.toast_success)
|
||||
finish()
|
||||
return true
|
||||
|
||||
@@ -155,6 +155,7 @@ class ServerActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
if (AngConfigManager.addServer(vmess, edit_index) == 0) {
|
||||
AngConfigManager.genStoreV2rayConfigIfActive(edit_index)
|
||||
toast(R.string.toast_success)
|
||||
finish()
|
||||
return true
|
||||
|
||||
@@ -155,7 +155,7 @@ object AngConfigManager {
|
||||
angConfig.index = index
|
||||
app.curIndex = index
|
||||
storeConfigFile()
|
||||
if (!genStoreV2rayConfig(index)) {
|
||||
if (!genStoreV2rayConfig()) {
|
||||
Log.d(AppConfig.ANG_PACKAGE, "set active index $index but generate full configuration failed!")
|
||||
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
|
||||
*/
|
||||
fun genStoreV2rayConfig(index: Int): Boolean {
|
||||
fun genStoreV2rayConfig(): Boolean {
|
||||
try {
|
||||
if (angConfig.index < 0
|
||||
|| angConfig.vmess.count() <= 0
|
||||
|| 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) {
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG, result.content)
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_GUID, currConfigGuid())
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_NAME, currConfigName())
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
angConfig.vmess.getOrNull(angConfig.index)?.let {
|
||||
val result = V2rayConfigUtil.getV2rayConfig(app, it)
|
||||
if (result.status) {
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG, result.content)
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_GUID, currConfigGuid())
|
||||
app.defaultDPreference.setPrefString(PREF_CURR_CONFIG_NAME, currConfigName())
|
||||
return true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun currGeneratedV2rayConfig(): String {
|
||||
|
||||
@@ -36,7 +36,7 @@ class SettingsViewModel(application: Application) : AndroidViewModel(application
|
||||
AppConfig.PREF_V2RAY_ROUTING_BLOCKED,
|
||||
AppConfig.PREF_V2RAY_ROUTING_DIRECT -> {
|
||||
GlobalScope.launch {
|
||||
if (!AngConfigManager.genStoreV2rayConfig(AngConfigManager.configs.index)) {
|
||||
if (!AngConfigManager.genStoreV2rayConfig()) {
|
||||
Log.d(AppConfig.ANG_PACKAGE, "$key changed but generate full configuration failed!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user