Fix connection test not reset in background

This commit is contained in:
Mygod
2016-06-18 18:26:20 +08:00
parent 56de231c4f
commit 27bf6a2237
@@ -177,7 +177,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
override def onServiceConnected() {
// Update the UI
if (fab != null) fab.setEnabled(true)
updateState(true)
updateState()
if (Build.VERSION.SDK_INT >= 21 && app.isNatEnabled) {
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)
@@ -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) {
bgService.getState match {
case State.CONNECTING =>
@@ -462,7 +462,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
preferences.setEnabled(false)
fabProgressCircle.postDelayed(hideCircle, 100)
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.setText(getString(R.string.connection_test_pending))
}
@@ -485,7 +485,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
}
}
private def updateCurrentProfile() {
private def updateCurrentProfile() = {
// Check if current profile changed
if (app.profileId != currentProfile.id) {
currentProfile = app.currentProfile match {
@@ -500,7 +500,9 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
updatePreferenceScreen()
if (serviceStarted) serviceLoad()
}
true
} else false
}
protected override def onResume() {
@@ -508,9 +510,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
ConfigUtils.refresh(this)
updateCurrentProfile()
updateState()
updateState(updateCurrentProfile())
}
private def updatePreferenceScreen() {