forked from upstream-mirrors/quik
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
This commit is contained in:
@@ -99,7 +99,6 @@ public enum QKPreference {
|
|||||||
CONVERSATION_THEME("conversation_theme"),
|
CONVERSATION_THEME("conversation_theme"),
|
||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
COMPOSE_DRAFT("compose_draft", ""),
|
|
||||||
LAST_AUTO_DELETE_CHECK("last_auto_delete_check", 0);
|
LAST_AUTO_DELETE_CHECK("last_auto_delete_check", 0);
|
||||||
|
|
||||||
private String mKey;
|
private String mKey;
|
||||||
|
|||||||
@@ -4,8 +4,13 @@ import android.app.FragmentManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
|
import com.moez.QKSMS.mmssms.Utils;
|
||||||
import com.moez.QKSMS.ui.base.QKSwipeBackActivity;
|
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 {
|
public class ComposeActivity extends QKSwipeBackActivity {
|
||||||
|
|
||||||
@@ -32,4 +37,27 @@ public class ComposeActivity extends QKSwipeBackActivity {
|
|||||||
new MenuInflater(this).inflate(R.menu.compose, menu);
|
new MenuInflater(this).inflate(R.menu.compose, menu);
|
||||||
return super.onCreateOptionsMenu(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,4 +105,11 @@ public class ComposeFragment extends QKFragment implements ActivityLauncher, Rec
|
|||||||
mStarredContactsView.collapse();
|
mStarredContactsView.collapse();
|
||||||
mComposeView.requestReplyTextFocus();
|
mComposeView.requestReplyTextFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isReplyTextEmpty() {
|
||||||
|
if (mComposeView != null) {
|
||||||
|
return mComposeView.isReplyTextEmpty();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.animation.ObjectAnimator;
|
|||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -749,13 +750,34 @@ public class ComposeView extends LinearLayout implements View.OnClickListener {
|
|||||||
mConversationLegacy.saveDraft(draft);
|
mConversationLegacy.saveDraft(draft);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String oldDraft = mPrefs.getString(QKPreference.COMPOSE_DRAFT.getKey(), "");
|
// Only show the draft if we saved text, not if we just cleared some
|
||||||
if (!draft.equals(oldDraft)) {
|
if (!TextUtils.isEmpty(draft)) {
|
||||||
mPrefs.edit().putString(QKPreference.COMPOSE_DRAFT.getKey(), draft).apply();
|
if (mRecipientProvider != null) {
|
||||||
|
String[] addresses = mRecipientProvider.getRecipientAddresses();
|
||||||
|
|
||||||
// Only show the draft if we saved text, not if we just cleared some
|
if (addresses != null && addresses.length > 0) {
|
||||||
if (!TextUtils.isEmpty(draft)) {
|
// save the message for each of the addresses
|
||||||
Toast.makeText(mContext, R.string.toast_draft, Toast.LENGTH_SHORT).show();
|
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("");
|
mReplyText.setText("");
|
||||||
clearAttachment();
|
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(),
|
ThemeManager.getTextOnColorPrimary() : ThemeManager.getTextOnColorSecondary(),
|
||||||
PorterDuff.Mode.SRC_ATOP);
|
PorterDuff.Mode.SRC_ATOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isReplyTextEmpty() {
|
||||||
|
return TextUtils.isEmpty(mReplyText.getText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user