forked from upstream-mirrors/quik
Added dialog to block phone numbers before they're received
This commit is contained in:
@@ -9,6 +9,7 @@ import android.provider.Telephony;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.utils.PhoneNumberUtils;
|
||||
import com.moez.QKSMS.data.Conversation;
|
||||
import com.moez.QKSMS.data.Message;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
@@ -53,6 +54,32 @@ public class BlockedConversationHelper {
|
||||
return prefs.getStringSet(SettingsFragment.BLOCKED_SENDERS, new HashSet<String>());
|
||||
}
|
||||
|
||||
public static void blockFutureConversation(SharedPreferences prefs, String address) {
|
||||
Set<String> idStrings = prefs.getStringSet(SettingsFragment.BLOCKED_FUTURE, new HashSet<String>());
|
||||
idStrings.add(address);
|
||||
prefs.edit().putStringSet(SettingsFragment.BLOCKED_FUTURE, idStrings).apply();
|
||||
}
|
||||
|
||||
public static void unblockFutureConversation(SharedPreferences prefs, String address) {
|
||||
Set<String> idStrings2 = prefs.getStringSet(SettingsFragment.BLOCKED_FUTURE, new HashSet<String>());
|
||||
idStrings2.remove(address);
|
||||
prefs.edit().putStringSet(SettingsFragment.BLOCKED_FUTURE, idStrings2).apply();
|
||||
}
|
||||
|
||||
public static Set<String> getFutureBlockedConversations(SharedPreferences prefs) {
|
||||
return prefs.getStringSet(SettingsFragment.BLOCKED_FUTURE, new HashSet<String>());
|
||||
}
|
||||
|
||||
public static boolean isFutureBlocked(SharedPreferences prefs, String address) {
|
||||
for (String s : getFutureBlockedConversations(prefs)) {
|
||||
if (PhoneNumberUtils.compareLoosely(s, address)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String[] getBlockedConversationArray(SharedPreferences prefs) {
|
||||
Set<String> idStrings = getBlockedConversations(prefs);
|
||||
return idStrings.toArray(new String[idStrings.size()]);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.moez.QKSMS.receiver;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
@@ -54,9 +55,15 @@ public class MessagingReceiver extends BroadcastReceiver {
|
||||
uri = SmsHelper.addMessageToInbox(context, address, body, date);
|
||||
|
||||
Message message = new Message(context, uri);
|
||||
ConversationPrefsHelper prefs = new ConversationPrefsHelper(context, message.getThreadId());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
|
||||
|
||||
if (prefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(
|
||||
if (BlockedConversationHelper.isFutureBlocked(prefs, address)) {
|
||||
BlockedConversationHelper.unblockFutureConversation(prefs, address);
|
||||
BlockedConversationHelper.blockConversation(prefs, message.getThreadId());
|
||||
message.markSeen();
|
||||
|
||||
} else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(
|
||||
PreferenceManager.getDefaultSharedPreferences(context)).contains(message.getThreadId())) {
|
||||
Intent messageHandlerIntent = new Intent(context, NotificationService.class);
|
||||
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
|
||||
@@ -69,7 +76,7 @@ public class MessagingReceiver extends BroadcastReceiver {
|
||||
message.markSeen();
|
||||
}
|
||||
|
||||
if (prefs.getWakePhoneEnabled()) {
|
||||
if (conversationPrefs.getWakePhoneEnabled()) {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
|
||||
wakeLock.acquire();
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.moez.QKSMS.ui.dialog;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.TextView;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.BlockedConversationHelper;
|
||||
import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.view.QKEditText;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockedNumberDialog {
|
||||
|
||||
public static void showDialog(final QKActivity context) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> addresses = BlockedConversationHelper.getFutureBlockedConversations(prefs);
|
||||
|
||||
new QKDialog()
|
||||
.setContext(context)
|
||||
.setTitle(R.string.pref_block_future)
|
||||
.setItems(addresses.toArray(new String[addresses.size()]), new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
|
||||
new QKDialog()
|
||||
.setContext(context)
|
||||
.setTitle(R.string.title_unblock_address)
|
||||
.setMessage(((TextView) view).getText().toString())
|
||||
.setPositiveButton(R.string.yes, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BlockedConversationHelper.unblockFutureConversation(prefs, ((TextView) view).getText().toString());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show(context.getFragmentManager(), "remove from future blocked");
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.add, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final QKEditText editText = new QKEditText(context);
|
||||
new QKDialog()
|
||||
.setContext(context)
|
||||
.setTitle(R.string.title_block_address)
|
||||
.setCustomView(editText)
|
||||
.setPositiveButton(R.string.add, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (editText.getText().length() > 0) {
|
||||
BlockedConversationHelper.blockFutureConversation(prefs, editText.getText().toString());
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show(context.getFragmentManager(), "add to future blocked");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show(context.getFragmentManager(), "future blocked conversations");
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import android.widget.Toast;
|
||||
import com.mariussoft.endlessjabber.sdk.EndlessJabberInterface;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.AnalyticsManager;
|
||||
import com.moez.QKSMS.ui.dialog.BlockedNumberDialog;
|
||||
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
|
||||
import com.moez.QKSMS.interfaces.LiveView;
|
||||
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
|
||||
@@ -113,6 +114,7 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||
public static final String YAPPY = "pref_key_endlessjabber";
|
||||
public static final String BLOCKED_ENABLED = "pref_key_blocked_enabled";
|
||||
public static final String BLOCKED_SENDERS = "pref_key_blocked_senders";
|
||||
public static final String BLOCKED_FUTURE = "pref_key_block_future";
|
||||
public static final String MOBILE_ONLY = "pref_key_mobile_only";
|
||||
public static final String COMPOSE_GROUP = "pref_key_compose_group";
|
||||
public static final String SPLIT_SMS = "pref_key_split";
|
||||
@@ -551,6 +553,9 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||
case ICON:
|
||||
ThemeManager.setIcon(mContext);
|
||||
break;
|
||||
case BLOCKED_FUTURE:
|
||||
BlockedNumberDialog.showDialog(mContext);
|
||||
break;
|
||||
case NOTIFICATION_LED_COLOR:
|
||||
mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user