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

Commit aca7fefc authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Draft support for compose screen

parent 0b1bd25d
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -93,7 +93,10 @@ public enum QKPreference {
    QK_COMPOSE("pref_key_quickcompose", false),

    // LiveViews
    CONVERSATION_THEME("conversation_theme");
    CONVERSATION_THEME("conversation_theme"),

    // Storage
    COMPOSE_DRAFT("compose_draft", "");

    private String mKey;
    private Object mDefaultValue;
+17 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch

        view.findViewById(R.id.compose_view_stub).setVisibility(View.VISIBLE);
        mComposeView = (ComposeView) view.findViewById(R.id.compose_view);
        mComposeView.onOpenConversation(null, null);
        mComposeView.setActivityLauncher(this);
        mComposeView.setRecipientProvider(this);
        mComposeView.setOnSendListener(this);
@@ -168,6 +169,22 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
        }
    }

    @Override
    public void onContentClosed() {
        super.onContentClosed();
        if (mComposeView != null) {
            mComposeView.saveDraft();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mComposeView != null) {
            mComposeView.saveDraft();
        }
    }

    @Override
    public void onMenuChanging(float percentOpen) {

+23 −7
Original line number Diff line number Diff line
@@ -715,7 +715,7 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
        mConversationLegacy = conversationLegacy;

        // If the conversation was different, set up the draft here.
        if (threadId != newThreadId) {
        if (threadId != newThreadId || newThreadId == -1) {
            setupDraft();
        }
    }
@@ -735,9 +735,10 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
    public void saveDraft() {
        // If the conversation_reply view is null, then we won't worry about saving drafts at all. We also don't save
        // drafts if a message is about to be sent (delayed)
        if (mReplyText != null && mConversation != null && mButtonState != SendButtonState.CANCEL) {
        if (mReplyText != null && mButtonState != SendButtonState.CANCEL) {
            String draft = mReplyText.getText().toString();

            if (mConversation != null) {
                if (mConversationLegacy.hasDraft() && TextUtils.isEmpty(draft)) {
                    mConversationLegacy.clearDrafts();

@@ -745,6 +746,17 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
                        (!mConversationLegacy.hasDraft() || !draft.equals(mConversationLegacy.getDraft()))) {
                    mConversationLegacy.saveDraft(draft);
                }
            } else {
                String oldDraft = mPrefs.getString(QKPreference.COMPOSE_DRAFT.getKey(), "");
                if (!draft.equals(oldDraft)) {
                    mPrefs.edit().putString(QKPreference.COMPOSE_DRAFT.getKey(), draft).apply();

                    // Only show the draft if we saved text, not if we just cleared some
                    if (!TextUtils.isEmpty(draft)) {
                        Toast.makeText(mContext, R.string.toast_draft, Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }

    }
@@ -767,6 +779,10 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
                mReplyText.setText("");
                clearAttachment();
            }
        } else {
            String draft = mPrefs.getString(QKPreference.COMPOSE_DRAFT.getKey(), "");
            mReplyText.setText(draft);
            mReplyText.setSelection(draft.length());
        }
    }