diff --git a/k9mail/src/main/java/com/fsck/k9/ui/dialog/AutocryptPreferEncryptDialog.java b/k9mail/src/main/java/com/fsck/k9/ui/dialog/AutocryptPreferEncryptDialog.java deleted file mode 100644 index b97dccf43..000000000 --- a/k9mail/src/main/java/com/fsck/k9/ui/dialog/AutocryptPreferEncryptDialog.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.fsck.k9.ui.dialog; - - -import android.annotation.SuppressLint; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.Context; -import android.content.DialogInterface; -import android.text.method.LinkMovementMethod; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.CheckBox; -import android.widget.TextView; - -import com.fsck.k9.R; - - -public class AutocryptPreferEncryptDialog extends AlertDialog implements OnClickListener { - - private final CheckBox preferEncryptCheckbox; - private final OnPreferEncryptChangedListener onPreferEncryptChangedListener; - - private boolean preferEncryptEnabled; - - public AutocryptPreferEncryptDialog(Context context, boolean preferEncryptEnabled, - OnPreferEncryptChangedListener onPreferEncryptChangedListener) { - super(context); - - this.onPreferEncryptChangedListener = onPreferEncryptChangedListener; - this.preferEncryptEnabled = preferEncryptEnabled; - - LayoutInflater inflater = LayoutInflater.from(context); - - @SuppressLint("InflateParams") - View contentView = inflater.inflate(R.layout.dialog_autocrypt_prefer_encrypt, null); - - TextView learnMoreText = (TextView) contentView.findViewById(R.id.prefer_encrypt_learn_more); - makeTextViewLinksClickable(learnMoreText); - - preferEncryptCheckbox = (CheckBox) contentView.findViewById(R.id.prefer_encrypt_check); - preferEncryptCheckbox.setChecked(preferEncryptEnabled); - - contentView.findViewById(R.id.prefer_encrypt).setOnClickListener(this); - - // TODO add autocrypt logo? - // setIcon(R.drawable.autocrypt); - setView(contentView); - setButton(Dialog.BUTTON_POSITIVE, context.getString(R.string.done_action), new OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - cancel(); - } - }); - } - - @Override - public void onClick(View v) { - toggleCheck(); - } - - private void toggleCheck() { - preferEncryptEnabled = !preferEncryptEnabled; - preferEncryptCheckbox.setChecked(preferEncryptEnabled); - - onPreferEncryptChangedListener.onPreferEncryptChanged(preferEncryptEnabled); - } - - public interface OnPreferEncryptChangedListener { - void onPreferEncryptChanged(boolean enabled); - } - - private void makeTextViewLinksClickable(TextView textView) { - textView.setMovementMethod(LinkMovementMethod.getInstance()); - } -} diff --git a/k9mail/src/main/java/com/fsck/k9/ui/settings/account/AutocryptPreferEncryptDialogFragment.kt b/k9mail/src/main/java/com/fsck/k9/ui/settings/account/AutocryptPreferEncryptDialogFragment.kt index 8784bf0e5..65e4c8b78 100644 --- a/k9mail/src/main/java/com/fsck/k9/ui/settings/account/AutocryptPreferEncryptDialogFragment.kt +++ b/k9mail/src/main/java/com/fsck/k9/ui/settings/account/AutocryptPreferEncryptDialogFragment.kt @@ -1,10 +1,17 @@ package com.fsck.k9.ui.settings.account +import android.annotation.SuppressLint import android.app.Dialog import android.os.Bundle import android.support.v4.app.DialogFragment +import android.support.v7.app.AlertDialog import android.support.v7.preference.DialogPreference -import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog +import android.text.method.LinkMovementMethod +import android.view.LayoutInflater +import android.view.View +import android.widget.CheckBox +import android.widget.TextView +import com.fsck.k9.R class AutocryptPreferEncryptDialogFragment : DialogFragment() { private val preference: AutocryptPreferEncryptPreference by lazy { @@ -16,11 +23,30 @@ class AutocryptPreferEncryptDialogFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val autocryptPreferEncryptMutual = preference.isChecked + @SuppressLint("InflateParams") + val view = LayoutInflater.from(context).inflate(R.layout.dialog_autocrypt_prefer_encrypt, null) - return AutocryptPreferEncryptDialog(context, autocryptPreferEncryptMutual) { newValue -> - preference.userChangedValue(newValue) + view.findViewById(R.id.prefer_encrypt_learn_more).makeLinksClickable() + + val preferEncryptCheckbox = view.findViewById(R.id.prefer_encrypt_check).apply { + isChecked = preference.isChecked } + + view.findViewById(R.id.prefer_encrypt).setOnClickListener { + preferEncryptCheckbox.performClick() + preference.userChangedValue(preferEncryptCheckbox.isChecked) + } + + return AlertDialog.Builder(requireContext()) + // TODO add autocrypt logo? + //.setIcon(R.drawable.autocrypt) + .setView(view) + .setPositiveButton(R.string.done_action, null) + .create() + } + + private fun TextView.makeLinksClickable() { + this.movementMethod = LinkMovementMethod.getInstance() }