Skip to content

Commit 385126c

Browse files
move domain strategi and geo asset file to settings preference
1 parent 1dbfe15 commit 385126c

8 files changed

Lines changed: 38 additions & 156 deletions

File tree

V2rayNG/app/src/main/java/com/v2ray/ang/ui/RoutingSettingActivity.kt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.content.Intent
55
import android.os.Bundle
66
import android.view.Menu
77
import android.view.MenuItem
8-
import android.widget.ArrayAdapter
98
import androidx.activity.viewModels
109
import androidx.appcompat.app.AlertDialog
1110
import com.v2ray.ang.util.showBlur
@@ -38,13 +37,6 @@ class RoutingSettingActivity : HelperBaseActivity(), RoutingMenuBottomSheet.OnRo
3837
private val viewModel: RoutingSettingsViewModel by viewModels()
3938
private lateinit var adapter: RoutingSettingRecyclerAdapter
4039
private var mItemTouchHelper: ItemTouchHelper? = null
41-
42-
private val routing_domain_strategy: Array<out String> by lazy {
43-
resources.getStringArray(R.array.routing_domain_strategy)
44-
}
45-
private val preset_rulesets: Array<out String> by lazy {
46-
resources.getStringArray(R.array.preset_rulesets)
47-
}
4840

4941
override fun onCreate(savedInstanceState: Bundle?) {
5042
super.onCreate(savedInstanceState)
@@ -62,8 +54,6 @@ class RoutingSettingActivity : HelperBaseActivity(), RoutingMenuBottomSheet.OnRo
6254

6355
mItemTouchHelper = ItemTouchHelper(SimpleItemTouchHelperCallback(adapter))
6456
mItemTouchHelper?.attachToRecyclerView(binding.recyclerView)
65-
66-
setupDomainStrategyDropdown()
6757
}
6858

6959
override fun onResume() {
@@ -95,34 +85,8 @@ class RoutingSettingActivity : HelperBaseActivity(), RoutingMenuBottomSheet.OnRo
9585
}
9686
}
9787

