Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1fd332e authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

use dialog for prefer-encrypt setting

parent d6064753
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import java.util.Map;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
@@ -22,6 +23,8 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.preference.RingtonePreference;
import android.widget.CompoundButton;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

import com.fsck.k9.Account;
@@ -46,6 +49,8 @@ import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.service.MailService;
import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog;
import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog.OnPreferEncryptChangedListener;
import org.openintents.openpgp.util.OpenPgpKeyPreference;
import timber.log.Timber;

@@ -55,6 +60,7 @@ public class AccountSettings extends K9PreferenceActivity {

    private static final int DIALOG_COLOR_PICKER_ACCOUNT = 1;
    private static final int DIALOG_COLOR_PICKER_LED = 2;
    private static final int DIALOG_AUTOCRYPT_PREFER_ENCRYPT = 3;

    private static final int SELECT_AUTO_EXPAND_FOLDER = 1;

@@ -179,7 +185,7 @@ public class AccountSettings extends K9PreferenceActivity {
    private ListPreference mMaxPushFolders;
    private boolean hasPgpCrypto = false;
    private OpenPgpKeyPreference pgpCryptoKey;
    private CheckBoxPreference autocryptPreferEncryptMutual;
    private Preference autocryptPreferEncryptMutual;

    private PreferenceScreen searchScreen;
    private CheckBoxPreference cloudSearchEnabled;
@@ -713,8 +719,14 @@ public class AccountSettings extends K9PreferenceActivity {

            cryptoMenu.setOnPreferenceClickListener(null);

            autocryptPreferEncryptMutual = (CheckBoxPreference) findPreference(PREFERENCE_AUTOCRYPT_PREFER_ENCRYPT);
            autocryptPreferEncryptMutual.setChecked(account.getAutocryptPreferEncryptMutual());
            autocryptPreferEncryptMutual = findPreference(PREFERENCE_AUTOCRYPT_PREFER_ENCRYPT);
            autocryptPreferEncryptMutual.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    showDialog(DIALOG_AUTOCRYPT_PREFER_ENCRYPT);
                    return false;
                }
            });
        } else {
            cryptoMenu.setSummary(R.string.account_settings_no_openpgp_provider_configured);
            cryptoMenu.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -795,7 +807,6 @@ public class AccountSettings extends K9PreferenceActivity {
        } else {
            account.setCryptoKey(Account.NO_OPENPGP_KEY);
        }
        account.setAutocryptPreferEncryptMutual(autocryptPreferEncryptMutual.isChecked());

        // In webdav account we use the exact folder name also for inbox,
        // since it varies because of internationalization
@@ -935,6 +946,16 @@ public class AccountSettings extends K9PreferenceActivity {

                break;
            }
            case DIALOG_AUTOCRYPT_PREFER_ENCRYPT: {
                dialog = new AutocryptPreferEncryptDialog(this, account.getAutocryptPreferEncryptMutual(),
                        new OnPreferEncryptChangedListener() {
                            @Override
                            public void onPreferEncryptChanged(boolean enabled) {
                                account.setAutocryptPreferEncryptMutual(enabled);
                            }
                        });
                break;
            }
        }

        return dialog;
+69 −0
Original line number Diff line number Diff line
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);

        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_NEUTRAL, 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);
    }
}
+57 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="20dp"
            android:text="@string/dialog_autocrypt_mutual_title"
            style="?android:textAppearanceLarge" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:text="@string/dialog_autocrypt_mutual_description_1" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp"
            android:gravity="center_vertical"
            android:minHeight="?android:listPreferredItemHeight"
            android:orientation="horizontal"
            android:background="?android:selectableItemBackground"
            android:id="@+id/prefer_encrypt">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/dialog_autocrypt_mutual_description_2" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/prefer_encrypt_check"
                android:clickable="false"
                />

        </LinearLayout>

    </LinearLayout>

</ScrollView>
+5 −3
Original line number Diff line number Diff line
@@ -1282,7 +1282,9 @@ Please submit bug reports, contribute new features and ask questions at
    <string name="openpgp_enabled_error_back">Back</string>
    <string name="openpgp_enabled_error_disable">Disable Encryption</string>
    <string name="openpgp_encryption">OpenPGP Encryption</string>
    <string name="account_settings_crypto_prefer_encrypt">Encryption preference</string>
    <string name="account_settings_crypto_prefer_encrypt_on">By default when replying to encrypted, or if all recipients also checked this option</string>
    <string name="account_settings_crypto_prefer_encrypt_off">By default, when replying to encrypted messages</string>

    <string name="account_settings_crypto_prefer_encrypt">Autocrypt mutual mode</string>
    <string name="dialog_autocrypt_mutual_title">Autocrypt mutual mode</string>
    <string name="dialog_autocrypt_mutual_description_1">Messages will normally be encrypted by choice, or when replying to an encrypted message.</string>
    <string name="dialog_autocrypt_mutual_description_2">If both sender and recipients enable mutual mode, encryption will be enabled by default.</string>
</resources>
+2 −3
Original line number Diff line number Diff line
@@ -479,12 +479,11 @@
            android:key="crypto_key"
            android:title="@string/account_settings_crypto_key" />

        <CheckBoxPreference
        <Preference
            android:key="autocrypt_prefer_encrypt"
            android:title="@string/account_settings_crypto_prefer_encrypt"
            android:summaryOn="@string/account_settings_crypto_prefer_encrypt_on"
            android:summaryOff="@string/account_settings_crypto_prefer_encrypt_off"
            />

    </PreferenceScreen>

</PreferenceScreen>