mirror of
https://github.com/2dust/v2rayNG.git
synced 2025-06-28 20:29:51 +00:00
Optimize and improve PerAppProxyActivity
This commit is contained in:
parent
a60f45ce31
commit
14ff9eb527
3 changed files with 23 additions and 18 deletions
|
@ -5,11 +5,8 @@ import android.text.TextUtils
|
|||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.v2ray.ang.AppConfig
|
||||
import com.v2ray.ang.AppConfig.ANG_PACKAGE
|
||||
import com.v2ray.ang.R
|
||||
|
@ -18,6 +15,7 @@ import com.v2ray.ang.dto.AppInfo
|
|||
import com.v2ray.ang.extension.toast
|
||||
import com.v2ray.ang.extension.v2RayApplication
|
||||
import com.v2ray.ang.handler.MmkvManager
|
||||
import com.v2ray.ang.handler.SettingsManager
|
||||
import com.v2ray.ang.util.AppManagerUtil
|
||||
import com.v2ray.ang.util.HttpUtil
|
||||
import com.v2ray.ang.util.Utils
|
||||
|
@ -48,7 +46,7 @@ class PerAppProxyActivity : BaseActivity() {
|
|||
val blacklist = MmkvManager.decodeSettingsStringSet(AppConfig.PREF_PER_APP_PROXY_SET)
|
||||
val apps = withContext(Dispatchers.IO) {
|
||||
val appsList = AppManagerUtil.loadNetworkAppList(this@PerAppProxyActivity)
|
||||
|
||||
|
||||
if (blacklist != null) {
|
||||
appsList.forEach { app ->
|
||||
app.isSelected = if (blacklist.contains(app.packageName)) 1 else 0
|
||||
|
@ -152,13 +150,20 @@ class PerAppProxyActivity : BaseActivity() {
|
|||
|
||||
private fun selectProxyApp() {
|
||||
toast(R.string.msg_downloading_content)
|
||||
binding.pbWaiting.show()
|
||||
|
||||
val url = AppConfig.androidpackagenamelistUrl
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val content = HttpUtil.getUrlContent(url, 5000)
|
||||
var content = HttpUtil.getUrlContent(url, 5000)
|
||||
if (content.isNullOrEmpty()) {
|
||||
val httpPort = SettingsManager.getHttpPort()
|
||||
content = HttpUtil.getUrlContent(url, 5000, httpPort) ?: ""
|
||||
}
|
||||
launch(Dispatchers.Main) {
|
||||
Log.d(ANG_PACKAGE, content)
|
||||
selectProxyApp(content, true)
|
||||
toast(R.string.toast_success)
|
||||
binding.pbWaiting.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,18 +26,18 @@ object HttpUtil {
|
|||
*
|
||||
* @param url The URL to fetch content from.
|
||||
* @param timeout The timeout value in milliseconds.
|
||||
* @param httpPort The HTTP port to use.
|
||||
* @return The content of the URL as a string.
|
||||
*/
|
||||
fun getUrlContent(url: String, timeout: Int): String {
|
||||
var result: String = ""
|
||||
val conn = createProxyConnection(url, 0, timeout, timeout) ?: return result
|
||||
fun getUrlContent(url: String, timeout: Int, httpPort: Int = 0): String? {
|
||||
val conn = createProxyConnection(url, httpPort, timeout, timeout) ?: return null
|
||||
try {
|
||||
result = conn.inputStream.bufferedReader().readText()
|
||||
return conn.inputStream.bufferedReader().readText()
|
||||
} catch (_: Exception) {
|
||||
} finally {
|
||||
conn.disconnect()
|
||||
}
|
||||
return result
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/pb_waiting"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
android:visibility="invisible"
|
||||
app:indicatorColor="@color/color_fab_active" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header_view"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -71,14 +79,6 @@
|
|||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/pb_waiting"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
android:visibility="invisible"
|
||||
app:indicatorColor="@color/color_fab_active" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue