Commit 79d1ccba authored by Max Lv's avatar Max Lv

Workaround for the crash caused by ProgressCircle

It's safe to ignore the exception throwed by hide().
Because the init state of the ProgressCircle is hidden.
parent 19df6caa
...@@ -126,14 +126,14 @@ class Shadowsocks ...@@ -126,14 +126,14 @@ class Shadowsocks
if (state == State.CONNECTING) { if (state == State.CONNECTING) {
fabProgressCircle.beginFinalAnimation() fabProgressCircle.beginFinalAnimation()
} else { } else {
handler.postDelayed(() => fabProgressCircle.hide(), 1000) fabProgressCircle.postDelayed(hideCircle, 1000)
} }
fab.setEnabled(true) fab.setEnabled(true)
changeSwitch(checked = true) changeSwitch(checked = true)
preferences.setEnabled(false) preferences.setEnabled(false)
case State.STOPPED => case State.STOPPED =>
fab.setBackgroundTintList(greyTint) fab.setBackgroundTintList(greyTint)
handler.postDelayed(() => fabProgressCircle.hide(), 1000) fabProgressCircle.postDelayed(hideCircle, 1000)
fab.setEnabled(true) fab.setEnabled(true)
changeSwitch(checked = false) changeSwitch(checked = false)
if (m != null) { if (m != null) {
...@@ -176,7 +176,7 @@ class Shadowsocks ...@@ -176,7 +176,7 @@ class Shadowsocks
override def onServiceConnected() { override def onServiceConnected() {
// Update the UI // Update the UI
if (fab != null) fab.setEnabled(true) if (fab != null) fab.setEnabled(true)
stateUpdate() updateState()
if (!ShadowsocksApplication.settings.getBoolean(ShadowsocksApplication.getVersionName, false)) { if (!ShadowsocksApplication.settings.getBoolean(ShadowsocksApplication.getVersionName, false)) {
ShadowsocksApplication.settings.edit.putBoolean(ShadowsocksApplication.getVersionName, true).apply() ShadowsocksApplication.settings.edit.putBoolean(ShadowsocksApplication.getVersionName, true).apply()
...@@ -404,7 +404,15 @@ class Shadowsocks ...@@ -404,7 +404,15 @@ class Shadowsocks
ShadowsocksApplication.profileManager.save ShadowsocksApplication.profileManager.save
} }
private def stateUpdate() { private def hideCircle() {
try {
fabProgressCircle.hide()
} catch {
case _: java.lang.NullPointerException => // Ignore
}
}
private def updateState() {
if (bgService != null) { if (bgService != null) {
bgService.getState match { bgService.getState match {
case State.CONNECTING => case State.CONNECTING =>
...@@ -418,7 +426,7 @@ class Shadowsocks ...@@ -418,7 +426,7 @@ class Shadowsocks
serviceStarted = true serviceStarted = true
fab.setImageResource(R.drawable.ic_cloud) fab.setImageResource(R.drawable.ic_cloud)
preferences.setEnabled(false) preferences.setEnabled(false)
fabProgressCircle.postDelayed(fabProgressCircle.hide, 100) fabProgressCircle.postDelayed(hideCircle, 100)
case State.STOPPING => case State.STOPPING =>
fab.setBackgroundTintList(greyTint) fab.setBackgroundTintList(greyTint)
serviceStarted = false serviceStarted = false
...@@ -430,7 +438,7 @@ class Shadowsocks ...@@ -430,7 +438,7 @@ class Shadowsocks
serviceStarted = false serviceStarted = false
fab.setImageResource(R.drawable.ic_cloud_off) fab.setImageResource(R.drawable.ic_cloud_off)
preferences.setEnabled(true) preferences.setEnabled(true)
fabProgressCircle.postDelayed(fabProgressCircle.hide, 100) fabProgressCircle.postDelayed(hideCircle, 100)
} }
state = bgService.getState state = bgService.getState
} }
...@@ -438,13 +446,13 @@ class Shadowsocks ...@@ -438,13 +446,13 @@ class Shadowsocks
protected override def onResume() { protected override def onResume() {
super.onResume() super.onResume()
stateUpdate()
ConfigUtils.refresh(this) ConfigUtils.refresh(this)
// Check if current profile changed // Check if current profile changed
if (ShadowsocksApplication.profileId != currentProfile.id) reloadProfile() if (ShadowsocksApplication.profileId != currentProfile.id) reloadProfile()
updateTraffic() updateTraffic()
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