Don't show notifications from blocked contacts

This commit is contained in:
Moez Bhatti
2015-09-17 22:48:55 -04:00
parent 87f4d31745
commit 43a5d443f1
2 changed files with 13 additions and 1 deletions
@@ -44,6 +44,15 @@ public class BlockedConversationHelper {
prefs.edit().putStringSet(SettingsFragment.BLOCKED_SENDERS, idStrings2).apply();
}
public static Set<Long> getBlockedConversationIds(SharedPreferences prefs) {
Set<String> conversations = getBlockedConversations(prefs);
Set<Long> ids = new HashSet<>();
for (String id : conversations) {
ids.add(Long.parseLong(id));
}
return ids;
}
public static Set<String> getBlockedConversations(SharedPreferences prefs) {
return prefs.getStringSet(SettingsFragment.BLOCKED_SENDERS, new HashSet<String>());
}
@@ -5,8 +5,10 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import android.util.Log;
import com.moez.QKSMS.common.BlockedConversationHelper;
import com.moez.QKSMS.common.ConversationPrefsHelper;
import com.moez.QKSMS.data.Message;
import com.moez.QKSMS.service.NotificationService;
@@ -54,7 +56,8 @@ public class MessagingReceiver extends BroadcastReceiver {
Message message = new Message(context, uri);
ConversationPrefsHelper prefs = new ConversationPrefsHelper(context, message.getThreadId());
if (prefs.getNotificationsEnabled()) {
if (prefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(
PreferenceManager.getDefaultSharedPreferences(context)).contains(message.getThreadId())) {
Intent messageHandlerIntent = new Intent(context, NotificationService.class);
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, uri.toString());