Repository: thunderbird/thunderbird-android
File: legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageCompose.java (Java)

Code before:

                    messagingController.deleteDraft(previousAccount, previousDraftId);
                }
            } else {
                this.account = account;
            }

            // Show CC/BCC text input field when switching to an account that always wants them
            // displayed.
            // Please note that we're not hiding the fields if the user switches back to an account
            // that doesn't have this setting checked.
            recipientPresenter.onSwitchAccount(this.account);
            quotedMessagePresenter.onSwitchAccount(this.account);

            // not sure how to handle mFolder, mSourceMessage?
        }

        switchToIdentity(identity);
    }

    private void openCamera() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(getPackageManager()) != null) {
            photoUri = captureImageFileWriter.getFileUri();
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
        }
    }

    private Boolean hasCameraPermission()  {
        int hasPermission = ContextCompat.checkSelfPermission(this, permission.CAMERA);
        return hasPermission == PackageManager.PERMISSION_GRANTED;
    }

    private void requestCameraPermission() {
        ActivityCompat.requestPermissions(this, new String[] { permission.CAMERA }, CAMERA_PERMISSION_REQUEST_CODE);
    }

    private void showPopupMenu(View view) {
        PopupMenu popup = new PopupMenu(this, view);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.message_attachment_option, popup.getMenu());

        // Set Material 3 Style
        MaterialShapeDrawable background = new MaterialShapeDrawable();
        background.setShapeAppearanceModel(
            ShapeAppearanceModel.builder()
                .setAllCornerSizes(20f)
                .build()
        );

Review comment (refactor):
I think we should move this logic to the `AttachmentPresenter`, the same way we do with usual attachments.

Code after:
            // Show CC/BCC text input field when switching to an account that always wants them
            // displayed.
            // Please note that we're not hiding the fields if the user switches back to an account
            // that doesn't have this setting checked.
            recipientPresenter.onSwitchAccount(this.account);
            quotedMessagePresenter.onSwitchAccount(this.account);

            // not sure how to handle mFolder, mSourceMessage?
        }

        switchToIdentity(identity);
    }

    private void showPopupMenu(View view) {
        PopupMenu popup = new PopupMenu(this, view);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.message_attachment_option, popup.getMenu());
        popup.getMenu().findItem(R.id.open_camera).setVisible(cameraCaptureHandler.canLaunchCamera(this));
        popup.setOnMenuItemClickListener(item -> {
            int itemId = item.getItemId();
            if (itemId == R.id.open_camera) {
                if(!cameraCaptureHandler.hasCameraPermission(this)){
                    cameraCaptureHandler.requestCameraPermission(this);
                }else {
                    cameraCaptureHandler.openCamera(this);
                }
                return true;
            } else if (itemId == R.id.attach_file) {
                attachmentPresenter.onClickAddAttachment(recipientPresenter);
                return true;
            }
            return false;
        });
        popup.show();
    }

    private void switchToIdentity(Identity identity) {
        this.identity = identity;
        identityChanged = true;
        changesMadeSinceLastSave = true;
        updateFrom();
        updateSignature();
        updateMessageFormat();
        replyToPresenter.setIdentity(identity);
        recipientPresenter.onSwitchIdentity();
    }

    private void updateFrom() {
        chooseIdentityView.setText(identity.getEmail());
    }