Skip to content

Commit

Permalink
Fixed disabled dialog behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Oct 23, 2017
1 parent a774210 commit 05326f2
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.app.AlertDialog;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.view.View;

Expand All @@ -23,17 +25,32 @@ public abstract class StateDialogActivity extends SyncthingActivity {

private AlertDialog mLoadingDialog;
private AlertDialog mDisabledDialog;
private boolean mIsPaused = true;

@Override
protected void onResume() {
super.onResume();
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerOnServiceConnectedListener(() ->
getService().registerOnApiChangeListener(this::onApiChange));
}

@Override
protected void onResume() {
super.onResume();
mIsPaused = false;
}

@Override
protected void onPause() {
super.onPause();
mIsPaused = true;
dismissDisabledDialog();
dismissLoadingDialog();
}

@Override
protected void onDestroy() {
super.onDestroy();
if (getService() != null) {
getService().unregisterOnApiChangeListener(this::onApiChange);
}
Expand Down Expand Up @@ -61,6 +78,9 @@ private void onApiChange(SyncthingService.State currentState) {
}

private void showDisabledDialog() {
if (mIsPaused)
return;

mDisabledDialog = new AlertDialog.Builder(this)
.setTitle(R.string.syncthing_disabled_title)
.setMessage(R.string.syncthing_disabled_message)
Expand All @@ -86,7 +106,7 @@ private void dismissDisabledDialog() {
* Shows the loading dialog with the correct text ("creating keys" or "loading").
*/
private void showLoadingDialog() {
if (isFinishing() || mLoadingDialog != null)
if (mIsPaused || mLoadingDialog != null)
return;

DialogLoadingBinding binding = DataBindingUtil.inflate(
Expand Down

0 comments on commit 05326f2

Please sign in to comment.