mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 14:40:06 +08:00
fix gui
This commit is contained in:
parent
82557554b3
commit
bb575e92cf
@ -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,6 +1278,7 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onUpdated(data: TrafficData) {
|
override suspend fun onUpdated(data: TrafficData) {
|
||||||
|
try {
|
||||||
val index = configurationIdList.indexOf(data.id)
|
val index = configurationIdList.indexOf(data.id)
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
val holder = layoutManager.findViewByPosition(index)
|
val holder = layoutManager.findViewByPosition(index)
|
||||||
@ -1287,6 +1289,9 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Logs.w(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onRemoved(groupId: Long, profileId: Long) {
|
override suspend fun onRemoved(groupId: Long, profileId: Long) {
|
||||||
|
|||||||
@ -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,9 +303,18 @@ class GroupSettingsActivity(
|
|||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
preferenceManager.preferenceDataStore = DataStore.profileCacheStore
|
preferenceManager.preferenceDataStore = DataStore.profileCacheStore
|
||||||
|
try {
|
||||||
activity.apply {
|
activity.apply {
|
||||||
createPreferences(savedInstanceState, rootKey)
|
createPreferences(savedInstanceState, rootKey)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(
|
||||||
|
SagerNet.application,
|
||||||
|
"Error on createPreferences, please try again.",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
Logs.e(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@ -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,9 +313,18 @@ class RouteSettingsActivity(
|
|||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
preferenceManager.preferenceDataStore = DataStore.profileCacheStore
|
preferenceManager.preferenceDataStore = DataStore.profileCacheStore
|
||||||
|
try {
|
||||||
activity.apply {
|
activity.apply {
|
||||||
createPreferences(savedInstanceState, rootKey)
|
createPreferences(savedInstanceState, rootKey)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(
|
||||||
|
SagerNet.application,
|
||||||
|
"Error on createPreferences, please try again.",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
Logs.e(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@ -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,9 +213,18 @@ 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
|
||||||
|
try {
|
||||||
activity.apply {
|
activity.apply {
|
||||||
createPreferences(savedInstanceState, rootKey)
|
createPreferences(savedInstanceState, rootKey)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(
|
||||||
|
SagerNet.application,
|
||||||
|
"Error on createPreferences, please try again.",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
Logs.e(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@ -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 { _, _ ->
|
||||||
|
|||||||
@ -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"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user