Search in sources :

Example 1 with Message

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;
}
Also used : Message(com.moez.QKSMS.data.Message) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MmsException(com.google.android.mms.MmsException)

Example 2 with Message

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();
}
Also used : Message(com.moez.QKSMS.data.Message)

Example 3 with Message

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();
    }
}
Also used : PowerManager(android.os.PowerManager) SmsMessage(android.telephony.SmsMessage) Message(com.moez.QKSMS.data.Message) Intent(android.content.Intent) NotificationService(com.moez.QKSMS.service.NotificationService) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Example 4 with Message

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;
}
Also used : Telephony(android.provider.Telephony) MessageListRecyclerView(com.moez.QKSMS.ui.view.MessageListRecyclerView) SensorManager(android.hardware.SensorManager) Bundle(android.os.Bundle) MmsConfig(com.moez.QKSMS.MmsConfig) Conversation(com.moez.QKSMS.data.Conversation) ConversationDetailsDialog(com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog) Ezvcard(ezvcard.Ezvcard) Uri(android.net.Uri) ContactOperations(com.moez.QKSMS.common.vcard.ContactOperations) ComposeView(com.moez.QKSMS.ui.view.ComposeView) WidgetProvider(com.moez.QKSMS.ui.widget.WidgetProvider) SQLiteException(android.database.sqlite.SQLiteException) ContentResolver(android.content.ContentResolver) LiveViewManager(com.moez.QKSMS.common.LiveViewManager) View(android.view.View) SensorEventListener(android.hardware.SensorEventListener) Contact(com.moez.QKSMS.data.Contact) AdapterView(android.widget.AdapterView) QKSMSApp(com.moez.QKSMS.QKSMSApp) Log(android.util.Log) DeliveryReportItem(com.moez.QKSMS.ui.delivery.DeliveryReportItem) LogTag(com.moez.QKSMS.LogTag) AsyncTask(android.os.AsyncTask) ContactList(com.moez.QKSMS.data.ContactList) IntegerRes(android.support.annotation.IntegerRes) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) MessageUtils(com.moez.QKSMS.common.utils.MessageUtils) Loader(android.content.Loader) ContentType(com.google.android.mms.ContentType) SettingsFragment(com.moez.QKSMS.ui.settings.SettingsFragment) QKPreferences(com.moez.QKSMS.common.QKPreferences) Context(android.content.Context) QKPreference(com.moez.QKSMS.enums.QKPreference) RecyclerCursorAdapter(com.moez.QKSMS.ui.base.RecyclerCursorAdapter) Intent(android.content.Intent) Linkify(android.text.util.Linkify) MainActivity(com.moez.QKSMS.ui.MainActivity) MenuItem(android.view.MenuItem) KeyboardUtils(com.moez.QKSMS.common.utils.KeyboardUtils) ActivityLauncher(com.moez.QKSMS.interfaces.ActivityLauncher) ArrayList(java.util.ArrayList) R(com.moez.QKSMS.R) HashSet(java.util.HashSet) R.attr.data(android.R.attr.data) SensorEvent(android.hardware.SensorEvent) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) QKFragment(com.moez.QKSMS.ui.base.QKFragment) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) Sensor(android.hardware.Sensor) DialogHelper(com.moez.QKSMS.common.DialogHelper) LoaderManager(android.app.LoaderManager) CursorLoader(android.content.CursorLoader) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) VCard(ezvcard.VCard) URLSpan(android.text.style.URLSpan) ThemeManager(com.moez.QKSMS.ui.ThemeManager) SmoothLinearLayoutManager(com.moez.QKSMS.ui.view.SmoothLinearLayoutManager) SpannableString(android.text.SpannableString) LayoutInflater(android.view.LayoutInflater) CIELChEvaluator(com.moez.QKSMS.common.CIELChEvaluator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) NotificationManager(com.moez.QKSMS.transaction.NotificationManager) ConversationLegacy(com.moez.QKSMS.data.ConversationLegacy) RecyclerView(android.support.v7.widget.RecyclerView) DeliveryReportHelper(com.moez.QKSMS.ui.delivery.DeliveryReportHelper) SwipeBackLayout(com.moez.QKSMS.ui.SwipeBackLayout) SmsHelper(com.moez.QKSMS.transaction.SmsHelper) AsyncDialog(com.moez.QKSMS.ui.dialog.AsyncDialog) ConversationSettingsDialog(com.moez.QKSMS.ui.dialog.ConversationSettingsDialog) SqliteWrapper(android.database.sqlite.SqliteWrapper) Vibrator(android.os.Vibrator) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper) ContentUris(android.content.ContentUris) Message(com.moez.QKSMS.data.Message) QKDialog(com.moez.QKSMS.ui.dialog.QKDialog) Cursor(android.database.Cursor)

Example 5 with Message

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;
}
Also used : Message(com.moez.QKSMS.data.Message) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MessageColumns(com.moez.QKSMS.ui.messagelist.MessageColumns) MmsException(com.google.android.mms.MmsException)

Aggregations

Message (com.moez.QKSMS.data.Message)8 Cursor (android.database.Cursor)5 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 MmsException (com.google.android.mms.MmsException)3 ConversationPrefsHelper (com.moez.QKSMS.common.ConversationPrefsHelper)3 R.attr.data (android.R.attr.data)1 AlertDialog (android.app.AlertDialog)1 LoaderManager (android.app.LoaderManager)1 ContentResolver (android.content.ContentResolver)1 ContentUris (android.content.ContentUris)1 Context (android.content.Context)1 CursorLoader (android.content.CursorLoader)1 DialogInterface (android.content.DialogInterface)1 Loader (android.content.Loader)1 SQLiteException (android.database.sqlite.SQLiteException)1 SqliteWrapper (android.database.sqlite.SqliteWrapper)1 Bitmap (android.graphics.Bitmap)1 Sensor (android.hardware.Sensor)1