Add mode in settings

This commit is contained in:
yuhan6665 committed 2020-09-04 18:19:51 -04:00
1 parent 9271857b1e
commit bebc6fea13
9 files changed
+30 -5

No files matched your search

@@ -13,6 +13,8 @@ object AppConfig {
const val PREF_CURR_CONFIG_DOMAIN = "pref_v2ray_config_domain"
const val PREF_CURR_CONFIG_OUTBOUND_TAGS = "pref_v2ray_config_outbound_tags"
const val PREF_INAPP_BUY_IS_PREMIUM = "pref_inapp_buy_is_premium"
const val PREF_MODE = "pref_mode"
const val VMESS_PROTOCOL: String = "vmess://"
const val SS_PROTOCOL: String = "ss://"
const val SOCKS_PROTOCOL: String = "socks://"
@@ -56,8 +56,12 @@ object V2RayServiceManager {
private var mSubscription: Subscription? = null
private var mNotificationManager: NotificationManager? = null
fun startV2Ray(context: Context) {
val intent = Intent(context.applicationContext, V2RayVpnService::class.java)
fun startV2Ray(context: Context, mode: String) {
val intent = if (mode == "VPN") {
Intent(context.applicationContext, V2RayVpnService::class.java)
} else {
Intent(context.applicationContext, V2RayProxyOnlyService::class.java)
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
context.startForegroundService(intent)
} else {
@@ -28,6 +28,7 @@ import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.widget.helper.ItemTouchHelper
import android.util.Log
import com.v2ray.ang.dto.EConfigType
import com.v2ray.ang.extension.defaultDPreference
//import com.v2ray.ang.InappBuyActivity
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
@@ -71,13 +72,15 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
fab.setOnClickListener {
if (isRunning) {
Utils.stopVService(this)
} else {
} else if (defaultDPreference.getPrefString(AppConfig.PREF_MODE, "VPN") == "VPN") {
val intent = VpnService.prepare(this)
if (intent == null) {
startV2Ray()
} else {
startActivityForResult(intent, REQUEST_CODE_VPN_PREPARE)
}
} else {
startV2Ray()
}
}
layout_test.setOnClickListener {
@@ -300,7 +300,7 @@ object Utils {
return false
}
}
V2RayServiceManager.startV2Ray(context)
V2RayServiceManager.startV2Ray(context, context.v2RayApplication.defaultDPreference.getPrefString(AppConfig.PREF_MODE, "VPN"))
return true
} else {
return false
@@ -123,6 +123,7 @@
<string name="title_pref_promotion">推广</string>
<string name="summary_pref_promotion">一些推广,点击查看详情(捐赠可去除)</string>
<string name="title_mode">模式</string>
<string name="title_pref_version">版本</string>
<string name="donate_error_setup">初始化错误:</string>
@@ -125,6 +125,7 @@
<string name="title_pref_promotion">推廣</string>
<string name="summary_pref_promotion">一些推廣,點擊查看詳情(捐款可去除)</string>
<string name="title_mode">模式</string>
<string name="title_pref_version">版本</string>
<string name="donate_error_setup">錯誤設定:</string>
@@ -67,6 +67,11 @@
<item>IPOnDemand</item>
</string-array>
<string-array name="mode_value" translatable="false">
<item>VPN</item>
<item>Proxy only</item>
</string-array>
<!-- minimum list https://serverfault.com/a/304791 -->
<string-array name="bypass_private_ip_address" translatable="false">
<item>0.0.0.0/5</item>
@@ -125,6 +125,7 @@
<string name="title_pref_promotion">Promotion</string>
<string name="summary_pref_promotion">Promotion,click for details(Donation can be removed)</string>
<string name="title_mode">Mode</string>
<string name="title_pref_version">Version</string>
<string name="donate_error_setup">Error Setup:</string>
@@ -85,6 +85,14 @@
android:key="pref_http_port"
android:summary="10809"
android:title="@string/title_pref_http_port" />
<ListPreference
android:defaultValue="VPN"
android:entries="@array/mode_value"
android:entryValues="@array/mode_value"
android:key="pref_mode"
android:summary="%s"
android:title="@string/title_mode" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_about">
@@ -110,4 +118,4 @@
android:key="pref_version"
android:title="@string/title_pref_version" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>