use of com.moez.QKSMS.data.ConversationLegacy in project qksms by moezbhatti.
the class QKReplyActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
sThreadId = extras.getLong(EXTRA_THREAD_ID);
mConversation = Conversation.get(this, sThreadId, false);
mConversationLegacy = new ConversationLegacy(this, sThreadId);
mConversationPrefsHelper = new ConversationPrefsHelper(this, sThreadId);
// Set up the compose view.
mComposeView = (ComposeView) findViewById(R.id.compose_view);
mComposeView.setActivityLauncher(this);
mComposeView.setOnSendListener(this);
mComposeView.setLabel("QKReply");
mAdapter = new QKReplyAdapter(this);
mListView = (ListView) findViewById(R.id.popup_messages);
mListView.setAdapter(mAdapter);
// Set the conversation data objects. These are used to save drafts, send sms messages, etc.
mComposeView.onOpenConversation(mConversation, mConversationLegacy);
// requesting the focus on the reply text.
if (extras.getBoolean(EXTRA_SHOW_KEYBOARD, false)) {
mComposeView.requestReplyTextFocus();
}
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mConversationLegacy.getName(true);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
setTitle(mConversationLegacy.getName(true));
initLoaderManager();
}
}.execute((Void[]) null);
}
use of com.moez.QKSMS.data.ConversationLegacy in project qksms by moezbhatti.
the class ConversationListFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_blocked:
setShowingBlocked(!mShowBlocked);
return true;
case R.id.menu_delete:
DialogHelper.showDeleteConversationsDialog((MainActivity) mContext, mAdapter.getSelectedItems().keySet());
mAdapter.disableMultiSelectMode(true);
return true;
case R.id.menu_mark_read:
for (long threadId : mAdapter.getSelectedItems().keySet()) {
if (getUnreadWeight() >= 0) {
new ConversationLegacy(mContext, threadId).markRead();
} else {
new ConversationLegacy(mContext, threadId).markUnread();
}
}
mAdapter.disableMultiSelectMode(true);
return true;
case R.id.menu_block:
for (long threadId : mAdapter.getSelectedItems().keySet()) {
if (getBlockedWeight() > 0) {
BlockedConversationHelper.unblockConversation(mPrefs, threadId);
} else {
BlockedConversationHelper.blockConversation(mPrefs, threadId);
}
}
mAdapter.disableMultiSelectMode(true);
initLoaderManager();
return true;
case R.id.menu_delete_failed:
DialogHelper.showDeleteFailedMessagesDialog((MainActivity) mContext, mAdapter.getSelectedItems().keySet());
mAdapter.disableMultiSelectMode(true);
return true;
case R.id.menu_done:
mAdapter.disableMultiSelectMode(true);
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.moez.QKSMS.data.ConversationLegacy in project qksms by moezbhatti.
the class ConversationListViewHolder method onUpdate.
@Override
public void onUpdate(final Contact updated) {
boolean shouldUpdate = true;
final Drawable drawable;
final String name;
if (mData.getRecipients().size() == 1) {
Contact contact = mData.getRecipients().get(0);
if (contact.getNumber().equals(updated.getNumber())) {
drawable = contact.getAvatar(mContext, null);
name = contact.getName();
if (contact.existsInDatabase()) {
mAvatarView.assignContactUri(contact.getUri());
} else {
mAvatarView.assignContactFromPhone(contact.getNumber(), true);
}
} else {
// onUpdate was called because *some* contact was loaded, but it wasn't the contact for this
// conversation, and thus we shouldn't update the UI because we won't be able to set the correct data
drawable = null;
name = "";
shouldUpdate = false;
}
} else if (mData.getRecipients().size() > 1) {
drawable = null;
name = "" + mData.getRecipients().size();
mAvatarView.assignContactUri(null);
} else {
drawable = null;
name = "#";
mAvatarView.assignContactUri(null);
}
final ConversationLegacy conversationLegacy = new ConversationLegacy(mContext, mData.getThreadId());
if (shouldUpdate) {
mContext.runOnUiThread(() -> {
mAvatarView.setImageDrawable(drawable);
mAvatarView.setContactName(name);
fromView.setText(formatMessage(mData, conversationLegacy));
});
}
}
use of com.moez.QKSMS.data.ConversationLegacy in project qksms by moezbhatti.
the class ComposeView method saveDraft.
/**
* Saves a draft to the conversation.
*/
public void saveDraft() {
// drafts if a message is about to be sent (delayed)
if (mReplyText != null && mButtonState != SendButtonState.CANCEL) {
String draft = mReplyText.getText().toString();
if (mConversation != null) {
if (mConversationLegacy.hasDraft() && TextUtils.isEmpty(draft)) {
mConversationLegacy.clearDrafts();
} else if (!TextUtils.isEmpty(draft) && (!mConversationLegacy.hasDraft() || !draft.equals(mConversationLegacy.getDraft()))) {
mConversationLegacy.saveDraft(draft);
}
} else {
// Only show the draft if we saved text, not if we just cleared some
if (!TextUtils.isEmpty(draft)) {
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);
}
}
}
}
}
}
}
Aggregations