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

Commit 677ef154 authored by cketti's avatar cketti
Browse files

Remove now unused `CryptoInfoDialog`

parent 80c68e1e
Loading
Loading
Loading
Loading
+0 −140
Original line number Diff line number Diff line
package com.fsck.k9.ui.messageview;


import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.fsck.k9.ui.R;
import com.fsck.k9.view.MessageCryptoDisplayStatus;
import com.fsck.k9.view.ThemeUtils;


public class CryptoInfoDialog extends DialogFragment {
    public static final String ARG_DISPLAY_STATUS = "display_status";
    public static final String ARG_HAS_SECURITY_WARNING = "has_security_warning";


    private ImageView statusIcon;
    private TextView titleText;
    private TextView descriptionText;


    public static CryptoInfoDialog newInstance(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning) {
        CryptoInfoDialog frag = new CryptoInfoDialog();

        Bundle args = new Bundle();
        args.putString(ARG_DISPLAY_STATUS, displayStatus.toString());
        args.putBoolean(ARG_HAS_SECURITY_WARNING, hasSecurityWarning);
        frag.setArguments(args);

        return frag;
    }

    @SuppressLint("InflateParams") // inflating without root element is fine for creating a dialog
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Builder b = new AlertDialog.Builder(getActivity());

        View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.message_crypto_info_dialog, null);

        statusIcon = dialogView.findViewById(R.id.crypto_info_top_icon_1);
        titleText = dialogView.findViewById(R.id.crypto_info_title);
        descriptionText = dialogView.findViewById(R.id.crypto_info_text);

        MessageCryptoDisplayStatus displayStatus =
                MessageCryptoDisplayStatus.valueOf(getArguments().getString(ARG_DISPLAY_STATUS));
        setMessageForDisplayStatus(displayStatus);

        b.setView(dialogView);
        b.setPositiveButton(R.string.crypto_info_ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dismiss();
            }
        });
        boolean hasSecurityWarning = getArguments().getBoolean(ARG_HAS_SECURITY_WARNING);
        if (hasSecurityWarning) {
            b.setNeutralButton(R.string.crypto_info_view_security_warning, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Fragment frag = getTargetFragment();
                    if (!(frag instanceof OnClickShowCryptoKeyListener)) {
                        throw new AssertionError("Displaying activity must implement OnClickShowCryptoKeyListener!");
                    }
                    ((OnClickShowCryptoKeyListener) frag).onClickShowSecurityWarning();
                }
            });
        } else if (displayStatus.isUnknownKey()) {
            b.setNeutralButton(R.string.crypto_info_search_key, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Fragment frag = getTargetFragment();
                    if (! (frag instanceof OnClickShowCryptoKeyListener)) {
                        throw new AssertionError("Displaying activity must implement OnClickShowCryptoKeyListener!");
                    }
                    ((OnClickShowCryptoKeyListener) frag).onClickSearchKey();
                }
            });
        } else if (displayStatus.hasAssociatedKey()) {
            int buttonLabel = displayStatus.isUnencryptedSigned() ?
                    R.string.crypto_info_view_signer : R.string.crypto_info_view_sender;
            b.setNeutralButton(buttonLabel, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Fragment frag = getTargetFragment();
                    if (! (frag instanceof OnClickShowCryptoKeyListener)) {
                        throw new AssertionError("Displaying activity must implement OnClickShowCryptoKeyListener!");
                    }
                    ((OnClickShowCryptoKeyListener) frag).onClickShowCryptoKey();
                }
            });
        }

        return b.create();
    }

    private void setMessageForDisplayStatus(MessageCryptoDisplayStatus displayStatus) {
        if (displayStatus.getTitleTextRes() == null) {
            throw new AssertionError("Crypto info dialog can only be displayed for items with text!");
        }

        setMessageSingleLine(displayStatus.getColorAttr(), displayStatus.getTitleTextRes(),
                displayStatus.getDescriptionTextRes(), displayStatus.getStatusIconRes());
    }

    private void setMessageSingleLine(@AttrRes int colorAttr, @StringRes int titleTextRes,
            @StringRes Integer descTextRes, @DrawableRes int statusIconRes) {
        @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr);

        statusIcon.setImageResource(statusIconRes);
        statusIcon.setColorFilter(color);
        titleText.setText(titleTextRes);
        if (descTextRes != null) {
            descriptionText.setText(descTextRes);
            descriptionText.setVisibility(View.VISIBLE);
        } else {
            descriptionText.setVisibility(View.GONE);
        }
    }

    public interface OnClickShowCryptoKeyListener {
        void onClickShowCryptoKey();
        void onClickShowSecurityWarning();
        void onClickSearchKey();
    }
}
+1 −36
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import timber.log.Timber;


@SuppressWarnings("WeakerAccess")
public class MessageCryptoPresenter implements OnCryptoClickListener {
public class MessageCryptoPresenter {
    public static final int REQUEST_CODE_UNKNOWN_KEY = 123;
    public static final int REQUEST_CODE_SECURITY_WARNING = 124;

@@ -100,23 +100,6 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
        return true;
    }