98-
private fun getDomainStrategy(): String {
99-
return MmkvManager.decodeSettingsString(AppConfig.PREF_ROUTING_DOMAIN_STRATEGY) ?: routing_domain_strategy.first()
100-
}
101-
102-
private fun setupDomainStrategyDropdown() {
103-
val dropdownAdapter = ArrayAdapter(
104-
this,
105-
android.R.layout.simple_dropdown_item_1line,
106-
routing_domain_strategy
107-
)
108-
109-
binding.tvDomainStrategyDropdown.apply {
110-
setAdapter(dropdownAdapter)
111-
setText(getDomainStrategy(), false)
112-
113-
setOnItemClickListener { _, _, position, _ ->
114-
try {
115-
val value = routing_domain_strategy[position]
116-
MmkvManager.encodeSettings(AppConfig.PREF_ROUTING_DOMAIN_STRATEGY, value)
117-
} catch (e: Exception) {
118-
LogUtil.e(AppConfig.TAG, "Failed to set domain strategy", e)
119-
}
120-
}
121-
}
122-
}
123-
12488
private fun importPredefined() {
125-
AlertDialog.Builder(this).setItems(preset_rulesets.asList().toTypedArray()) { _, i ->
89+
AlertDialog.Builder(this).setItems(resources.getStringArray(R.array.preset_rulesets)) { _, i ->
12690
AlertDialog.Builder(this).setMessage(R.string.routing_settings_import_rulesets_tip)
12791
.setPositiveButton(android.R.string.ok) { _, _ ->
12892
try {

V2rayNG/app/src/main/java/com/v2ray/ang/ui/UserAssetActivity.kt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.os.Bundle
88
import android.provider.OpenableColumns
99
import android.view.Menu
1010
import android.view.MenuItem
11-
import android.widget.ArrayAdapter
1211
import androidx.activity.viewModels
1312
import androidx.lifecycle.lifecycleScope
1413
import androidx.recyclerview.widget.LinearLayoutManager
@@ -53,8 +52,6 @@ class UserAssetActivity : HelperBaseActivity(), AssetMenuBottomSheet.OnAssetMenu
5352
binding.recyclerView.layoutManager = LinearLayoutManager(this)
5453
adapter = UserAssetAdapter(viewModel, extDir, ActivityAdapterListener())
5554
binding.recyclerView.adapter = adapter
56-
57-
setupGeoFilesSourcesDropdown()
5855
}
5956

6057
override fun onResume() {
@@ -85,34 +82,6 @@ class UserAssetActivity : HelperBaseActivity(), AssetMenuBottomSheet.OnAssetMenu
8582
}
8683
}
8784

88-
private fun getGeoFilesSources(): String {
89-
return MmkvManager.decodeSettingsString(AppConfig.PREF_GEO_FILES_SOURCES) ?: AppConfig.GEO_FILES_SOURCES.first()
90-
}
91-
92-
private fun setupGeoFilesSourcesDropdown() {
93-
val dropdownAdapter = ArrayAdapter(
94-
this,
95-
android.R.layout.simple_dropdown_item_1line,
96-
AppConfig.GEO_FILES_SOURCES
97-
)
98-
99-
binding.tvGeoFilesSourcesDropdown.apply {
100-
setAdapter(dropdownAdapter)
101-
setText(getGeoFilesSources(), false)
102-
103-
setOnItemClickListener { _, _, position, _ ->
104-
try {
105-
val value = AppConfig.GEO_FILES_SOURCES[position]
106-
MmkvManager.encodeSettings(AppConfig.PREF_GEO_FILES_SOURCES, value)
107-
108-
refreshData()
109-
} catch (e: Exception) {
110-
LogUtil.e(AppConfig.TAG, "Failed to set geo files sources", e)
111-
}
112-
}
113-
}
114-
}
115-
11685
private fun showFileChooser() {
11786
launchFileChooser { uri ->
11887
if (uri == null) {
@@ -235,7 +204,8 @@ class UserAssetActivity : HelperBaseActivity(), AssetMenuBottomSheet.OnAssetMenu
235204

236205
@SuppressLint("NotifyDataSetChanged")
237206
fun refreshData() {
238-
viewModel.reload(getGeoFilesSources())
207+
val geoFilesSources = MmkvManager.decodeSettingsString(AppConfig.PREF_GEO_FILES_SOURCES) ?: AppConfig.GEO_FILES_SOURCES.first()
208+
viewModel.reload(geoFilesSources)
239209
adapter.notifyDataSetChanged()
240210
}
241211

V2rayNG/app/src/main/res/layout/activity_routing_setting.xml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,6 @@
5858
android:paddingTop="4.0dip"
5959
android:paddingBottom="@dimen/padding_spacing_dp16">
6060

61-
<com.google.android.material.card.MaterialCardView
62-
android:layout_width="match_parent"
63-
android:layout_height="wrap_content"
64-
android:layout_marginHorizontal="@dimen/padding_spacing_dp16"
65-
android:layout_marginBottom="4.0dip"
66-
app:cardBackgroundColor="?colorCard"
67-
app:cardCornerRadius="14.0dip"
68-
app:cardElevation="0.0dip"
69-
app:strokeWidth="0.0dip">
70-
71-
<LinearLayout
72-
android:layout_width="match_parent"
73-
android:layout_height="wrap_content"
74-
android:orientation="vertical"
75-
android:padding="@dimen/padding_spacing_dp16">
76-
77-
<com.google.android.material.textview.MaterialTextView
78-
android:layout_width="wrap_content"
79-
android:layout_height="wrap_content"
80-
android:layout_marginBottom="@dimen/padding_spacing_dp16"
81-
android:text="@string/routing_settings_domain_strategy"
82-
android:textColor="?attr/colorPrimary"
83-
android:textAppearance="?textAppearanceTitleMedium"
84-
android:textStyle="bold" />
85-
86-
<com.google.android.material.textfield.TextInputLayout
87-
android:id="@+id/layout_domain_strategy"
88-
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
89-
android:layout_width="match_parent"
90-
android:layout_height="wrap_content"
91-
android:hint="@string/routing_settings_domain_strategy">
92-
93-
<com.google.android.material.textfield.MaterialAutoCompleteTextView
94-
android:id="@+id/tv_domain_strategy_dropdown"
95-
android:layout_width="match_parent"
96-
android:layout_height="wrap_content"
97-
android:inputType="none" />
98-
99-
</com.google.android.material.textfield.TextInputLayout>
100-
101-
</LinearLayout>
102-
</com.google.android.material.card.MaterialCardView>
103-
10461
<androidx.recyclerview.widget.RecyclerView
10562
android:id="@+id/recycler_view"
10663
android:layout_width="match_parent"

V2rayNG/app/src/main/res/layout/activity_user_asset.xml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,6 @@
5858
android:paddingTop="4.0dip"
5959
android:paddingBottom="@dimen/padding_spacing_dp16">
6060

61-
<com.google.android.material.card.MaterialCardView
62-
android:layout_width="match_parent"
63-
android:layout_height="wrap_content"
64-
android:layout_marginHorizontal="@dimen/padding_spacing_dp16"
65-
android:layout_marginBottom="4.0dip"
66-
app:cardBackgroundColor="?colorCard"
67-
app:cardCornerRadius="14.0dip"
68-
app:cardElevation="0.0dip"
69-
app:strokeWidth="0.0dip">
70-
71-
<LinearLayout
72-
android:layout_width="match_parent"
73-
android:layout_height="wrap_content"
74-
android:orientation="vertical"
75-
android:padding="@dimen/padding_spacing_dp16">
76-
77-
<com.google.android.material.textview.MaterialTextView
78-
android:layout_width="wrap_content"
79-
android:layout_height="wrap_content"
80-
android:layout_marginBottom="@dimen/padding_spacing_dp16"
81-
android:text="@string/asset_geo_files_sources"
82-
android:textColor="?colorPrimary"
83-
android:textAppearance="?textAppearanceTitleMedium"
84-
android:textStyle="bold" />
85-
86-
<com.google.android.material.textfield.TextInputLayout
87-
android:id="@+id/layout_geo_files_sources"
88-
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
89-
android:layout_width="match_parent"
90-
android:layout_height="wrap_content"
91-
android:hint="@string/asset_geo_files_sources">
92-
93-
<com.google.android.material.textfield.MaterialAutoCompleteTextView
94-
android:id="@+id/tv_geo_files_sources_dropdown"
95-
android:layout_width="match_parent"
96-
android:layout_height="wrap_content"
97-
android:inputType="none" />
98-
99-
</com.google.android.material.textfield.TextInputLayout>
100-
101-
</LinearLayout>
102-
</com.google.android.material.card.MaterialCardView>
103-
10461
<androidx.recyclerview.widget.RecyclerView
10562
android:id="@+id/recycler_view"
10663
android:layout_width="match_parent"

V2rayNG/app/src/main/res/values-night/themes.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<item name="elevation">0.0dip</item>
2222
<item name="preferenceTheme">@style/AppThemePreference</item>
2323
<item name="android:homeAsUpIndicator">@drawable/uwu_back_arrow</item>
24+
<item name="textAppearanceTitleMedium">@style/TextAppearance.App.TitleMedium</item>
25+
<item name="textAppearanceTitleSmall">@style/TextAppearance.App.TitleSmall</item>
2426
</style>
2527

2628
</resources>

V2rayNG/app/src/main/res/values/arrays.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@
105105
<item>IPOnDemand</item>
106106
</string-array>
107107

108+
<string-array name="geo_files_sources_entries" translatable="false">
109+
<item>Loyalsoldier/v2ray-rules-dat</item>
110+
<item>runetfreedom/russia-v2ray-rules-dat</item>
111+
<item>Chocolate4U/Iran-v2ray-rules</item>
112+
</string-array>
113+
114+
<string-array name="geo_files_sources_values" translatable="false">
115+
<item>Loyalsoldier/v2ray-rules-dat</item>
116+
<item>runetfreedom/russia-v2ray-rules-dat</item>
117+
<item>Chocolate4U/Iran-v2ray-rules</item>
118+
</string-array>
119+
108120
<string-array name="core_loglevel" translatable="false">
109121
<item>debug</item>
110122
<item>info</item>

V2rayNG/app/src/main/res/xml/pref_advanced_settings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
android:summary="@string/summary_pref_ip_api_url"
5353
android:title="@string/title_pref_ip_api_url" />
5454

55+
<ListPreference
56+
android:icon="@drawable/ic_arrow_decision"
57+
app:layout="@layout/uwu_mid"
58+
android:defaultValue="AsIs"
59+
android:entries="@array/routing_domain_strategy"
60+
android:entryValues="@array/routing_domain_strategy"
61+
android:key="pref_routing_domain_strategy"
62+
android:summary="%s"
63+
android:title="@string/routing_settings_domain_strategy" />
64+
5565
<ListPreference
5666
android:icon="@drawable/ic_key"
5767
app:layout="@layout/uwu_bot"

V2rayNG/app/src/main/res/xml/pref_core_settings.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,24 @@
122122

123123
<ListPreference
124124
android:icon="@drawable/ic_domain"
125-
app:layout="@layout/uwu_bot"
125+
app:layout="@layout/uwu_mid"
126126
android:defaultValue="1"
127127
android:entries="@array/outbound_domain_resolve_method"
128128
android:entryValues="@array/outbound_domain_resolve_method_value"
129129
android:key="pref_outbound_domain_resolve_method"
130130
android:summary="%s"
131131
android:title="@string/title_outbound_domain_resolve_method" />
132132

133+
<ListPreference
134+
android:icon="@drawable/ic_cloud_download_24dp"
135+
app:layout="@layout/uwu_bot"
136+
android:defaultValue="Loyalsoldier/v2ray-rules-dat"
137+
android:entries="@array/geo_files_sources_entries"
138+
android:entryValues="@array/geo_files_sources_values"
139+
android:key="pref_geo_files_sources"
140+
android:summary="%s"
141+
android:title="@string/asset_geo_files_sources" />
142+
133143
</PreferenceCategory>
134144

135145
</PreferenceScreen>

0 commit comments

Comments
 (0)