Commit 27bf6a22 authored by Mygod's avatar Mygod

Fix connection test not reset in background

parent 56de231c
...@@ -177,7 +177,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -177,7 +177,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
override def onServiceConnected() { override def onServiceConnected() {
// Update the UI // Update the UI
if (fab != null) fab.setEnabled(true) if (fab != null) fab.setEnabled(true)
updateState(true) updateState()
if (Build.VERSION.SDK_INT >= 21 && app.isNatEnabled) { if (Build.VERSION.SDK_INT >= 21 && app.isNatEnabled) {
val snackbar = Snackbar.make(findViewById(android.R.id.content), R.string.nat_deprecated, Snackbar.LENGTH_LONG) val snackbar = Snackbar.make(findViewById(android.R.id.content), R.string.nat_deprecated, Snackbar.LENGTH_LONG)
snackbar.setAction(R.string.switch_to_vpn, (_ => preferences.natSwitch.setChecked(false)): View.OnClickListener) snackbar.setAction(R.string.switch_to_vpn, (_ => preferences.natSwitch.setChecked(false)): View.OnClickListener)
...@@ -445,7 +445,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -445,7 +445,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
} }
private def updateState(initial: Boolean = false) { private def updateState(resetConnectionTest: Boolean = true) {
if (bgService != null) { if (bgService != null) {
bgService.getState match { bgService.getState match {
case State.CONNECTING => case State.CONNECTING =>
...@@ -462,7 +462,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -462,7 +462,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
preferences.setEnabled(false) preferences.setEnabled(false)
fabProgressCircle.postDelayed(hideCircle, 100) fabProgressCircle.postDelayed(hideCircle, 100)
stat.setVisibility(View.VISIBLE) stat.setVisibility(View.VISIBLE)
if (initial) if (app.isNatEnabled) connectionTestText.setVisibility(View.GONE) else { if (resetConnectionTest) if (app.isNatEnabled) connectionTestText.setVisibility(View.GONE) else {
connectionTestText.setVisibility(View.VISIBLE) connectionTestText.setVisibility(View.VISIBLE)
connectionTestText.setText(getString(R.string.connection_test_pending)) connectionTestText.setText(getString(R.string.connection_test_pending))
} }
...@@ -485,7 +485,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -485,7 +485,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
} }
private def updateCurrentProfile() { private def updateCurrentProfile() = {
// Check if current profile changed // Check if current profile changed
if (app.profileId != currentProfile.id) { if (app.profileId != currentProfile.id) {
currentProfile = app.currentProfile match { currentProfile = app.currentProfile match {
...@@ -500,7 +500,9 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -500,7 +500,9 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
updatePreferenceScreen() updatePreferenceScreen()
if (serviceStarted) serviceLoad() if (serviceStarted) serviceLoad()
}
true
} else false
} }
protected override def onResume() { protected override def onResume() {
...@@ -508,9 +510,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -508,9 +510,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
ConfigUtils.refresh(this) ConfigUtils.refresh(this)
updateCurrentProfile() updateState(updateCurrentProfile())
updateState()
} }
private def updatePreferenceScreen() { private def updatePreferenceScreen() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment