Files
app_Settings/src/com/android/settings/homepage/contextualcards/ContextualCardsFragment.java
Emily Chuang f519e3ffe5 Make ContextualCardLoader do entire loading upon fragment's onStart()
For dismissal mechanism, we will have to get information about those
dismissed cards that are stored in Card DB with flag "dismiss" to filter
them out. Currently we only do the entire loading in fragment's
onCreate(), so only when the fragment is recreated users can get the new
data. Now we are changing it to onStart() and make the loader restart so
we are able to show the latest cards.

Change-Id: I4c0be297232f026b46feb8084084816e1acc8f11
Fixes: 119090460
Bug: 113783548
Test: visual
2018-11-06 19:56:42 +08:00

75 lines
2.7 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source 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.settings.homepage.contextualcards;
import static com.android.settings.homepage.contextualcards.ContextualCardsAdapter.SPAN_COUNT;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
public class ContextualCardsFragment extends InstrumentedFragment {
private static final String TAG = "ContextualCardsFragment";
private RecyclerView mCardsContainer;
private GridLayoutManager mLayoutManager;
private ContextualCardsAdapter mContextualCardsAdapter;
private ContextualCardManager mContextualCardManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContextualCardManager = new ContextualCardManager(getContext(), getSettingsLifecycle());
}
@Override
public void onStart() {
super.onStart();
mContextualCardManager.loadContextualCards(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
mCardsContainer = rootView.findViewById(R.id.card_container);
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT,
GridLayoutManager.VERTICAL, false /* reverseLayout */);
mCardsContainer.setLayoutManager(mLayoutManager);
mContextualCardsAdapter = new ContextualCardsAdapter(getContext(),
this /* lifecycleOwner */, mContextualCardManager);
mCardsContainer.setAdapter(mContextualCardsAdapter);
mContextualCardManager.setListener(mContextualCardsAdapter);
return rootView;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.SETTINGS_HOMEPAGE;
}
}