    @Override
    public void onCryptoClick() {
        if (cryptoResultAnnotation == null) {
            return;
        }
        MessageCryptoDisplayStatus displayStatus =
                MessageCryptoDisplayStatus.fromResultAnnotation(cryptoResultAnnotation);
        switch (displayStatus) {
            case LOADING:
                // no need to do anything, there is a progress bar...
                break;
            default:
                displayCryptoInfoDialog(displayStatus);
                break;
        }
    }

    @SuppressWarnings("UnusedParameters") // for consistency with Activity.onActivityResult
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_UNKNOWN_KEY) {
@@ -132,11 +115,6 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
        }
    }

    private void displayCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus) {
        messageCryptoMvpView.showCryptoInfoDialog(
                displayStatus, cryptoResultAnnotation.hasOpenPgpInsecureWarningPendingIntent());
    }

    void onClickSearchKey() {
        try {
            PendingIntent pendingIntent = cryptoResultAnnotation.getOpenPgpSigningKeyIntentIfAny();
@@ -149,18 +127,6 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
        }
    }

    public void onClickShowCryptoKey() {
        try {
            PendingIntent pendingIntent = cryptoResultAnnotation.getOpenPgpSigningKeyIntentIfAny();
            if (pendingIntent != null) {
                messageCryptoMvpView.startPendingIntentForCryptoPresenter(
                        pendingIntent.getIntentSender(), null, null, 0, 0, 0);
            }
        } catch (IntentSender.SendIntentException e) {
            Timber.e(e, "SendIntentException");
        }
    }

    public void onClickRetryCryptoOperation() {
        messageCryptoMvpView.restartMessageCryptoProcessing();
    }
@@ -208,7 +174,6 @@ public class MessageCryptoPresenter implements OnCryptoClickListener {
        void startPendingIntentForCryptoPresenter(IntentSender si, Integer requestCode, Intent fillIntent,
                int flagsMask, int flagValues, int extraFlags) throws IntentSender.SendIntentException;

        void showCryptoInfoDialog(MessageCryptoDisplayStatus displayStatus, boolean hasSecurityWarning);
        void showCryptoConfigDialog();
    }
}
+3 −24
Original line number Diff line number Diff line
@@ -48,12 +48,10 @@ import com.fsck.k9.ui.base.ThemeManager
import com.fsck.k9.ui.choosefolder.ChooseFolderActivity
import com.fsck.k9.ui.messagedetails.MessageDetailsFragment
import com.fsck.k9.ui.messagesource.MessageSourceActivity
import com.fsck.k9.ui.messageview.CryptoInfoDialog.OnClickShowCryptoKeyListener
import com.fsck.k9.ui.messageview.MessageCryptoPresenter.MessageCryptoMvpView
import com.fsck.k9.ui.settings.account.AccountSettingsActivity
import com.fsck.k9.ui.share.ShareIntentBuilder
import com.fsck.k9.ui.withArguments
import com.fsck.k9.view.MessageCryptoDisplayStatus
import java.util.Locale
import org.koin.android.ext.android.inject
import timber.log.Timber
@@ -61,8 +59,7 @@ import timber.log.Timber
class MessageViewFragment :
    Fragment(),
    ConfirmationDialogFragmentListener,
    AttachmentViewCallback,
    OnClickShowCryptoKeyListener {
    AttachmentViewCallback {

    private val themeManager: ThemeManager by inject()
    private val messageLoaderHelperFactory: MessageLoaderHelperFactory by inject()
@@ -585,10 +582,10 @@ class MessageViewFragment :
    private fun onMessageDetailsResult(requestKey: String, result: Bundle) {
        when (val action = result.getString(MessageDetailsFragment.RESULT_ACTION)) {
            MessageDetailsFragment.ACTION_SEARCH_KEYS -> {
                onClickSearchKey()
                messageCryptoPresenter.onClickSearchKey()
            }
            MessageDetailsFragment.ACTION_SHOW_WARNING -> {
                onClickShowSecurityWarning()
                messageCryptoPresenter.onClickShowCryptoWarningDetails()
            }
            else -> {
                error("Unsupported action: $action")
@@ -834,12 +831,6 @@ class MessageViewFragment :
            )
        }

        override fun showCryptoInfoDialog(displayStatus: MessageCryptoDisplayStatus, hasSecurityWarning: Boolean) {
            val dialog = CryptoInfoDialog.newInstance(displayStatus, hasSecurityWarning)
            dialog.setTargetFragment(this@MessageViewFragment, 0)
            dialog.show(parentFragmentManager, "crypto_info_dialog")
        }

        override fun restartMessageCryptoProcessing() {
            messageTopView.setToLoadingState()
            messageLoaderHelper.asyncRestartMessageCryptoProcessing()
@@ -850,18 +841,6 @@ class MessageViewFragment :
        }
    }

    override fun onClickShowSecurityWarning() {
        messageCryptoPresenter.onClickShowCryptoWarningDetails()
    }

    override fun onClickSearchKey() {
        messageCryptoPresenter.onClickSearchKey()
    }

    override fun onClickShowCryptoKey() {
        messageCryptoPresenter.onClickShowCryptoKey()
    }

    interface MessageViewFragmentListener {
        fun onForward(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
        fun onForwardAsAttachment(messageReference: MessageReference, decryptionResultForReply: Parcelable?)
+0 −6
Original line number Diff line number Diff line
package com.fsck.k9.ui.messageview;


public interface OnCryptoClickListener {
    void onCryptoClick();
}