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

Commit 6d9532ad authored by Moez Bhatti's avatar Moez Bhatti Committed by GitHub
Browse files

Merge pull request #613 from frogoscar/enmingxie/Fix_Draft_SMS_is_not_saved_in_some_context

Fix Draft SMS is not saved in some context
parents a64fba71 2b7a7583
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ public enum QKPreference {
    CONVERSATION_THEME("conversation_theme"),

    // Storage
    COMPOSE_DRAFT("compose_draft", ""),
    LAST_AUTO_DELETE_CHECK("last_auto_delete_check", 0);

    private String mKey;
+28 −0
Original line number Diff line number Diff line
@@ -4,8 +4,13 @@ import android.app.FragmentManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.ViewGroup;

import com.moez.QKSMS.R;
import com.moez.QKSMS.mmssms.Utils;
import com.moez.QKSMS.ui.base.QKSwipeBackActivity;
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
import com.moez.QKSMS.ui.dialog.QKDialog;

public class ComposeActivity extends QKSwipeBackActivity {

@@ -32,4 +37,27 @@ public class ComposeActivity extends QKSwipeBackActivity {
        new MenuInflater(this).inflate(R.menu.compose, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void onBackPressed() {
        // Check if we're not the default SMS app
        if (!Utils.isDefaultSmsApp(this)) {
            // Ask to become the default SMS app
            new DefaultSmsHelper(this, R.string.not_default_send)
                    .showIfNotDefault((ViewGroup)getWindow().getDecorView().getRootView());
        } else if (mComposeFragment != null && !mComposeFragment.isReplyTextEmpty()
                && mComposeFragment.getRecipientAddresses().length == 0) {
            // If there is Draft message and no recipients are set
            new QKDialog()
                    .setContext(this)
                    .setMessage(R.string.discard_message_reason)
                    .setPositiveButton(R.string.yes, v -> {
                        super.onBackPressed();
                    })
                    .setNegativeButton(R.string.cancel, null)
                    .show();
        } else {
            super.onBackPressed();
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -105,4 +105,11 @@ public class ComposeFragment extends QKFragment implements ActivityLauncher, Rec
        mStarredContactsView.collapse();
        mComposeView.requestReplyTextFocus();
    }

    public boolean isReplyTextEmpty() {
        if (mComposeView != null) {
            return mComposeView.isReplyTextEmpty();
        }
        return true;
    }
}
+32 −10
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -749,13 +750,34 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
                    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();
                    if (mRecipientProvider != null) {
                        String[] addresses = mRecipientProvider.getRecipientAddresses();

                        if (addresses != null && addresses.length > 0) {
                            // save the message for each of the addresses
                            for (int i = 0; i < addresses.length; i++) {
                                ContentValues values = new ContentValues();
                                values.put("address", addresses[i]);
                                values.put("date", System.currentTimeMillis());
                                values.put("read", 1);
                                values.put("type", 4);

                                // attempt to create correct thread id
                                long threadId = Utils.getOrCreateThreadId(mContext, addresses[i]);

                                Log.v(TAG, "saving message with thread id: " + threadId);

                                values.put("thread_id", threadId);
                                Uri messageUri = mContext.getContentResolver().insert(Uri.parse("content://sms/draft"), values);

                                Log.v(TAG, "inserted to uri: " + messageUri);

                                ConversationLegacy mConversationLegacy = new ConversationLegacy(mContext, threadId);
                                mConversationLegacy.saveDraft(draft);
                            }
                        }
                    }
                }
            }
@@ -781,10 +803,6 @@ 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());
        }
    }

@@ -1010,4 +1028,8 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
                        ThemeManager.getTextOnColorPrimary() : ThemeManager.getTextOnColorSecondary(),
                PorterDuff.Mode.SRC_ATOP);
    }

    public boolean isReplyTextEmpty() {
        return TextUtils.isEmpty(mReplyText.getText());
    }
}