Commit 9613d653 authored by Max Lv's avatar Max Lv

fix a issue of progress dialog

parent a510b111
Subproject commit 7260153439e5ec264b8eb5f7364bd2c73fdb0e39 Subproject commit 91730267dd23975ca3b3a05417e89df4865b6f88
...@@ -185,6 +185,7 @@ class Shadowsocks ...@@ -185,6 +185,7 @@ class Shadowsocks
// Variables // Variables
var switchButton: Switch = null var switchButton: Switch = null
var progressDialog: ProgressDialog = null var progressDialog: ProgressDialog = null
var progressTag = -1
var state = State.INIT var state = State.INIT
var prepared = false var prepared = false
var currentProfile = new Profile var currentProfile = new Profile
...@@ -271,9 +272,10 @@ class Shadowsocks ...@@ -271,9 +272,10 @@ class Shadowsocks
switchButton.setOnCheckedChangeListener(this) switchButton.setOnCheckedChangeListener(this)
} }
private def showProgress(msg: String): Handler = { private def showProgress(msg: Int): Handler = {
clearDialog() clearDialog()
progressDialog = ProgressDialog.show(this, "", msg, true, false) progressDialog = ProgressDialog.show(this, "", getString(msg), true, false)
progressTag = msg
new Handler { new Handler {
override def handleMessage(msg: Message) { override def handleMessage(msg: Message) {
clearDialog() clearDialog()
...@@ -397,7 +399,7 @@ class Shadowsocks ...@@ -397,7 +399,7 @@ class Shadowsocks
} }
def prepareStartService() { def prepareStartService() {
showProgress(getString(R.string.connecting)) showProgress(R.string.connecting)
spawn { spawn {
if (!status.getBoolean(getVersionName, false)) { if (!status.getBoolean(getVersionName, false)) {
status.edit.putBoolean(getVersionName, true).commit() status.edit.putBoolean(getVersionName, true).commit()
...@@ -616,7 +618,7 @@ class Shadowsocks ...@@ -616,7 +618,7 @@ class Shadowsocks
which match { which match {
case 0 => case 0 =>
dialog.dismiss() dialog.dismiss()
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
h.postDelayed(new Runnable() { h.postDelayed(new Runnable() {
def run() { def run() {
val integrator = new IntentIntegrator(Shadowsocks.this) val integrator = new IntentIntegrator(Shadowsocks.this)
...@@ -640,7 +642,7 @@ class Shadowsocks ...@@ -640,7 +642,7 @@ class Shadowsocks
def reloadProfile() { def reloadProfile() {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
...@@ -659,7 +661,7 @@ class Shadowsocks ...@@ -659,7 +661,7 @@ class Shadowsocks
def addProfile(profile: Profile) { def addProfile(profile: Profile) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
...@@ -678,7 +680,7 @@ class Shadowsocks ...@@ -678,7 +680,7 @@ class Shadowsocks
def addProfile(id: Int) { def addProfile(id: Int) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
...@@ -696,7 +698,7 @@ class Shadowsocks ...@@ -696,7 +698,7 @@ class Shadowsocks
def updateProfile(id: Int) { def updateProfile(id: Int) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
...@@ -933,15 +935,11 @@ class Shadowsocks ...@@ -933,15 +935,11 @@ class Shadowsocks
} }
private def recovery() { private def recovery() {
val h = showProgress(getString(R.string.recovering)) serviceStop()
val h = showProgress(R.string.recovering)
spawn { spawn {
reset() reset()
handler.post(new Runnable { h.sendEmptyMessage(0)
override def run() {
serviceStop
h.sendEmptyMessage(0)
}
})
} }
} }
...@@ -971,7 +969,7 @@ class Shadowsocks ...@@ -971,7 +969,7 @@ class Shadowsocks
} }
private def flushDnsCache() { private def flushDnsCache() {
val h = showProgress(getString(R.string.flushing)) val h = showProgress(R.string.flushing)
spawn { spawn {
Utils.toggleAirplaneMode(getBaseContext) Utils.toggleAirplaneMode(getBaseContext)
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
...@@ -1089,6 +1087,7 @@ class Shadowsocks ...@@ -1089,6 +1087,7 @@ class Shadowsocks
if (progressDialog != null) { if (progressDialog != null) {
progressDialog.dismiss() progressDialog.dismiss()
progressDialog = null progressDialog = null
progressTag = -1
} }
} }
...@@ -1102,14 +1101,19 @@ class Shadowsocks ...@@ -1102,14 +1101,19 @@ class Shadowsocks
if (progressDialog == null) { if (progressDialog == null) {
progressDialog = ProgressDialog progressDialog = ProgressDialog
.show(Shadowsocks.this, "", getString(R.string.connecting), true, true) .show(Shadowsocks.this, "", getString(R.string.connecting), true, true)
progressTag = R.string.connecting
} }
setPreferenceEnabled(enabled = false) setPreferenceEnabled(enabled = false)
case State.CONNECTED => case State.CONNECTED =>
clearDialog() if (progressTag == R.string.connecting) {
clearDialog()
}
changeSwitch(checked = true) changeSwitch(checked = true)
setPreferenceEnabled(enabled = false) setPreferenceEnabled(enabled = false)
case State.STOPPED => case State.STOPPED =>
clearDialog() if (progressTag == R.string.stopping) {
clearDialog()
}
changeSwitch(checked = false) changeSwitch(checked = false)
if (m != null) { if (m != null) {
new SnackBar.Builder(Shadowsocks.this) new SnackBar.Builder(Shadowsocks.this)
...@@ -1124,6 +1128,7 @@ class Shadowsocks ...@@ -1124,6 +1128,7 @@ class Shadowsocks
if (progressDialog == null) { if (progressDialog == null) {
progressDialog = ProgressDialog progressDialog = ProgressDialog
.show(Shadowsocks.this, "", getString(R.string.stopping), true, true) .show(Shadowsocks.this, "", getString(R.string.stopping), true, true)
progressTag = R.string.stopping
} }
} }
} }
......
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