Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.contacts.interactions; |
| 18 | |
| 19 | import android.app.Fragment; |
| 20 | import android.app.LoaderManager; |
| 21 | import android.content.Loader; |
| 22 | import android.os.Bundle; |
| 23 | |
| 24 | import com.android.contacts.common.list.ContactListFilter; |
| 25 | import com.android.contacts.common.util.AccountFilterUtil; |
| 26 | |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * Loads account filters. |
| 31 | */ |
| 32 | public class AccountFiltersFragment extends Fragment { |
| 33 | |
| 34 | private static final int LOADER_FILTERS = 1; |
| 35 | |
| 36 | /** |
| 37 | * Callbacks for hosts of the {@link AccountFiltersFragment}. |
| 38 | */ |
| 39 | public interface AccountFiltersListener { |
| 40 | |
| 41 | /** |
| 42 | * Invoked after account filters have been loaded. |
| 43 | */ |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 44 | void onFiltersLoaded(List<ContactListFilter> accountFilterItems); |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | private final LoaderManager.LoaderCallbacks<List<ContactListFilter>> mFiltersLoaderListener = |
| 48 | new LoaderManager.LoaderCallbacks<List<ContactListFilter>> () { |
| 49 | @Override |
| 50 | public Loader<List<ContactListFilter>> onCreateLoader(int id, Bundle args) { |
| 51 | return new AccountFilterUtil.FilterLoader(getActivity()); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onLoadFinished( |
| 56 | Loader<List<ContactListFilter>> loader, List<ContactListFilter> data) { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 57 | if (mListener != null && data != null) { |
| 58 | mListener.onFiltersLoaded(data); |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | public void onLoaderReset(Loader<List<ContactListFilter>> loader) { |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | private AccountFiltersListener mListener; |
| 67 | |
| 68 | @Override |
Marcus Hagerott | 6caf23f | 2016-08-18 15:02:42 -0700 | [diff] [blame] | 69 | public void onCreate(Bundle savedInstanceState) { |
| 70 | super.onCreate(savedInstanceState); |
Marcus Hagerott | 6caf23f | 2016-08-18 15:02:42 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 74 | public void onStart() { |
| 75 | getLoaderManager().initLoader(LOADER_FILTERS, null, mFiltersLoaderListener); |
Marcus Hagerott | 6caf23f | 2016-08-18 15:02:42 -0700 | [diff] [blame] | 76 | |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 77 | super.onStart(); |
| 78 | } |
| 79 | |
| 80 | public void setListener(AccountFiltersListener listener) { |
| 81 | mListener = listener; |
| 82 | } |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 83 | } |