1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-27 06:41:15 +00:00

Wrap onApiChange in runOnUiThread (fixes #312).

This commit is contained in:
Lode Hoste 2015-03-27 17:19:24 +01:00
parent 0a07f4546b
commit 396b05006c

View file

@ -50,14 +50,17 @@ public class MainActivity extends SyncthingActivity
*/ */
@Override @Override
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
public void onApiChange(SyncthingService.State currentState) { public void onApiChange(final SyncthingService.State currentState) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (currentState != SyncthingService.State.ACTIVE && !isFinishing() && !mIsDestroyed) { if (currentState != SyncthingService.State.ACTIVE && !isFinishing() && !mIsDestroyed) {
if (currentState == SyncthingService.State.DISABLED) { if (currentState == SyncthingService.State.DISABLED) {
if (mLoadingDialog != null) { if (mLoadingDialog != null) {
mLoadingDialog.dismiss(); mLoadingDialog.dismiss();
mLoadingDialog = null; mLoadingDialog = null;
} }
mDisabledDialog = SyncthingService.showDisabledDialog(this); mDisabledDialog = SyncthingService.showDisabledDialog(MainActivity.this);
} else if (mLoadingDialog == null) { } else if (mLoadingDialog == null) {
final SharedPreferences prefs = final SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(MainActivity.this); PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
@ -69,14 +72,14 @@ public class MainActivity extends SyncthingActivity
? R.string.web_gui_creating_key ? R.string.web_gui_creating_key
: R.string.api_loading); : R.string.api_loading);
mLoadingDialog = new AlertDialog.Builder(this) mLoadingDialog = new AlertDialog.Builder(MainActivity.this)
.setCancelable(false) .setCancelable(false)
.setView(dialogLayout) .setView(dialogLayout)
.show(); .show();
// Make sure the first start dialog is shown on top. // Make sure the first start dialog is shown on top.
if (prefs.getBoolean("first_start", true)) { if (prefs.getBoolean("first_start", true)) {
new AlertDialog.Builder(this) new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.welcome_title) .setTitle(R.string.welcome_title)
.setMessage(R.string.welcome_text) .setMessage(R.string.welcome_text)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@ -104,6 +107,8 @@ public class MainActivity extends SyncthingActivity
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
} }
});
}
private final FragmentPagerAdapter mSectionsPagerAdapter = private final FragmentPagerAdapter mSectionsPagerAdapter =
new FragmentPagerAdapter(getSupportFragmentManager()) { new FragmentPagerAdapter(getSupportFragmentManager()) {