Search in sources :

Example 1 with ConversationPrefsHelper

use of com.moez.QKSMS.common.ConversationPrefsHelper 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 2 with ConversationPrefsHelper

use of com.moez.QKSMS.common.ConversationPrefsHelper in project qksms by moezbhatti.

the class MessageListActivity method onActivityResult.

/**
     * When In-App billing is done, it'll return information via onActivityResult().
     */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ConversationSettingsDialog.RINGTONE_REQUEST_CODE) {
        if (data != null) {
            if (mWaitingForThreadId > 0) {
                ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(this, mWaitingForThreadId);
                Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
                conversationPrefs.putString(SettingsFragment.NOTIFICATION_TONE, (uri == null) ? "" : uri.toString());
                mWaitingForThreadId = -1;
            }
        }
    } else if (requestCode == WelcomeActivity.WELCOME_REQUEST_CODE) {
        new DefaultSmsHelper(this, R.string.not_default_first).showIfNotDefault(null);
    }
}
Also used : DefaultSmsHelper(com.moez.QKSMS.ui.dialog.DefaultSmsHelper) Uri(android.net.Uri) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Example 3 with ConversationPrefsHelper

use of com.moez.QKSMS.common.ConversationPrefsHelper in project qksms by moezbhatti.

the class MessageListFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        Bundle args = getArguments();
        mThreadId = args.getLong(MessageListActivity.ARG_THREAD_ID, -1);
        mRowId = args.getLong(MessageListActivity.ARG_ROW_ID, -1);
        mHighlight = args.getString(MessageListActivity.ARG_HIGHLIGHT, null);
        mShowImmediate = args.getBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, false);
    } else if (savedInstanceState != null) {
        mThreadId = savedInstanceState.getLong(MessageListActivity.ARG_THREAD_ID, -1);
        mRowId = savedInstanceState.getLong(MessageListActivity.ARG_ROW_ID, -1);
        mHighlight = savedInstanceState.getString(MessageListActivity.ARG_HIGHLIGHT, null);
        mShowImmediate = savedInstanceState.getBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, false);
    }
    mConversationPrefs = new ConversationPrefsHelper(mContext, mThreadId);
    mIsSmsEnabled = MmsConfig.isSmsEnabled(mContext);
    mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager());
    onOpenConversation();
    setHasOptionsMenu(true);
    LiveViewManager.registerView(QKPreference.CONVERSATION_THEME, this, key -> {
        mCIELChEvaluator = new CIELChEvaluator(mConversationPrefs.getColor(), ThemeManager.getThemeColor());
    });
    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (QKPreferences.getBoolean(QKPreference.PROXIMITY_SENSOR)) {
        mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
    mBackgroundQueryHandler = new BackgroundQueryHandler(mContext.getContentResolver());
}
Also used : CIELChEvaluator(com.moez.QKSMS.common.CIELChEvaluator) Bundle(android.os.Bundle) ConversationDetailsDialog(com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Example 4 with ConversationPrefsHelper

use of com.moez.QKSMS.common.ConversationPrefsHelper in project qksms by moezbhatti.

the class NotificationManager method multipleSenders.

/**
     * Create notifications for multiple conversations
     */
private static void multipleSenders(Context context, HashMap<Long, ArrayList<MessageItem>> conversations, Set<Long> oldThreads, NotificationCompat.Builder builder) {
    Set<Long> threadIds = conversations.keySet();
    for (long threadId : threadIds) {
        if (!oldThreads.contains(threadId)) {
            ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(context, threadId);
            Integer privateNotification = conversationPrefs.getPrivateNotificationsSetting();
            if (conversations.get(threadId).size() == 1) {
                singleMessage(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, privateNotification);
            } else {
                singleSender(context, conversations.get(threadId), threadId, copyBuilder(builder), conversationPrefs, privateNotification);
            }
        }
    }
}
Also used : ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Example 5 with ConversationPrefsHelper

use of com.moez.QKSMS.common.ConversationPrefsHelper in project qksms by moezbhatti.

the class NotificationService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Uri uri = Uri.parse(intent.getStringExtra(EXTRA_URI));
    // Try to get the message's ID, in case the given Uri is bad.
    long messageId = -1;
    Cursor cursor = context.getContentResolver().query(uri, new String[] { SmsHelper.COLUMN_ID }, null, null, null);
    if (cursor.moveToFirst()) {
        messageId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsHelper.COLUMN_ID));
    }
    cursor.close();
    // Make sure we found a message before showing QuickReply and using PushBullet.
    if (messageId != -1) {
        Message message = new Message(context, messageId);
        conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
        if (conversationPrefs.getNotificationsEnabled()) {
            // Only show QuickReply if we're outside of the app, and they have popups and QuickReply enabled.
            if (!LifecycleHandler.isApplicationVisible() && intent.getBooleanExtra(EXTRA_POPUP, false) && prefs.getBoolean(SettingsFragment.QUICKREPLY, Build.VERSION.SDK_INT < 24)) {
                popupIntent = new Intent(context, QKReplyActivity.class);
                popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                popupIntent.putExtra(QKReplyActivity.EXTRA_THREAD_ID, message.getThreadId());
                startActivity(popupIntent);
            }
            // Get the photo for the PushBullet notification.
            Bitmap photoBitmap = message.getPhotoBitmap();
            if (photoBitmap == null) {
                photoBitmap = ContactHelper.blankContact(context, message.getName());
            }
            PushbulletService.mirrorMessage(context, "" + message.getThreadId(), message.getName(), message.getBody(), photoBitmap, null, 6639);
        } else {
            // If the conversation is muted, mark this message as "seen". Note that this is
            // different from marking it as "read".
            message.markSeen();
        }
    }
    stopSelf();
    return super.onStartCommand(intent, flags, startId);
}
Also used : QKReplyActivity(com.moez.QKSMS.ui.popup.QKReplyActivity) Bitmap(android.graphics.Bitmap) Message(com.moez.QKSMS.data.Message) Intent(android.content.Intent) Cursor(android.database.Cursor) Uri(android.net.Uri) ConversationPrefsHelper(com.moez.QKSMS.common.ConversationPrefsHelper)

Aggregations

ConversationPrefsHelper (com.moez.QKSMS.common.ConversationPrefsHelper)8 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Message (com.moez.QKSMS.data.Message)2 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 PowerManager (android.os.PowerManager)1 SmsMessage (android.telephony.SmsMessage)1 LinearLayout (android.widget.LinearLayout)1 CIELChEvaluator (com.moez.QKSMS.common.CIELChEvaluator)1 Conversation (com.moez.QKSMS.data.Conversation)1 ConversationLegacy (com.moez.QKSMS.data.ConversationLegacy)1 NotificationService (com.moez.QKSMS.service.NotificationService)1 DefaultSmsHelper (com.moez.QKSMS.ui.dialog.DefaultSmsHelper)1 ConversationDetailsDialog (com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog)1 QKReplyActivity (com.moez.QKSMS.ui.popup.QKReplyActivity)1 QKPreference (com.moez.QKSMS.ui.view.QKPreference)1 QKRingtonePreference (com.moez.QKSMS.ui.view.QKRingtonePreference)1 QKSwitchPreference (com.moez.QKSMS.ui.view.QKSwitchPreference)1