blob: e1d882e6b8fe903c6f25e9b121aa32985bd7720c [file] [log] [blame]
Wenyi Wang9cfe1af2016-04-07 18:06:08 -07001/*
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
17package com.android.contacts.interactions;
18
19import android.app.Fragment;
20import android.app.LoaderManager;
21import android.content.Loader;
22import android.os.Bundle;
23
Gary Mai69c182a2016-12-05 13:07:03 -080024import com.android.contacts.list.ContactListFilter;
25import com.android.contacts.util.AccountFilterUtil;
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070026
27import java.util.List;
28
29/**
30 * Loads account filters.
31 */
32public 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 Wangbb229242016-05-25 16:04:13 -070044 void onFiltersLoaded(List<ContactListFilter> accountFilterItems);
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070045 }
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 Hagerottfac695a2016-08-24 17:02:40 -070057 if (mListener != null && data != null) {
58 mListener.onFiltersLoaded(data);
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070059 }
60 }
61
62 public void onLoaderReset(Loader<List<ContactListFilter>> loader) {
63 }
64 };
65
66 private AccountFiltersListener mListener;
67
68 @Override
Marcus Hagerott6caf23f2016-08-18 15:02:42 -070069 public void onCreate(Bundle savedInstanceState) {
70 super.onCreate(savedInstanceState);
Marcus Hagerott6caf23f2016-08-18 15:02:42 -070071 }
72
73 @Override
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070074 public void onStart() {
75 getLoaderManager().initLoader(LOADER_FILTERS, null, mFiltersLoaderListener);
Marcus Hagerott6caf23f2016-08-18 15:02:42 -070076
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070077 super.onStart();
78 }
79
80 public void setListener(AccountFiltersListener listener) {
81 mListener = listener;
82 }
Wenyi Wang9cfe1af2016-04-07 18:06:08 -070083}