This commit is contained in:
arm64v8a 2023-04-13 14:04:23 +09:00
parent 82557554b3
commit bb575e92cf
6 changed files with 67 additions and 26 deletions

View File

@ -550,33 +550,34 @@ class ConfigurationFragment @JvmOverloads constructor(
suspend fun update(profile: ProxyEntity) { suspend fun update(profile: ProxyEntity) {
fragment?.configurationListView?.post { fragment?.configurationListView?.post {
val context = context ?: return@post
if (!isAdded) return@post
var profileStatusText: String? = null var profileStatusText: String? = null
var profileStatusColor = 0 var profileStatusColor = 0
when (profile.status) { when (profile.status) {
-1 -> { -1 -> {
profileStatusText = profile.error profileStatusText = profile.error
profileStatusColor = profileStatusColor = context.getColorAttr(android.R.attr.textColorSecondary)
requireContext().getColorAttr(android.R.attr.textColorSecondary)
} }
0 -> { 0 -> {
profileStatusText = getString(R.string.connection_test_testing) profileStatusText = getString(R.string.connection_test_testing)
profileStatusColor = profileStatusColor = context.getColorAttr(android.R.attr.textColorSecondary)
requireContext().getColorAttr(android.R.attr.textColorSecondary)
} }
1 -> { 1 -> {
profileStatusText = getString(R.string.available, profile.ping) profileStatusText = getString(R.string.available, profile.ping)
profileStatusColor = requireContext().getColour(R.color.material_green_500) profileStatusColor = context.getColour(R.color.material_green_500)
} }
2 -> { 2 -> {
profileStatusText = profile.error profileStatusText = profile.error
profileStatusColor = requireContext().getColour(R.color.material_red_500) profileStatusColor = context.getColour(R.color.material_red_500)
} }
3 -> { 3 -> {
val err = profile.error ?: "" val err = profile.error ?: ""
val msg = Protocols.genFriendlyMsg(err) val msg = Protocols.genFriendlyMsg(err)
profileStatusText = if (msg != err) msg else getString(R.string.unavailable) profileStatusText = if (msg != err) msg else getString(R.string.unavailable)
profileStatusColor = requireContext().getColour(R.color.material_red_500) profileStatusColor = context.getColour(R.color.material_red_500)
} }
} }
@ -585,7 +586,7 @@ class ConfigurationFragment @JvmOverloads constructor(
append("\n") append("\n")
append( append(
profile.displayType(), profile.displayType(),
ForegroundColorSpan(requireContext().getProtocolColor(profile.type)), ForegroundColorSpan(context.getProtocolColor(profile.type)),
SPAN_EXCLUSIVE_EXCLUSIVE SPAN_EXCLUSIVE_EXCLUSIVE
) )
append(" ") append(" ")
@ -1277,15 +1278,19 @@ class ConfigurationFragment @JvmOverloads constructor(
} }
override suspend fun onUpdated(data: TrafficData) { override suspend fun onUpdated(data: TrafficData) {
val index = configurationIdList.indexOf(data.id) try {
if (index != -1) { val index = configurationIdList.indexOf(data.id)
val holder = layoutManager.findViewByPosition(index) if (index != -1) {
?.let { configurationListView.getChildViewHolder(it) } as ConfigurationHolder? val holder = layoutManager.findViewByPosition(index)
if (holder != null) { ?.let { configurationListView.getChildViewHolder(it) } as ConfigurationHolder?
onMainDispatcher { if (holder != null) {
holder.bind(holder.entity, data) onMainDispatcher {
holder.bind(holder.entity, data)
}
} }
} }
} catch (e: Exception) {
Logs.w(e)
} }
} }

View File

@ -9,6 +9,7 @@ import android.os.Parcelable
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
@ -19,8 +20,10 @@ import com.github.shadowsocks.plugin.fragment.AlertDialogFragment
import io.nekohasekai.sagernet.GroupType import io.nekohasekai.sagernet.GroupType
import io.nekohasekai.sagernet.Key import io.nekohasekai.sagernet.Key
import io.nekohasekai.sagernet.R import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.SagerNet
import io.nekohasekai.sagernet.database.* import io.nekohasekai.sagernet.database.*
import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener
import io.nekohasekai.sagernet.ktx.Logs
import io.nekohasekai.sagernet.ktx.applyDefaultValues import io.nekohasekai.sagernet.ktx.applyDefaultValues
import io.nekohasekai.sagernet.ktx.onMainDispatcher import io.nekohasekai.sagernet.ktx.onMainDispatcher
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
@ -300,8 +303,17 @@ class GroupSettingsActivity(
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.preferenceDataStore = DataStore.profileCacheStore preferenceManager.preferenceDataStore = DataStore.profileCacheStore
activity.apply { try {
createPreferences(savedInstanceState, rootKey) activity.apply {
createPreferences(savedInstanceState, rootKey)
}
} catch (e: Exception) {
Toast.makeText(
SagerNet.application,
"Error on createPreferences, please try again.",
Toast.LENGTH_SHORT
).show()
Logs.e(e)
} }
} }

View File

@ -8,6 +8,7 @@ import android.os.Parcelable
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.Toast
import androidx.activity.result.component1 import androidx.activity.result.component1
import androidx.activity.result.component2 import androidx.activity.result.component2
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
@ -23,11 +24,13 @@ import com.github.shadowsocks.plugin.fragment.AlertDialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import io.nekohasekai.sagernet.Key import io.nekohasekai.sagernet.Key
import io.nekohasekai.sagernet.R import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.SagerNet
import io.nekohasekai.sagernet.database.DataStore import io.nekohasekai.sagernet.database.DataStore
import io.nekohasekai.sagernet.database.ProfileManager import io.nekohasekai.sagernet.database.ProfileManager
import io.nekohasekai.sagernet.database.RuleEntity import io.nekohasekai.sagernet.database.RuleEntity
import io.nekohasekai.sagernet.database.SagerDatabase import io.nekohasekai.sagernet.database.SagerDatabase
import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener
import io.nekohasekai.sagernet.ktx.Logs
import io.nekohasekai.sagernet.ktx.app import io.nekohasekai.sagernet.ktx.app
import io.nekohasekai.sagernet.ktx.onMainDispatcher import io.nekohasekai.sagernet.ktx.onMainDispatcher
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
@ -310,8 +313,17 @@ class RouteSettingsActivity(
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.preferenceDataStore = DataStore.profileCacheStore preferenceManager.preferenceDataStore = DataStore.profileCacheStore
activity.apply { try {
createPreferences(savedInstanceState, rootKey) activity.apply {
createPreferences(savedInstanceState, rootKey)
}
} catch (e: Exception) {
Toast.makeText(
SagerNet.application,
"Error on createPreferences, please try again.",
Toast.LENGTH_SHORT
).show()
Logs.e(e)
} }
} }

View File

@ -10,6 +10,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Toast
import androidx.activity.result.component1 import androidx.activity.result.component1
import androidx.activity.result.component2 import androidx.activity.result.component2
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
@ -35,10 +36,7 @@ import io.nekohasekai.sagernet.database.SagerDatabase
import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener import io.nekohasekai.sagernet.database.preference.OnPreferenceDataStoreChangeListener
import io.nekohasekai.sagernet.databinding.LayoutGroupItemBinding import io.nekohasekai.sagernet.databinding.LayoutGroupItemBinding
import io.nekohasekai.sagernet.fmt.AbstractBean import io.nekohasekai.sagernet.fmt.AbstractBean
import io.nekohasekai.sagernet.ktx.applyDefaultValues import io.nekohasekai.sagernet.ktx.*
import io.nekohasekai.sagernet.ktx.onMainDispatcher
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
import io.nekohasekai.sagernet.ktx.runOnMainDispatcher
import io.nekohasekai.sagernet.ui.ThemedActivity import io.nekohasekai.sagernet.ui.ThemedActivity
import io.nekohasekai.sagernet.widget.ListListener import io.nekohasekai.sagernet.widget.ListListener
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@ -215,8 +213,17 @@ abstract class ProfileSettingsActivity<T : AbstractBean>(
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.preferenceDataStore = DataStore.profileCacheStore preferenceManager.preferenceDataStore = DataStore.profileCacheStore
activity.apply { try {
createPreferences(savedInstanceState, rootKey) activity.apply {
createPreferences(savedInstanceState, rootKey)
}
} catch (e: Exception) {
Toast.makeText(
SagerNet.application,
"Error on createPreferences, please try again.",
Toast.LENGTH_SHORT
).show()
Logs.e(e)
} }
} }

View File

@ -3,7 +3,9 @@ package moe.matsuri.nb4a.ui
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.EditText import android.widget.EditText
import android.widget.LinearLayout
import androidx.core.content.res.TypedArrayUtils import androidx.core.content.res.TypedArrayUtils
import androidx.core.view.isVisible
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import io.nekohasekai.sagernet.R import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.database.DataStore import io.nekohasekai.sagernet.database.DataStore
@ -30,6 +32,7 @@ constructor(
concurrent?.apply { concurrent?.apply {
setText(DataStore.connectionTestConcurrent.toString()) setText(DataStore.connectionTestConcurrent.toString())
} }
it.rootView.findViewById<LinearLayout>(R.id.concurrent_layout)?.isVisible = true
} }
setOnPreferenceChangeListener { _, _ -> setOnPreferenceChangeListener { _, _ ->

View File

@ -31,8 +31,10 @@
android:typeface="monospace" /> android:typeface="monospace" />
<LinearLayout <LinearLayout
android:id="@+id/concurrent_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="gone">
<TextView <TextView
style="?android:attr/textAppearanceSmall" style="?android:attr/textAppearanceSmall"