mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 00:01:19 +00:00
Prevent crashes when dismissing dialogs
This commit is contained in:
parent
9ca1c8acd5
commit
bdec750b34
7 changed files with 40 additions and 32 deletions
|
@ -235,20 +235,14 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis
|
||||||
outState.putString("device", new Gson().toJson(mDevice));
|
outState.putString("device", new Gson().toJson(mDevice));
|
||||||
if (mIsCreateMode){
|
if (mIsCreateMode){
|
||||||
outState.putBoolean(IS_SHOWING_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
|
outState.putBoolean(IS_SHOWING_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
|
||||||
if(mDiscardDialog != null){
|
Util.dismissDialogSafe(mDiscardDialog, this);
|
||||||
mDiscardDialog.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outState.putBoolean(IS_SHOWING_COMPRESSION_DIALOG, mCompressionDialog != null && mCompressionDialog.isShowing());
|
outState.putBoolean(IS_SHOWING_COMPRESSION_DIALOG, mCompressionDialog != null && mCompressionDialog.isShowing());
|
||||||
if(mCompressionDialog != null){
|
Util.dismissDialogSafe(mCompressionDialog, this);
|
||||||
mCompressionDialog.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
|
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
|
||||||
if (mDeleteDialog != null) {
|
Util.dismissDialogSafe(mDeleteDialog, this);
|
||||||
mDeleteDialog.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onServiceConnected() {
|
private void onServiceConnected() {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.model.Folder;
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.util.TextWatcherAdapter;
|
import com.nutomic.syncthingandroid.util.TextWatcherAdapter;
|
||||||
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -242,15 +243,11 @@ public class FolderActivity extends SyncthingActivity
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
|
outState.putBoolean(IS_SHOWING_DELETE_DIALOG, mDeleteDialog != null && mDeleteDialog.isShowing());
|
||||||
if (mDeleteDialog != null) {
|
Util.dismissDialogSafe(mDeleteDialog, this);
|
||||||
mDeleteDialog.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mIsCreateMode){
|
if (mIsCreateMode){
|
||||||
outState.putBoolean(IS_SHOW_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
|
outState.putBoolean(IS_SHOW_DISCARD_DIALOG, mDiscardDialog != null && mDiscardDialog.isShowing());
|
||||||
if(mDiscardDialog != null){
|
Util.dismissDialogSafe(mDiscardDialog, this);
|
||||||
mDiscardDialog.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,9 +288,7 @@ public class MainActivity extends StateDialogActivity
|
||||||
outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap());
|
outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap());
|
||||||
outState.putString(DEVICEID_KEY, deviceID.getText().toString());
|
outState.putString(DEVICEID_KEY, deviceID.getText().toString());
|
||||||
}
|
}
|
||||||
if (mRestartDialog != null){
|
Util.dismissDialogSafe(mRestartDialog, this);
|
||||||
mRestartDialog.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.google.common.io.Files;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.model.Folder;
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||||
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -258,7 +259,7 @@ public class ShareActivity extends StateDialogActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Boolean isError) {
|
protected void onPostExecute(Boolean isError) {
|
||||||
mProgress.dismiss();
|
Util.dismissDialogSafe(mProgress, ShareActivity.this);
|
||||||
Toast.makeText(ShareActivity.this, mIgnored > 0 ?
|
Toast.makeText(ShareActivity.this, mIgnored > 0 ?
|
||||||
getResources().getQuantityString(R.plurals.copy_success_partially, mCopied,
|
getResources().getQuantityString(R.plurals.copy_success_partially, mCopied,
|
||||||
mCopied, mFolder.label, mIgnored) :
|
mCopied, mFolder.label, mIgnored) :
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||||
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles loading/disabled dialogs.
|
* Handles loading/disabled dialogs.
|
||||||
|
@ -78,11 +79,9 @@ public abstract class StateDialogActivity extends SyncthingActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismissDisabledDialog() {
|
private void dismissDisabledDialog() {
|
||||||
if (mDisabledDialog != null && mDisabledDialog.isShowing()) {
|
Util.dismissDialogSafe(mDisabledDialog, this);
|
||||||
mDisabledDialog.dismiss();
|
|
||||||
mDisabledDialog = null;
|
mDisabledDialog = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the loading dialog with the correct text ("creating keys" or "loading").
|
* Shows the loading dialog with the correct text ("creating keys" or "loading").
|
||||||
|
@ -111,9 +110,7 @@ public abstract class StateDialogActivity extends SyncthingActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismissLoadingDialog() {
|
private void dismissLoadingDialog() {
|
||||||
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
|
Util.dismissDialogSafe(mLoadingDialog, this);
|
||||||
mLoadingDialog.dismiss();
|
|
||||||
mLoadingDialog = null;
|
mLoadingDialog = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
|
||||||
import com.nutomic.syncthingandroid.service.RestApi;
|
import com.nutomic.syncthingandroid.service.RestApi;
|
||||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
|
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
|
||||||
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
package com.nutomic.syncthingandroid.util;
|
package com.nutomic.syncthingandroid.util;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.widget.Toast;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.os.Build;
|
||||||
import java.io.IOException;
|
import android.util.Log;
|
||||||
import java.io.DataOutputStream;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
import eu.chainfire.libsuperuser.Shell;
|
import eu.chainfire.libsuperuser.Shell;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
@ -116,4 +119,21 @@ public class Util {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure that dialog is showing and activity is valid before dismissing dialog, to prevent
|
||||||
|
* various crashes.
|
||||||
|
*/
|
||||||
|
public static void dismissDialogSafe(Dialog dialog, Activity activity) {
|
||||||
|
if (dialog == null || !dialog.isShowing())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (activity.isFinishing())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN && activity.isDestroyed())
|
||||||
|
return;
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue