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.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
|
import com.moez.QKSMS.common.utils.PhoneNumberUtils;
|
||||||
import com.moez.QKSMS.data.Conversation;
|
import com.moez.QKSMS.data.Conversation;
|
||||||
import com.moez.QKSMS.data.Message;
|
import com.moez.QKSMS.data.Message;
|
||||||
import com.moez.QKSMS.transaction.SmsHelper;
|
import com.moez.QKSMS.transaction.SmsHelper;
|
||||||
@@ -53,6 +54,32 @@ public class BlockedConversationHelper {
|
|||||||
return prefs.getStringSet(SettingsFragment.BLOCKED_SENDERS, new HashSet<String>());
|
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) {
|
public static String[] getBlockedConversationArray(SharedPreferences prefs) {
|
||||||
Set<String> idStrings = getBlockedConversations(prefs);
|
Set<String> idStrings = getBlockedConversations(prefs);
|
||||||
return idStrings.toArray(new String[idStrings.size()]);
|
return idStrings.toArray(new String[idStrings.size()]);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.moez.QKSMS.receiver;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@@ -54,9 +55,15 @@ public class MessagingReceiver extends BroadcastReceiver {
|
|||||||
uri = SmsHelper.addMessageToInbox(context, address, body, date);
|
uri = SmsHelper.addMessageToInbox(context, address, body, date);
|
||||||
|
|
||||||
Message message = new Message(context, uri);
|
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())) {
|
PreferenceManager.getDefaultSharedPreferences(context)).contains(message.getThreadId())) {
|
||||||
Intent messageHandlerIntent = new Intent(context, NotificationService.class);
|
Intent messageHandlerIntent = new Intent(context, NotificationService.class);
|
||||||
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
|
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
|
||||||
@@ -69,7 +76,7 @@ public class MessagingReceiver extends BroadcastReceiver {
|
|||||||
message.markSeen();
|
message.markSeen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs.getWakePhoneEnabled()) {
|
if (conversationPrefs.getWakePhoneEnabled()) {
|
||||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
|
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
|
||||||
wakeLock.acquire();
|
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.mariussoft.endlessjabber.sdk.EndlessJabberInterface;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
import com.moez.QKSMS.common.AnalyticsManager;
|
import com.moez.QKSMS.common.AnalyticsManager;
|
||||||
|
import com.moez.QKSMS.ui.dialog.BlockedNumberDialog;
|
||||||
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
|
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
|
||||||
import com.moez.QKSMS.interfaces.LiveView;
|
import com.moez.QKSMS.interfaces.LiveView;
|
||||||
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
|
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 YAPPY = "pref_key_endlessjabber";
|
||||||
public static final String BLOCKED_ENABLED = "pref_key_blocked_enabled";
|
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_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 MOBILE_ONLY = "pref_key_mobile_only";
|
||||||
public static final String COMPOSE_GROUP = "pref_key_compose_group";
|
public static final String COMPOSE_GROUP = "pref_key_compose_group";
|
||||||
public static final String SPLIT_SMS = "pref_key_split";
|
public static final String SPLIT_SMS = "pref_key_split";
|
||||||
@@ -551,6 +553,9 @@ public class SettingsFragment extends PreferenceFragment implements
|
|||||||
case ICON:
|
case ICON:
|
||||||
ThemeManager.setIcon(mContext);
|
ThemeManager.setIcon(mContext);
|
||||||
break;
|
break;
|
||||||
|
case BLOCKED_FUTURE:
|
||||||
|
BlockedNumberDialog.showDialog(mContext);
|
||||||
|
break;
|
||||||
case NOTIFICATION_LED_COLOR:
|
case NOTIFICATION_LED_COLOR:
|
||||||
mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
|
mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -166,6 +166,8 @@
|
|||||||
<string name="pref_endlessjabber_summary">Enable full support for Yappy</string>
|
<string name="pref_endlessjabber_summary">Enable full support for Yappy</string>
|
||||||
<string name="pref_blocked_conversations">Blocked conversations</string>
|
<string name="pref_blocked_conversations">Blocked conversations</string>
|
||||||
<string name="pref_blocked_conversations_summary">Long-press on a conversation and block to move to blocked inbox and stop notifications</string>
|
<string name="pref_blocked_conversations_summary">Long-press on a conversation and block to move to blocked inbox and stop notifications</string>
|
||||||
|
<string name="pref_block_future">Block future messages</string>
|
||||||
|
<string name="pref_block_future_summary">Add additional phone numbers to block</string>
|
||||||
<string name="pref_mobile_only">Mobile numbers</string>
|
<string name="pref_mobile_only">Mobile numbers</string>
|
||||||
<string name="pref_mobile_only_summary">Only show mobile numbers in contact suggestions</string>
|
<string name="pref_mobile_only_summary">Only show mobile numbers in contact suggestions</string>
|
||||||
<string name="pref_auto_emoji">Automatic emoji</string>
|
<string name="pref_auto_emoji">Automatic emoji</string>
|
||||||
@@ -304,6 +306,8 @@
|
|||||||
<string name="title_donate">Donate</string>
|
<string name="title_donate">Donate</string>
|
||||||
<!--QK Response dialog title-->
|
<!--QK Response dialog title-->
|
||||||
<string name="title_qk_responses">QK Responses</string>
|
<string name="title_qk_responses">QK Responses</string>
|
||||||
|
<string name="title_block_address">Block number</string>
|
||||||
|
<string name="title_unblock_address">Unblock number</string>
|
||||||
|
|
||||||
<!-- Menu shown in the context menu when long pressing on a message when the message contains
|
<!-- Menu shown in the context menu when long pressing on a message when the message contains
|
||||||
one or more phone numbers and/or email addresses and the number or email is new to
|
one or more phone numbers and/or email addresses and the number or email is new to
|
||||||
@@ -368,6 +372,7 @@
|
|||||||
<string name="call">Call</string>
|
<string name="call">Call</string>
|
||||||
<!--Positive action button-->
|
<!--Positive action button-->
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
|
<string name="add">Add</string>
|
||||||
<!--Positive action button-->
|
<!--Positive action button-->
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<!--Positive action button-->
|
<!--Positive action button-->
|
||||||
|
|||||||
@@ -96,6 +96,13 @@
|
|||||||
android:summary="@string/pref_blocked_conversations_summary"
|
android:summary="@string/pref_blocked_conversations_summary"
|
||||||
android:title="@string/pref_blocked_conversations"
|
android:title="@string/pref_blocked_conversations"
|
||||||
android:widgetLayout="@layout/view_checkbox" />
|
android:widgetLayout="@layout/view_checkbox" />
|
||||||
|
<Preference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:dependency="pref_key_blocked_enabled"
|
||||||
|
android:key="pref_key_block_future"
|
||||||
|
android:layout="@layout/list_item_preference"
|
||||||
|
android:summary="@string/pref_block_future_summary"
|
||||||
|
android:title="@string/pref_block_future" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_key_mobile_only"
|
android:key="pref_key_mobile_only"
|
||||||
|
|||||||
Reference in New Issue
Block a user