Commit 58c16704 authored by Mygod's avatar Mygod

No more restarting AppManager after importing

parent bf9b3f4f
...@@ -104,11 +104,12 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -104,11 +104,12 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
implicit def anyrefarray_tools[T <: AnyRef](a: Array[T]): ObjectArrayTools[T] = new ObjectArrayTools(a) implicit def anyrefarray_tools[T <: AnyRef](a: Array[T]): ObjectArrayTools[T] = new ObjectArrayTools(a)
var apps: Array[ProxiedApp] = null var apps: Array[ProxiedApp] = _
var appListView: ListView = null var appListView: ListView = _
var overlay: TextView = null var loadingView: View = _
var adapter: ListAdapter = null var overlay: TextView = _
var appsLoaded: Boolean = false var adapter: ListAdapter = _
@volatile var appsLoading: Boolean = _
def loadApps(context: Context): Array[ProxiedApp] = { def loadApps(context: Context): Array[ProxiedApp] = {
val proxiedAppString = ShadowsocksApplication.settings.getString(Key.proxied, "") val proxiedAppString = ShadowsocksApplication.settings.getString(Key.proxied, "")
...@@ -133,6 +134,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -133,6 +134,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
} }
def loadApps() { def loadApps() {
appsLoading = true
apps = loadApps(this).sortWith((a, b) => { apps = loadApps(this).sortWith((a, b) => {
if (a == null || b == null || a.name == null || b.name == null) { if (a == null || b == null || a.name == null || b.name == null) {
true true
...@@ -173,7 +175,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -173,7 +175,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
convertView convertView
} }
} }
appsLoaded = true
} }
/** Called an application is check/unchecked */ /** Called an application is check/unchecked */
...@@ -230,9 +231,9 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -230,9 +231,9 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
prefs.edit.putString(Key.proxied, apps).apply() prefs.edit.putString(Key.proxied, apps).apply()
Toast.makeText(this, R.string.action_import_msg, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.action_import_msg, Toast.LENGTH_SHORT).show()
// Restart activity // Restart activity
val intent = getIntent appListView.setVisibility(View.GONE)
finish() loadingView.setVisibility(View.VISIBLE)
startActivity(intent) if (appsLoading) appsLoading = false else loadAppsAsync()
return true return true
} }
} }
...@@ -272,6 +273,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -272,6 +273,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
ShadowsocksApplication.settings.edit().putBoolean(Key.isBypassApps, checked).apply()) ShadowsocksApplication.settings.edit().putBoolean(Key.isBypassApps, checked).apply())
bypassSwitch.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isBypassApps, false)) bypassSwitch.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isBypassApps, false))
loadingView = findViewById(R.id.loading)
appListView = findViewById(R.id.applistview).asInstanceOf[ListView] appListView = findViewById(R.id.applistview).asInstanceOf[ListView]
appListView.setOnScrollListener(new AbsListView.OnScrollListener { appListView.setOnScrollListener(new AbsListView.OnScrollListener {
var visible = false var visible = false
...@@ -294,15 +296,16 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -294,15 +296,16 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
} }
} }
}) })
loadAppsAsync()
} }
protected override def onResume() { def loadAppsAsync() {
super.onResume()
Future { Future {
if (!appsLoaded) loadApps() while (!appsLoading) loadApps()
appsLoading = false
handler.post(() => { handler.post(() => {
appListView.setAdapter(adapter) appListView.setAdapter(adapter)
Utils.crossFade(AppManager.this, findViewById(R.id.loading), appListView) Utils.crossFade(AppManager.this, loadingView, appListView)
}) })
} }
} }
......
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