Merge AutocryptPreferEncryptDialog into AutocryptPreferEncryptDialogFragment

This commit is contained in:
cketti 2018-05-21 04:04:29 +02:00
parent 5eee669468
commit 6863c4ca27
2 changed files with 30 additions and 80 deletions

View file

@ -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());
}
}

View file

@ -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<TextView>(R.id.prefer_encrypt_learn_more).makeLinksClickable()
val preferEncryptCheckbox = view.findViewById<CheckBox>(R.id.prefer_encrypt_check).apply {
isChecked = preference.isChecked
}
view.findViewById<View>(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()
}