diff options
author | Andrew Lee <anwlee@google.com> | 2015-10-13 00:57:01 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-10-13 00:57:01 +0000 |
commit | 975d2d46ac7148a86065ebf5987bc9aa2365d251 (patch) | |
tree | 3f774bfebef6ee255ed3460fb19c92a55755cee1 /src/com | |
parent | 8aa09c8771ef5d521c3f646484d9304a19cf6fd9 (diff) | |
parent | 257368c2dff97da3b9be7653190699b5686e1b56 (diff) |
Merge "Implement behavior for import settings visibility." into ub-contactsdialer-a-dev
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/dialer/filterednumber/BlockedNumberFragment.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java index e12fd6b38..5740305f7 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java @@ -21,7 +21,9 @@ import android.content.CursorLoader; import android.content.Intent; import android.content.Loader; import android.database.Cursor; +import android.os.AsyncTask; import android.os.Bundle; +import android.provider.ContactsContract.Contacts; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -32,7 +34,16 @@ import com.android.dialer.database.FilteredNumberContract; public class BlockedNumberFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener { + private static class SendToVoicemailContactQuery { + static final String[] PROJECTION = { + Contacts._ID + }; + + static final String SELECT_SEND_TO_VOICEMAIL_TRUE = Contacts.SEND_TO_VOICEMAIL + "=1"; + } + private BlockedNumberAdapter mAdapter; + private View mImportSettings; @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -47,6 +58,8 @@ public class BlockedNumberFragment extends ListFragment implements getActivity().findViewById(R.id.add_number_button).setOnClickListener(this); getListView().getEmptyView().findViewById(R.id.add_number_button).setOnClickListener(this); + + mImportSettings = getActivity().findViewById(R.id.importsettings); } @Override @@ -62,6 +75,12 @@ public class BlockedNumberFragment extends ListFragment implements } @Override + public void onResume() { + super.onResume(); + checkForSendToVoicemailContact(); + } + + @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.blocked_number_fragment, container, false); @@ -102,4 +121,44 @@ public class BlockedNumberFragment extends ListFragment implements manageBlockedNumbersActivity.enterSearchUi(); } } + + /** + * Checks if there exists a contact with {@code Contacts.SEND_TO_VOICEMAIL} set to true, + * and updates the visibility of the import settings buttons accordingly. + */ + private void checkForSendToVoicemailContact() { + final AsyncTask task = new AsyncTask<Object, Void, Boolean>() { + @Override + public Boolean doInBackground(Object[] params) { + if (getActivity() == null) { + return false; + } + + final Cursor cursor = getActivity().getContentResolver().query( + Contacts.CONTENT_URI, + SendToVoicemailContactQuery.PROJECTION, + SendToVoicemailContactQuery.SELECT_SEND_TO_VOICEMAIL_TRUE, + null, + null); + + boolean hasSendToVoicemailContacts = false; + if (cursor != null) { + try { + hasSendToVoicemailContacts = cursor.getCount() > 0; + } finally { + cursor.close(); + } + } + + return hasSendToVoicemailContacts; + } + + @Override + public void onPostExecute(Boolean hasSendToVoicemailContact) { + final int visibility = hasSendToVoicemailContact ? View.VISIBLE : View.GONE; + mImportSettings.setVisibility(visibility); + } + }; + task.execute(); + } } |