1 /*
2  * Copyright (C) 2018 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.car.settings.suggestions;
18 
19 import android.content.Context;
20 import android.service.settings.suggestions.Suggestion;
21 
22 import com.android.car.settings.common.Logger;
23 import com.android.car.settingslib.loader.AsyncLoader;
24 import com.android.settingslib.suggestions.SuggestionController;
25 
26 import java.util.List;
27 
28 /**
29  * Loads suggestions for car settings. Taken from
30  * {@link com.android.settingslib.suggestions.SuggestionLoader}, only change is to extend from car
31  * settings {@link AsyncLoader} which extends from support library {@link AsyncTaskLoader}.
32  */
33 public class SettingsSuggestionsLoader extends AsyncLoader<List<Suggestion>> {
34     private static final Logger LOG = new Logger(SettingsSuggestionsLoader.class);
35 
36     /**
37      * ID used for loader that loads the settings suggestions. ID value is an arbitrary value.
38      */
39     public static final int LOADER_ID_SUGGESTIONS = 42;
40 
41     private final SuggestionController mSuggestionController;
42 
SettingsSuggestionsLoader(Context context, SuggestionController controller)43     public SettingsSuggestionsLoader(Context context, SuggestionController controller) {
44         super(context);
45         mSuggestionController = controller;
46     }
47 
48     @Override
loadInBackground()49     public List<Suggestion> loadInBackground() {
50         final List<Suggestion> data = mSuggestionController.getSuggestions();
51         if (data == null) {
52             LOG.d("data is null");
53         } else {
54             LOG.d("data size " + data.size());
55         }
56         return data;
57     }
58 }