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:
parent
0a07f4546b
commit
396b05006c
1 changed files with 52 additions and 47 deletions
|
@ -50,59 +50,64 @@ public class MainActivity extends SyncthingActivity
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
public void onApiChange(SyncthingService.State currentState) {
|
public void onApiChange(final SyncthingService.State currentState) {
|
||||||
if (currentState != SyncthingService.State.ACTIVE && !isFinishing() && !mIsDestroyed) {
|
runOnUiThread(new Runnable() {
|
||||||
if (currentState == SyncthingService.State.DISABLED) {
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (currentState != SyncthingService.State.ACTIVE && !isFinishing() && !mIsDestroyed) {
|
||||||
|
if (currentState == SyncthingService.State.DISABLED) {
|
||||||
|
if (mLoadingDialog != null) {
|
||||||
|
mLoadingDialog.dismiss();
|
||||||
|
mLoadingDialog = null;
|
||||||
|
}
|
||||||
|
mDisabledDialog = SyncthingService.showDisabledDialog(MainActivity.this);
|
||||||
|
} else if (mLoadingDialog == null) {
|
||||||
|
final SharedPreferences prefs =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||||
|
|
||||||
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
|
View dialogLayout = inflater.inflate(R.layout.loading_dialog, null);
|
||||||
|
TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text);
|
||||||
|
loadingText.setText((getService().isFirstStart())
|
||||||
|
? R.string.web_gui_creating_key
|
||||||
|
: R.string.api_loading);
|
||||||
|
|
||||||
|
mLoadingDialog = new AlertDialog.Builder(MainActivity.this)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setView(dialogLayout)
|
||||||
|
.show();
|
||||||
|
|
||||||
|
// Make sure the first start dialog is shown on top.
|
||||||
|
if (prefs.getBoolean("first_start", true)) {
|
||||||
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
|
.setTitle(R.string.welcome_title)
|
||||||
|
.setMessage(R.string.welcome_text)
|
||||||
|
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
prefs.edit().putBoolean("first_start", false).commit();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mLoadingDialog != null) {
|
if (mLoadingDialog != null) {
|
||||||
mLoadingDialog.dismiss();
|
mLoadingDialog.dismiss();
|
||||||
mLoadingDialog = null;
|
mLoadingDialog = null;
|
||||||
}
|
}
|
||||||
mDisabledDialog = SyncthingService.showDisabledDialog(this);
|
if (mDisabledDialog != null) {
|
||||||
} else if (mLoadingDialog == null) {
|
mDisabledDialog.dismiss();
|
||||||
final SharedPreferences prefs =
|
mDisabledDialog = null;
|
||||||
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
|
||||||
|
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
|
||||||
View dialogLayout = inflater.inflate(R.layout.loading_dialog, null);
|
|
||||||
TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text);
|
|
||||||
loadingText.setText((getService().isFirstStart())
|
|
||||||
? R.string.web_gui_creating_key
|
|
||||||
: R.string.api_loading);
|
|
||||||
|
|
||||||
mLoadingDialog = new AlertDialog.Builder(this)
|
|
||||||
.setCancelable(false)
|
|
||||||
.setView(dialogLayout)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
// Make sure the first start dialog is shown on top.
|
|
||||||
if (prefs.getBoolean("first_start", true)) {
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setTitle(R.string.welcome_title)
|
|
||||||
.setMessage(R.string.welcome_text)
|
|
||||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
prefs.edit().putBoolean("first_start", false).commit();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
}
|
}
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
|
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
}
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (mLoadingDialog != null) {
|
|
||||||
mLoadingDialog.dismiss();
|
|
||||||
mLoadingDialog = null;
|
|
||||||
}
|
|
||||||
if (mDisabledDialog != null) {
|
|
||||||
mDisabledDialog.dismiss();
|
|
||||||
mDisabledDialog = null;
|
|
||||||
}
|
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
|
||||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final FragmentPagerAdapter mSectionsPagerAdapter =
|
private final FragmentPagerAdapter mSectionsPagerAdapter =
|
||||||
|
|
Loading…
Reference in a new issue