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();
}
}
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);
}
}
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());
}
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);
}
}
}
}
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);
}
Aggregations