use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.
the class SmsHelper method deleteFailedMessages.
public static List<Message> deleteFailedMessages(Context context, long threadId) {
Log.d(TAG, "Deleting failed messages");
Cursor cursor = null;
List<Message> messages = new ArrayList<>();
try {
cursor = context.getContentResolver().query(SMS_CONTENT_PROVIDER, new String[] { COLUMN_ID }, FAILED_SELECTION, null, sortDateDesc);
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
messages.add(new Message(context, cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID))));
cursor.moveToNext();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
for (Message m : messages) {
if (m.getThreadId() == threadId) {
Log.d(TAG, "Deleting failed message to " + m.getName() + "\n Body: " + m.getBody());
m.delete();
}
}
return messages;
}
use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.
the class SmsHelper method getUnreadMessageText.
public static String getUnreadMessageText(Context context, Uri threadUri) {
StringBuilder builder = new StringBuilder();
ArrayList<Message> messages = SmsHelper.getUnreadMessagesLegacy(context, threadUri);
for (int i = 0; i < messages.size(); i++) {
Message message = messages.get(i);
builder.append(message.getBody());
if (i < messages.size() - 1) {
builder.append("\n\n");
}
}
return builder.toString();
}
use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.
the class MessagingReceiver method insertMessageAndNotify.
private void insertMessageAndNotify() {
mUri = SmsHelper.addMessageToInbox(mContext, mAddress, mBody, mDate);
Message message = new Message(mContext, mUri);
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(mContext, message.getThreadId());
// we can block it, so that the conversation list adapter knows to ignore this thread in the main list
if (BlockedConversationHelper.isFutureBlocked(mPrefs, mAddress)) {
BlockedConversationHelper.unblockFutureConversation(mPrefs, mAddress);
BlockedConversationHelper.blockConversation(mPrefs, message.getThreadId());
message.markSeen();
BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().futureBlockedConversationReceived();
// If we have notifications enabled and this conversation isn't blocked
} else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(PreferenceManager.getDefaultSharedPreferences(mContext)).contains(message.getThreadId())) {
Intent messageHandlerIntent = new Intent(mContext, NotificationService.class);
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, mUri.toString());
mContext.startService(messageHandlerIntent);
UnreadBadgeService.update(mContext);
NotificationManager.create(mContext);
} else {
// We shouldn't show a notification for this message
message.markSeen();
}
if (conversationPrefs.getWakePhoneEnabled()) {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
wakeLock.acquire();
wakeLock.release();
}
}
use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.
the class MessageListFragment method showMessageResendOptions.
private boolean showMessageResendOptions(final MessageItem msgItem) {
final Cursor cursor = mAdapter.getCursorForItem(msgItem);
if (cursor == null) {
return false;
}
KeyboardUtils.hide(mContext, mComposeView);
new QKDialog().setContext(mContext).setTitle(R.string.failed_message_title).setItems(R.array.resend_menu, (parent, view, position, id) -> {
switch(position) {
case // Resend message
0:
resendMessageItem(msgItem);
break;
case // Edit message
1:
editMessageItem(msgItem);
break;
case // Delete message
2:
confirmDeleteDialog(new DeleteMessageListener(msgItem), false);
break;
}
}).show();
return true;
}
use of com.moez.QKSMS.data.Message in project qksms by moezbhatti.
the class SmsHelper method getUnreadMessagesLegacy.
/**
* @return A list of unread messages to be deleted by QKReply
*/
public static ArrayList<Message> getUnreadMessagesLegacy(Context context, Uri threadUri) {
ArrayList<Message> result = new ArrayList<>();
if (threadUri != null) {
Cursor messageCursor = context.getContentResolver().query(threadUri, MessageColumns.PROJECTION, UNREAD_SELECTION, null, SmsHelper.sortDateAsc);
MessageColumns.ColumnsMap columnsMap = new MessageColumns.ColumnsMap(messageCursor);
if (messageCursor.moveToFirst()) {
do {
try {
Message message = new Message(context, messageCursor.getLong(columnsMap.mColumnMsgId));
result.add(message);
} catch (Exception e) {
e.printStackTrace();
}
} while (messageCursor.moveToNext());
}
messageCursor.close();
}
return result;
}
Aggregations