1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Fixed disabled dialog behaviour

This commit is contained in:
Felix Ableitner 2017-10-24 03:23:43 +09:00
parent a7742103e1
commit 05326f2b60

View file

@ -3,7 +3,9 @@ package com.nutomic.syncthingandroid.activities;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.view.View; import android.view.View;
@ -23,17 +25,32 @@ public abstract class StateDialogActivity extends SyncthingActivity {
private AlertDialog mLoadingDialog; private AlertDialog mLoadingDialog;
private AlertDialog mDisabledDialog; private AlertDialog mDisabledDialog;
private boolean mIsPaused = true;
@Override @Override
protected void onResume() { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onResume(); super.onCreate(savedInstanceState);
registerOnServiceConnectedListener(() -> registerOnServiceConnectedListener(() ->
getService().registerOnApiChangeListener(this::onApiChange)); getService().registerOnApiChangeListener(this::onApiChange));
} }
@Override
protected void onResume() {
super.onResume();
mIsPaused = false;
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
mIsPaused = true;
dismissDisabledDialog();
dismissLoadingDialog();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (getService() != null) { if (getService() != null) {
getService().unregisterOnApiChangeListener(this::onApiChange); getService().unregisterOnApiChangeListener(this::onApiChange);
} }
@ -61,6 +78,9 @@ public abstract class StateDialogActivity extends SyncthingActivity {
} }
private void showDisabledDialog() { private void showDisabledDialog() {
if (mIsPaused)
return;
mDisabledDialog = new AlertDialog.Builder(this) mDisabledDialog = new AlertDialog.Builder(this)
.setTitle(R.string.syncthing_disabled_title) .setTitle(R.string.syncthing_disabled_title)
.setMessage(R.string.syncthing_disabled_message) .setMessage(R.string.syncthing_disabled_message)
@ -86,7 +106,7 @@ public abstract class StateDialogActivity extends SyncthingActivity {
* Shows the loading dialog with the correct text ("creating keys" or "loading"). * Shows the loading dialog with the correct text ("creating keys" or "loading").
*/ */
private void showLoadingDialog() { private void showLoadingDialog() {
if (isFinishing() || mLoadingDialog != null) if (mIsPaused || mLoadingDialog != null)
return; return;
DialogLoadingBinding binding = DataBindingUtil.inflate( DialogLoadingBinding binding = DataBindingUtil.inflate(