Skip to content

Commit d111bc8

Browse files
committed
Using SAM
1 parent a57c06e commit d111bc8

11 files changed

+195
-281
lines changed

src/main/scala/com/github/shadowsocks/AppManager.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
297297

298298
val bypassSwitch = findViewById(R.id.bypassSwitch).asInstanceOf[Switch]
299299
val prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext)
300-
bypassSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener {
301-
def onCheckedChanged(button: CompoundButton, checked: Boolean) {
302-
prefs.edit().putBoolean(Key.isBypassApps, checked).commit()
303-
}
304-
})
300+
bypassSwitch.setOnCheckedChangeListener((button: CompoundButton, checked: Boolean) =>
301+
prefs.edit().putBoolean(Key.isBypassApps, checked).commit())
305302
bypassSwitch.setChecked(prefs.getBoolean(Key.isBypassApps, false))
306303

307304
appListView = findViewById(R.id.applistview).asInstanceOf[ListView]

src/main/scala/com/github/shadowsocks/BaseService.scala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,19 @@ trait BaseService {
110110

111111
protected def changeState(s: Int, msg: String) {
112112
val handler = new Handler(getContext.getMainLooper)
113-
handler.post(new Runnable {
114-
override def run() {
115-
if (state != s) {
116-
if (callbackCount > 0) {
117-
val n = callbacks.beginBroadcast()
118-
for (i <- 0 to n - 1) {
119-
try {
120-
callbacks.getBroadcastItem(i).stateChanged(s, msg)
121-
} catch {
122-
case _: Exception => // Ignore
123-
}
124-
}
125-
callbacks.finishBroadcast()
113+
handler.post(() => if (state != s) {
114+
if (callbackCount > 0) {
115+
val n = callbacks.beginBroadcast()
116+
for (i <- 0 to n - 1) {
117+
try {
118+
callbacks.getBroadcastItem(i).stateChanged(s, msg)
119+
} catch {
120+
case _: Exception => // Ignore
126121
}
127-
state = s
128122
}
123+
callbacks.finishBroadcast()
129124
}
125+
state = s
130126
})
131127
}
132128

src/main/scala/com/github/shadowsocks/ParserActivity.scala

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ class ParserActivity extends Activity {
5757
new AlertDialog.Builder(this)
5858
.setTitle(R.string.add_profile_dialog)
5959
.setCancelable(false)
60-
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
61-
override def onClick(dialog: DialogInterface, id: Int) {
60+
.setPositiveButton(R.string.yes, ((dialog: DialogInterface, id: Int) => {
6261
Parser.parse(data) match {
6362
case Some(profile) => addProfile(profile)
6463
case _ => // ignore
6564
}
6665
dialog.dismiss()
67-
}
68-
})
69-
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
70-
override def onClick(dialog: DialogInterface, id: Int) {
66+
}): DialogInterface.OnClickListener)
67+
.setNegativeButton(R.string.no, ((dialog: DialogInterface, id: Int) => {
7168
dialog.dismiss()
7269
finish()
73-
}
74-
})
70+
}): DialogInterface.OnClickListener)
7571
.setMessage(data)
7672
.create()
7773
.show()
@@ -91,15 +87,13 @@ class ParserActivity extends Activity {
9187

9288
val h = showProgress(getString(R.string.loading))
9389

94-
h.postDelayed(new Runnable {
95-
def run() {
96-
val profileManager =
97-
new ProfileManager(PreferenceManager.getDefaultSharedPreferences(getBaseContext),
98-
getApplication.asInstanceOf[ShadowsocksApplication].dbHelper)
99-
profileManager.createOrUpdateProfile(profile)
100-
profileManager.reload(profile.id)
101-
h.sendEmptyMessage(0)
102-
}
90+
h.postDelayed(() => {
91+
val profileManager =
92+
new ProfileManager(PreferenceManager.getDefaultSharedPreferences(getBaseContext),
93+
getApplication.asInstanceOf[ShadowsocksApplication].dbHelper)
94+
profileManager.createOrUpdateProfile(profile)
95+
profileManager.reload(profile.id)
96+
h.sendEmptyMessage(0)
10397
}, 600)
10498
}
10599

0 commit comments

Comments
 (0)