Fix dialog handling

This commit is contained in:
cketti 2017-01-24 07:12:56 +01:00
parent e49bfec2d4
commit 330aef8577
2 changed files with 27 additions and 72 deletions

View file

@ -9,6 +9,8 @@ import java.util.Map;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
@ -47,17 +49,17 @@ import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.service.MailService;
import com.fsck.k9.ui.dialog.ApgDeprecationWarningDialog;
import com.fsck.k9.ui.dialog.ApgDeprecationWarningDialog.ApgDeprecationDialogDismissListener;
import org.openintents.openpgp.util.OpenPgpAppPreference;
import org.openintents.openpgp.util.OpenPgpKeyPreference;
import org.openintents.openpgp.util.OpenPgpUtils;
public class AccountSettings extends K9PreferenceActivity implements ApgDeprecationDialogDismissListener {
public class AccountSettings extends K9PreferenceActivity {
private static final String EXTRA_ACCOUNT = "account";
private static final int DIALOG_COLOR_PICKER_ACCOUNT = 1;
private static final int DIALOG_COLOR_PICKER_LED = 2;
private static final int DIALOG_APG_DEPRECATION_WARNING = 3;
private static final int SELECT_AUTO_EXPAND_FOLDER = 1;
@ -129,7 +131,6 @@ public class AccountSettings extends K9PreferenceActivity implements ApgDeprecat
private static final String PREFERENCE_SPAM_FOLDER = "spam_folder";
private static final String PREFERENCE_TRASH_FOLDER = "trash_folder";
private static final String PREFERENCE_ALWAYS_SHOW_CC_BCC = "always_show_cc_bcc";
public static final String APG_DEPRECATION_DIALOG_TAG = "apgDeprecationDialog";
public static final String APG_PROVIDER_PLACEHOLDER = "apg-placeholder";
@ -716,7 +717,7 @@ public class AccountSettings extends K9PreferenceActivity implements ApgDeprecat
if (APG_PROVIDER_PLACEHOLDER.equals(value)) {
mCryptoApp.setValue("");
mCryptoKey.setOpenPgpProvider("");
showApgDeprecationDialog();
showDialog(DIALOG_APG_DEPRECATION_WARNING);
} else {
mCryptoApp.setValue(value);
mCryptoKey.setOpenPgpProvider(value);
@ -746,18 +747,6 @@ public class AccountSettings extends K9PreferenceActivity implements ApgDeprecat
}
}
private void showApgDeprecationDialog() {
ApgDeprecationWarningDialog fragment = ApgDeprecationWarningDialog.newInstance();
fragment.show(getFragmentManager(), APG_DEPRECATION_DIALOG_TAG);
}
@Override
public void onDismissApgDeprecationDialog() {
if (mCryptoApp != null) {
mCryptoApp.show();
}
}
private void removeListEntry(ListPreference listPreference, String remove) {
CharSequence[] entryValues = listPreference.getEntryValues();
CharSequence[] entries = listPreference.getEntries();
@ -964,6 +953,16 @@ public class AccountSettings extends K9PreferenceActivity implements ApgDeprecat
break;
}
case DIALOG_APG_DEPRECATION_WARNING: {
dialog = new ApgDeprecationWarningDialog(this);
dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mCryptoApp.show();
}
});
break;
}
}
return dialog;

View file

@ -1,13 +1,11 @@
package com.fsck.k9.ui.dialog;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
@ -16,72 +14,30 @@ import android.widget.TextView;
import com.fsck.k9.R;
public class ApgDeprecationWarningDialog extends DialogFragment {
private ApgDeprecationDialogDismissListener onDismissListener;
public static ApgDeprecationWarningDialog newInstance() {
return new ApgDeprecationWarningDialog();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
if (context == null) {
return null;
}
public class ApgDeprecationWarningDialog extends AlertDialog {
public ApgDeprecationWarningDialog(Context context) {
super(context);
LayoutInflater inflater = LayoutInflater.from(context);
View contentView = inflater.inflate(R.layout.dialog_apg_deprecated, null, false);
@SuppressLint("InflateParams")
View contentView = inflater.inflate(R.layout.dialog_apg_deprecated, null);
TextView textViewLearnMore = (TextView) contentView.findViewById(R.id.apg_learn_more);
makeTextViewLinksClickable(textViewLearnMore);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.drawable.ic_apg_small);
builder.setTitle(R.string.apg_deprecated_title);
builder.setView(contentView);
builder.setNeutralButton(R.string.apg_deprecated_ok, new OnClickListener() {
setIcon(R.drawable.ic_apg_small);
setTitle(R.string.apg_deprecated_title);
setView(contentView);
setButton(Dialog.BUTTON_NEUTRAL, context.getString(R.string.apg_deprecated_ok), new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dismiss();
cancel();
}
});
builder.setCancelable(false);
return builder.create();
}
private void makeTextViewLinksClickable(TextView textView) {
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof ApgDeprecationDialogDismissListener) {
onDismissListener = (ApgDeprecationDialogDismissListener) context;
} else {
throw new ClassCastException("An activity displaying this dialog must implement OnDismissListener!");
}
}
@Override
public void onDetach() {
super.onDetach();
onDismissListener = null;
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (onDismissListener != null) {
onDismissListener.onDismissApgDeprecationDialog();
}
}
public interface ApgDeprecationDialogDismissListener {
void onDismissApgDeprecationDialog();
}
}