summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2016-03-02 09:40:20 -0800
committerRichard MacGregor <rmacgregor@cyngn.com>2016-03-25 11:42:19 -0700
commit0bda716a5afd58f63c846c72663b5b3a17897c4e (patch)
treef4d0c4b33653c5b9a2438c57ad40682c3bb73da1 /src
parent70292caeb1dae0b1bd6c129b25f6b1813e9bf7ac (diff)
downloadandroid_packages_apps_ContactsCommon-0bda716a5afd58f63c846c72663b5b3a17897c4e.tar.gz
android_packages_apps_ContactsCommon-0bda716a5afd58f63c846c72663b5b3a17897c4e.tar.bz2
android_packages_apps_ContactsCommon-0bda716a5afd58f63c846c72663b5b3a17897c4e.zip
Refactor BlockContactHelper and BlockContactDialogFragment
- remove redundant and duplicated BlockNumberHelper - Enforce BlockContactDialogFragment callback to strictly be an Activity or Fragment. This is to preserve the Callback across Fragment reconstruction (like that during a config change) - Additional callbacks in BlockContactHelper Change-Id: I029e31d51baa14ba13c267242bff12e6153337da
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/common/activity/fragment/BlockContactDialogFragment.java81
-rw-r--r--src/com/android/contacts/common/model/BlockRequest.java72
-rw-r--r--src/com/android/contacts/common/util/BlockContactHelper.java217
-rw-r--r--src/com/android/contacts/common/util/BlockNumberHelper.java172
4 files changed, 270 insertions, 272 deletions
diff --git a/src/com/android/contacts/common/activity/fragment/BlockContactDialogFragment.java b/src/com/android/contacts/common/activity/fragment/BlockContactDialogFragment.java
index b6b93518..02f194b0 100644
--- a/src/com/android/contacts/common/activity/fragment/BlockContactDialogFragment.java
+++ b/src/com/android/contacts/common/activity/fragment/BlockContactDialogFragment.java
@@ -1,8 +1,25 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.contacts.common.activity.fragment;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Dialog;
+import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.app.AlertDialog;
@@ -14,7 +31,7 @@ import android.widget.CheckBox;
import com.android.contacts.common.R;
/**
- * Interacts with the framework implementation of Blacklist and any phonenumber Lookup Providers
+ * Interacts with the framework implementation of Blacklist and any phonenumber Lookup Provider
* interested in spam collection
*
* NOTE: ensure you have Blacklist permissions before using this class
@@ -26,11 +43,27 @@ public class BlockContactDialogFragment extends DialogFragment
public static final int UNBLOCK_MODE = 1;
public static final String KEY_CURRENT_LOOKUP_PROVIDER_NAME = "CURRENT_LOOKUP_PROVIDER_NAME";
public static final String KEY_LAUNCH_MODE = "LAUNCH_MODE";
- public static final String BLOCK_UI_RESULT_CALLBACK = "BLOCK_UI_RESULT_CALLBACK";
private int mLaunchMode;
private CheckBox mNotifyProviderCheckBox;
- private BlockContactCallbacks mUIResultCallbacks;
+
+ public static BlockContactDialogFragment create(int mode, String lookupProvider) {
+ return create(mode, lookupProvider, null);
+ }
+
+ public static BlockContactDialogFragment create(int mode, String lookupProvider,
+ Fragment targetFragment) {
+ BlockContactDialogFragment f = new BlockContactDialogFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(BlockContactDialogFragment.KEY_LAUNCH_MODE, mode);
+ bundle.putString(BlockContactDialogFragment.KEY_CURRENT_LOOKUP_PROVIDER_NAME,
+ lookupProvider);
+ f.setArguments(bundle);
+ if (targetFragment != null) {
+ f.setTargetFragment(targetFragment, 0);
+ }
+ return f;
+ }
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -39,17 +72,6 @@ public class BlockContactDialogFragment extends DialogFragment
Bundle bundle = getArguments();
mLaunchMode = bundle.getInt(KEY_LAUNCH_MODE);
lookupProviderName = bundle.getString(KEY_CURRENT_LOOKUP_PROVIDER_NAME);
-
- mUIResultCallbacks = null;
-
- if (bundle.getSerializable(BLOCK_UI_RESULT_CALLBACK) != null) {
- try {
- mUIResultCallbacks = (BlockContactCallbacks) bundle.getSerializable
- (BLOCK_UI_RESULT_CALLBACK);
- } catch (ClassCastException e) {
- mUIResultCallbacks = null;
- }
- }
}
Activity hostActivity = getActivity();
@@ -106,32 +128,39 @@ public class BlockContactDialogFragment extends DialogFragment
@Override
public void onClick(DialogInterface dialog, int which) {
boolean mCheckboxStatus = mNotifyProviderCheckBox.isChecked();
- Activity parentActivity = getActivity();
- if (parentActivity instanceof BlockContactCallbacks) {
- if (mLaunchMode == BLOCK_MODE) {
- ((BlockContactCallbacks) parentActivity).onBlockContact(mCheckboxStatus);
- } else {
- ((BlockContactCallbacks) parentActivity).onUnblockContact(mCheckboxStatus);
+ // determine if a Callback is present
+ // priority is given to a TargetFragment if one is set
+ // otherwise the host activity is chosen, if it adheres to the Callbacks interface
+ Callbacks callback = null;
+ Fragment targetFragment = getTargetFragment();
+ if (targetFragment != null) {
+ // throw a runtime exception if a TargetFragment is set that doesn't implement
+ // the Callbacks interface
+ callback = (Callbacks) targetFragment;
+ } else {
+ Activity parentActivity = getActivity();
+ if (parentActivity instanceof Callbacks) {
+ callback = (Callbacks) parentActivity;
}
}
- if (mUIResultCallbacks != null && mUIResultCallbacks instanceof BlockContactCallbacks) {
+ if (callback != null) {
if (mLaunchMode == BLOCK_MODE) {
- ((BlockContactCallbacks) mUIResultCallbacks).onBlockContact(mCheckboxStatus);
+ callback.onBlockSelected(mCheckboxStatus);
} else {
- ((BlockContactCallbacks) mUIResultCallbacks).onUnblockContact(mCheckboxStatus);
+ callback.onUnblockSelected(mCheckboxStatus);
}
}
}
- public interface BlockContactCallbacks {
+ public interface Callbacks {
/**
* Callback noting that the user opted to block the contact
*
* @param notifyLookupProvider indicates whether the user opted to report the contact
* to the current LookupProvider
*/
- void onBlockContact(boolean notifyLookupProvider);
+ void onBlockSelected(boolean notifyLookupProvider);
/**
* Callback noting that the user opted to unblock the contact
@@ -139,6 +168,6 @@ public class BlockContactDialogFragment extends DialogFragment
* @param notifyLookupProvider indicates whether the user opted to notify the current
* LookupProvider of the unblock
*/
- void onUnblockContact(boolean notifyLookupProvider);
+ void onUnblockSelected(boolean notifyLookupProvider);
}
}
diff --git a/src/com/android/contacts/common/model/BlockRequest.java b/src/com/android/contacts/common/model/BlockRequest.java
new file mode 100644
index 00000000..54bc7217
--- /dev/null
+++ b/src/com/android/contacts/common/model/BlockRequest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.common.model;
+
+import android.content.Context;
+import android.text.TextUtils;
+import com.android.contacts.common.model.dataitem.DataItem;
+import com.android.contacts.common.model.dataitem.PhoneDataItem;
+import com.android.contacts.common.util.PhoneNumberHelper;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * ADT used by {@link com.android.contacts.common.util.BlockContactHelper}
+ */
+public class BlockRequest {
+
+ public static BlockRequest EMPTY = new BlockRequest();
+
+ public List<String> phoneNumbers = Collections.EMPTY_LIST;
+
+ public static BlockRequest createFrom(Context context, Contact contact) {
+ ArrayList<String> numbersList = new ArrayList<String>();
+ for (RawContact rawContact : contact.getRawContacts()) {
+ List<DataItem> data = rawContact.getDataItems();
+ for(DataItem item : data) {
+ if (item instanceof PhoneDataItem) {
+ PhoneDataItem phoneDataItem = (PhoneDataItem) item;
+ String number = phoneDataItem.getNumber();
+ String formattedNumber = PhoneNumberHelper.formatPhoneNumber(context, number);
+ numbersList.add(formattedNumber);
+ }
+ }
+ }
+
+ if (numbersList.size() == 0) {
+ return EMPTY;
+ } else {
+ BlockRequest blockRequest = new BlockRequest();
+ blockRequest.phoneNumbers = numbersList;
+ return blockRequest;
+ }
+ }
+
+ public static BlockRequest createFrom(Context context, String phoneNumber) {
+ if (TextUtils.isEmpty(phoneNumber)) {
+ return EMPTY;
+ }
+
+ BlockRequest blockRequest = new BlockRequest();
+ blockRequest.phoneNumbers = new ArrayList<String>();
+ blockRequest.phoneNumbers.add(PhoneNumberHelper.formatPhoneNumber(context, phoneNumber));
+ return blockRequest;
+ }
+
+}
diff --git a/src/com/android/contacts/common/util/BlockContactHelper.java b/src/com/android/contacts/common/util/BlockContactHelper.java
index c68181e0..eff65b6b 100644
--- a/src/com/android/contacts/common/util/BlockContactHelper.java
+++ b/src/com/android/contacts/common/util/BlockContactHelper.java
@@ -1,19 +1,33 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.contacts.common.util;
import android.app.DialogFragment;
+import android.app.Fragment;
import android.content.Context;
import android.os.AsyncTask;
-import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
+
import com.android.contacts.common.activity.fragment.BlockContactDialogFragment;
+import com.android.contacts.common.model.BlockRequest;
import com.android.contacts.common.model.Contact;
-import com.android.contacts.common.model.RawContact;
-import com.android.contacts.common.model.dataitem.DataItem;
-import com.android.contacts.common.model.dataitem.PhoneDataItem;
import com.android.internal.telephony.util.BlacklistUtils;
import com.cyanogen.lookup.phonenumber.contract.LookupProvider;
-
-import java.util.List;
+import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl;
/**
* Helper class used to interface with the framework implementation of Blacklist and delegating
@@ -25,11 +39,12 @@ import java.util.List;
public class BlockContactHelper {
private final Context mContext;
private AsyncTask mBackgroundTask;
- private Contact mContact;
+ private BlockRequest mBlockRequest;
private LookupProvider mLookupProvider;
private volatile boolean mIsBlacklisted;
private volatile boolean mIsProviderInitialized;
private boolean mBackgroundTaskCompleted;
+ private StatusCallbacks mListener;
public enum BlockOperation {
BLOCK,
@@ -42,48 +57,69 @@ public class BlockContactHelper {
}
public void setContactInfo(Contact contact) {
- mContact = contact;
+ mBlockRequest = BlockRequest.createFrom(mContext, contact);
+ gatherDataInBackgroundAsync();
}
- public void gatherDataInBackground() {
+ public void setContactInfo(String phoneNumber) {
+ mBlockRequest = BlockRequest.createFrom(mContext, phoneNumber);
+ gatherDataInBackgroundAsync();
+ }
+
+ public void setStatusListener(StatusCallbacks listener) {
+ mListener = listener;
+ }
+
+ public void gatherDataInBackgroundAsync() {
mBackgroundTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- if (mContact == null) {
- return null;
- }
+ gatherDataInBackground();
+ mBackgroundTaskCompleted = true;
+ return null;
+ }
- // reset blacklist status
- mIsBlacklisted = false;
- // check blacklist status of all of the contact's numbers
- blacklist_search:
- for (RawContact rawContact : mContact.getRawContacts()) {
- List<DataItem> data = rawContact.getDataItems();
- for(DataItem item : data) {
- if (item instanceof PhoneDataItem) {
- PhoneDataItem phoneDataItem = (PhoneDataItem) item;
- if (isBlacklisted(phoneDataItem.getNumber())) {
- mIsBlacklisted = true;
- break blacklist_search;
- }
- }
- }
+ @Override
+ protected void onPostExecute(Void Void) {
+ if (mListener != null) {
+ mListener.onInfoAvailable();
}
+ }
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
+ }
- if (mLookupProvider.initialize()) {
- mIsProviderInitialized = true;
- }
+ public void gatherDataInBackground() {
+ if (mBlockRequest == null || mBlockRequest == BlockRequest.EMPTY) {
+ return;
+ }
- mBackgroundTaskCompleted = true;
- return null;
+ mIsBlacklisted = false;
+
+ // check blacklist status of all of the contact's numbers
+ for (String phoneNumber : mBlockRequest.phoneNumbers) {
+ if (isBlacklisted(phoneNumber)) {
+ mIsBlacklisted = true;
+ break;
}
- }.execute();
+ }
+
+ if (mLookupProvider.initialize()) {
+ mIsProviderInitialized = true;
+ }
}
public boolean isContactBlacklisted() {
return mIsBlacklisted;
}
+ public String getLookupProviderName() {
+ if (mIsProviderInitialized) {
+ return mLookupProvider.getDisplayName();
+ } else {
+ return null;
+ }
+ }
+
/**
* Note: run on non-ui thread as this call executes a content provider query
*/
@@ -103,56 +139,56 @@ public class BlockContactHelper {
!= BlacklistUtils.MATCH_NONE;
}
- public DialogFragment getBlockContactDialog(BlockOperation blockOperation) {
- BlockContactDialogFragment f = new BlockContactDialogFragment();
- Bundle bundle = new Bundle();
- int launchMode = blockOperation == BlockOperation.BLOCK ?
- BlockContactDialogFragment.BLOCK_MODE : BlockContactDialogFragment.UNBLOCK_MODE;
- bundle.putInt(BlockContactDialogFragment.KEY_LAUNCH_MODE, launchMode);
- String providerName = mLookupProvider.getDisplayName();
- bundle.putString(BlockContactDialogFragment.KEY_CURRENT_LOOKUP_PROVIDER_NAME, providerName);
+ public DialogFragment getBlockContactDialog(BlockOperation blockMode) {
+ return getBlockContactDialog(blockMode, null);
+ }
- f.setArguments(bundle);
- return f;
+ public DialogFragment getBlockContactDialog(BlockOperation blockMode, Fragment targetFragment) {
+ int launchMode = blockMode == BlockOperation.BLOCK ? BlockContactDialogFragment.BLOCK_MODE :
+ BlockContactDialogFragment.UNBLOCK_MODE;
+ return BlockContactDialogFragment.create(launchMode, mLookupProvider.getDisplayName(),
+ targetFragment);
}
public void blockContact(boolean notifyLookupProvider) {
- applyBlockOperationOnContact(BlockOperation.BLOCK, notifyLookupProvider);
+ blockContact(notifyLookupProvider, true /*notify status-listener*/);
+ }
+
+ private void blockContact(boolean notifyLookupProvider, boolean notifyListener) {
+ for (String phoneNumber : mBlockRequest.phoneNumbers) {
+ toggleBlacklistStatus(phoneNumber, true /*block contact*/);
+
+ if (notifyLookupProvider && mIsProviderInitialized &&
+ mLookupProvider.supportsSpamReporting()) {
+ mLookupProvider.markAsSpam(phoneNumber);
+ }
+ }
+
+ if (notifyListener && mListener != null) {
+ mListener.onBlockCompleted();
+ }
+
gatherDataInBackground();
}
public void unblockContact(boolean notifyLookupProvider) {
- applyBlockOperationOnContact(BlockOperation.UNBLOCK, notifyLookupProvider);
- gatherDataInBackground();
+ unblockContact(notifyLookupProvider, true /*notify status-listener*/);
}
- public void applyBlockOperationOnContact(BlockOperation blockOperation, boolean notifyLookupProvider) {
- boolean shouldBlock = blockOperation == BlockOperation.BLOCK;
- for (RawContact rawContact : mContact.getRawContacts()) {
- List<DataItem> data = rawContact.getDataItems();
- for(DataItem item : data) {
- if (item instanceof PhoneDataItem) {
- PhoneDataItem phoneDataItem = (PhoneDataItem) item;
- String number = phoneDataItem.getNumber();
- toggleBlacklistStatus(number, shouldBlock);
-
- if (notifyLookupProvider && mIsProviderInitialized &&
- mLookupProvider.supportsSpamReporting()) {
-
- String formattedNumber = PhoneNumberHelper.formatPhoneNumber(mContext,
- number);
- switch (blockOperation) {
- case BLOCK:
- mLookupProvider.markAsSpam(formattedNumber);
- break;
- case UNBLOCK:
- mLookupProvider.unmarkAsSpam(formattedNumber);
- }
- }
- }
+ private void unblockContact(boolean notifyLookupProvider, boolean notifyListener) {
+ for (String phoneNumber : mBlockRequest.phoneNumbers) {
+ toggleBlacklistStatus(phoneNumber, false /*unblock contact*/);
+
+ if (notifyLookupProvider && mIsProviderInitialized &&
+ mLookupProvider.supportsSpamReporting()) {
+ mLookupProvider.unmarkAsSpam(phoneNumber);
}
}
+ if (notifyListener && mListener != null) {
+ mListener.onUnblockCompleted();
+ }
+
gatherDataInBackground();
}
@@ -160,27 +196,60 @@ public class BlockContactHelper {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- blockContact(notifyLookupProvider);
+ blockContact(notifyLookupProvider, false);
return null;
}
- }.execute();
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ if(mListener != null) {
+ mListener.onBlockCompleted();
+ }
+ }
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
public void unblockContactAsync(final boolean notifyLookupProvider) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- unblockContact(notifyLookupProvider);
+ unblockContact(notifyLookupProvider, false);
return null;
}
- }.execute();
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ if(mListener != null) {
+ mListener.onUnblockCompleted();
+ }
+ }
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
/**
* Clean-up any external resources that are used
*/
public void destroy() {
+ if (mBackgroundTask != null) {
+ mBackgroundTask.cancel(true /*interrupt*/);
+ }
mLookupProvider.disable();
}
+ public interface StatusCallbacks {
+ /**
+ * Callback indicating that Blacklist information about the contact has been fetched
+ */
+ void onInfoAvailable();
+
+ /**
+ * Callback indicating that block action has completed
+ */
+ void onBlockCompleted();
+
+ /**
+ * Callback indicating that unblock action has completed
+ */
+ void onUnblockCompleted();
+ }
}
diff --git a/src/com/android/contacts/common/util/BlockNumberHelper.java b/src/com/android/contacts/common/util/BlockNumberHelper.java
deleted file mode 100644
index 9d329d51..00000000
--- a/src/com/android/contacts/common/util/BlockNumberHelper.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package com.android.contacts.common.util;
-
-import android.app.DialogFragment;
-import android.content.Context;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.telephony.PhoneNumberUtils;
-
-import com.android.internal.telephony.util.BlacklistUtils;
-import com.android.contacts.common.activity.fragment.BlockContactDialogFragment;
-import com.android.contacts.common.R;
-import com.android.contacts.common.model.Contact;
-import com.cyanogen.lookup.phonenumber.contract.LookupProvider;
-
-import java.io.Serializable;
-
-/**
- * Helper class used to interface with the framework implementation of Blacklist and delegating
- * the apropos information to the active phonenumber LookupProvider, if any.
- */
-public class BlockNumberHelper implements BlockContactDialogFragment.BlockContactCallbacks,
- Serializable {
- private final Context mContext;
- private AsyncTask mBackgroundTask;
- private String mNumber;
- private LookupProvider mLookupProvider;
- private volatile boolean mIsProviderInitialized;
- private BlockActionCallbacks mTaskCompletionCallbacks;
-
- public enum BlockMode {
- BLOCK,
- UNBLOCK
- }
-
- public BlockNumberHelper(Context context, LookupProvider lookupProvider) {
- mContext = context;
- mLookupProvider = lookupProvider;
- }
-
- public void setNumberInfo(String number) {
- mNumber = number;
- }
-
- public void setTaskCompletionCallbacks(BlockActionCallbacks taskCompletionCallbacks) {
- mTaskCompletionCallbacks = taskCompletionCallbacks;
- }
-
- public void gatherDataInBackground() {
- mBackgroundTask = new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- if (mNumber == null) return null;
-
- if (mLookupProvider.initialize()) {
- mIsProviderInitialized = true;
- }
-
- return null;
- }
- }.execute();
- }
-
- /**
- * Note: run on non-ui thread as this call executes a content provider query
- */
- private void toggleBlacklistStatus(String number, boolean shouldBlacklist) {
- String nn = PhoneNumberUtils.normalizeNumber(number);
- BlacklistUtils.addOrUpdate(mContext, nn,
- shouldBlacklist ? BlacklistUtils.BLOCK_CALLS | BlacklistUtils.BLOCK_MESSAGES
- : 0, BlacklistUtils.BLOCK_CALLS | BlacklistUtils.BLOCK_MESSAGES);
- }
-
- public DialogFragment getBlockNumberDialog(BlockMode blockMode) {
- BlockContactDialogFragment f = new BlockContactDialogFragment();
- Bundle bundle = new Bundle();
- int launchMode = blockMode == BlockMode.BLOCK ? BlockContactDialogFragment.BLOCK_MODE :
- BlockContactDialogFragment.UNBLOCK_MODE;
- bundle.putInt(BlockContactDialogFragment.KEY_LAUNCH_MODE, launchMode);
- String providerName = mLookupProvider.getDisplayName();
- bundle.putString(BlockContactDialogFragment.KEY_CURRENT_LOOKUP_PROVIDER_NAME, providerName);
- bundle.putSerializable(BlockContactDialogFragment.BLOCK_UI_RESULT_CALLBACK,
- (Serializable)this);
-
- f.setArguments(bundle);
- return f;
- }
-
- private void blockNumber(String number, boolean notifyLookupProvider) {
- toggleBlacklistStatus(number, true /*block number*/);
-
- if (notifyLookupProvider && mIsProviderInitialized &&
- mLookupProvider.supportsSpamReporting()) {
- String formattedNumber = PhoneNumberHelper.formatPhoneNumber(mContext,
- number);
- mLookupProvider.markAsSpam(formattedNumber);
- }
- }
-
- private void unblockNumber(String number, boolean notifyLookupProvider) {
- toggleBlacklistStatus(number, false /*unblock number*/);
-
- if (notifyLookupProvider && mIsProviderInitialized &&
- mLookupProvider.supportsSpamReporting()) {
- String formattedNumber = PhoneNumberHelper.formatPhoneNumber(mContext,
- number);
- mLookupProvider.unmarkAsSpam(formattedNumber);
- }
- }
-
- private void blockNumberAsync(final String number, final boolean notifyLookupProvider) {
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- blockNumber(number, notifyLookupProvider);
- return null;
- }
- @Override
- protected void onPostExecute(Void v) {
- if(mTaskCompletionCallbacks != null
- && mTaskCompletionCallbacks instanceof BlockActionCallbacks) {
- ((BlockActionCallbacks)mTaskCompletionCallbacks).onBlockCompleted();
- }
- }
- }.execute();
- }
-
- private void unblockNumberAsync(final String number, final boolean notifyLookupProvider) {
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- unblockNumber(number, notifyLookupProvider);
- return null;
- }
- @Override
- protected void onPostExecute(Void v) {
- if(mTaskCompletionCallbacks != null
- && mTaskCompletionCallbacks instanceof BlockActionCallbacks) {
- ((BlockActionCallbacks)mTaskCompletionCallbacks).onUnblockCompleted();
- }
- }
- }.execute();
- }
-
- @Override
- public void onBlockContact(boolean notifyLookupProvider) {
- if (mNumber != null) {
- blockNumberAsync(mNumber, notifyLookupProvider);
- }
- }
-
- @Override
- public void onUnblockContact(boolean notifyLookupProvider) {
- if (mNumber != null) {
- unblockNumberAsync(mNumber, notifyLookupProvider);
- }
- }
-
-
- public interface BlockActionCallbacks {
- /**
- * Callback indicating that block action has completedd
- */
- void onBlockCompleted();
-
- /**
- * Callback indicating that unblock action has completed
- */
- void onUnblockCompleted();
- }
-
-
-}