org.chromium.chrome.browser.ntp.snippets.SnippetsBridge Java Examples

The following examples show how to use org.chromium.chrome.browser.ntp.snippets.SnippetsBridge. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentSuggestionsPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Switches preference screens depending on whether the remote suggestions are enabled/disabled.
 * @param isEnabled Indicates whether the remote suggestions are enabled.
 */
public void updatePreferences(boolean isEnabled) {
    if (mIsEnabled == isEnabled) return;

    mFeatureSwitch.setChecked(isEnabled);
    mIsEnabled = isEnabled;

    if (canShowNotificationsSwitch()) {
        mFeatureSwitch.setSummaryOn(R.string.suggestions_feature_switch_on_summary);
        setNotificationsPrefState(true);
        mNotificationsSwitch.setChecked(
                SnippetsBridge.areContentSuggestionsNotificationsEnabled());
        setCaveatsPrefState(false);
    } else {
        mFeatureSwitch.setSummaryOn(R.string.text_on);
        setNotificationsPrefState(false);
        setCaveatsPrefState(true);
    }
}
 
Example #2
Source File: NewTabPageAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor to create the manager for all the cards to display on the NTP
 *
 * @param manager the NewTabPageManager to use to interact with the rest of the system.
 * @param newTabPageLayout the layout encapsulating all the above-the-fold elements
 *                         (logo, search box, most visited tiles)
 * @param snippetsBridge the bridge to interact with the snippets service.
 */
public NewTabPageAdapter(NewTabPageManager manager, NewTabPageLayout newTabPageLayout,
        SnippetsBridge snippetsBridge) {
    mNewTabPageManager = manager;
    mNewTabPageLayout = newTabPageLayout;
    mAboveTheFoldListItem = new AboveTheFoldListItem();
    mHeaderListItem = new SnippetHeaderListItem();
    mItemTouchCallbacks = new ItemTouchCallbacks();
    mNewTabPageListItems = new ArrayList<NewTabPageListItem>();
    mWantsSnippets = true;
    mSnippetsBridge = snippetsBridge;
    mStatusListItem = StatusListItem.create(snippetsBridge.getDisabledReason(), this, manager);

    loadSnippets(new ArrayList<SnippetArticle>());
    mSnippetsBridge.setObserver(this);
}
 
Example #3
Source File: ContentSuggestionsPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.suggestions_preferences);
    setHasOptionsMenu(true);
    finishSwitchInitialisation();

    boolean isEnabled = SnippetsBridge.areRemoteSuggestionsEnabled();
    mIsEnabled = !isEnabled; // Opposite so that we trigger side effects below.
    updatePreferences(isEnabled);

    @LaunchSource
    int launchSource =
            getActivity().getIntent().getIntExtra(LAUNCH_SOURCE_EXTRA, LAUNCH_SOURCE_SETTINGS);
    if (launchSource == LAUNCH_SOURCE_NOTIFICATION) {
        ContentSuggestionsNotificationHelper.recordNotificationAction(
                ContentSuggestionsNotificationAction.OPEN_SETTINGS);
    }
}
 
Example #4
Source File: SectionList.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the category is able to process the suggestions. The category might decide
 * not to show incoming suggestions later, but this check ensures it's in a basic state
 * compatible with displaying content.
 */
private boolean canProcessSuggestions(@CategoryInt int category, @CategoryStatus int status) {
    // If the category was blacklisted, we note that there might be new content to show.
    mBlacklistedCategories.remove(category);

    // We never want to add suggestions from unknown categories.
    if (!mSections.containsKey(category)) return false;

    // The status may have changed while the suggestions were loading, perhaps they should not
    // be displayed any more.
    if (!SnippetsBridge.isCategoryEnabled(status)) {
        Log.w(TAG, "Received suggestions for a disabled category (id=%d, status=%d)", category,
                status);
        return false;
    }

    return true;
}
 
Example #5
Source File: SuggestionsSection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public void addSuggestions(List<SnippetArticle> suggestions, @CategoryStatusEnum int status) {
    if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestionsList.clear();
    mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));

    Log.d(TAG, "addSuggestions: current number of suggestions: %d",
            mSuggestionsList.getItemCount());

    int sizeBefore = suggestions.size();

    // TODO(dgn): remove once the backend stops sending duplicates.
    if (suggestions.removeAll(mSuggestionsList.mSuggestions)) {
        Log.d(TAG, "addSuggestions: Removed duplicates from incoming suggestions. "
                        + "Count changed from %d to %d",
                sizeBefore, suggestions.size());
    }

    mSuggestionsList.addAll(suggestions);
    for (SnippetArticle article : suggestions) {
        if (!article.requiresExactOfflinePage()) {
            updateSnippetOfflineAvailability(article);
        }
    }

    refreshChildrenVisibility();
}
 
Example #6
Source File: SectionList.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Resets the sections, reloading the whole new tab page content.
 * @param alwaysAllowEmptySections Whether sections are always allowed to be displayed when
 *     they are empty, even when they are normally not.
 */
private void resetSections(boolean alwaysAllowEmptySections) {
    removeAllSections();

    SuggestionsSource suggestionsSource = mUiDelegate.getSuggestionsSource();
    int[] categories = suggestionsSource.getCategories();
    int[] suggestionsPerCategory = new int[categories.length];
    int visibleCategoriesCount = 0;
    int categoryIndex = 0;
    for (int category : categories) {
        int categoryStatus = suggestionsSource.getCategoryStatus(category);
        int suggestionsCount = 0;
        if (SnippetsBridge.isCategoryEnabled(categoryStatus)) {
            suggestionsCount = resetSection(category, categoryStatus, alwaysAllowEmptySections);
            if (mSections.get(category) != null) ++visibleCategoriesCount;
        }
        suggestionsPerCategory[categoryIndex] = suggestionsCount;
        ++categoryIndex;
    }

    maybeHideArticlesHeader();
    mUiDelegate.getEventReporter().onPageShown(
            categories, suggestionsPerCategory, visibleCategoriesCount);
}
 
Example #7
Source File: NewTabPageAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private boolean canLoadSuggestions(@CategoryInt int category, @CategoryStatusEnum int status) {
    // We never want to add suggestions from unknown categories.
    if (!mSections.containsKey(category)) return false;

    // The status may have changed while the suggestions were loading, perhaps they should not
    // be displayed any more.
    if (!SnippetsBridge.isCategoryEnabled(status)) {
        Log.w(TAG, "Received suggestions for a disabled category (id=%d, status=%d)", category,
                status);
        return false;
    }

    return true;
}
 
Example #8
Source File: SuggestionsSection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Sets the status for the section. Some statuses can cause the suggestions to be cleared. */
public void setStatus(@CategoryStatus int status) {
    if (!SnippetsBridge.isCategoryStatusAvailable(status)) {
        clearData();
        Log.d(TAG, "setStatus: unavailable status, cleared suggestions.");
    }
    mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));
}
 
Example #9
Source File: NewTabPageAdapter.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Start a request for new snippets. */
public void reloadSnippets() {
    SnippetsBridge.fetchSnippets(/*forceRequest=*/true);
}
 
Example #10
Source File: ChromeBackgroundService.java    From delion with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void fetchSnippets() {
    SnippetsBridge.fetchSnippets();
}
 
Example #11
Source File: NewTabPageUma.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void endRecording(Tab removeObserverFromTab) {
    if (removeObserverFromTab != null) removeObserverFromTab.removeObserver(this);
    RecordUserAction.record("MobileNTP.Snippets.VisitEnd");
    long visitTimeMs = SystemClock.elapsedRealtime() - mStartTimeMs;
    SnippetsBridge.onSuggestionTargetVisited(mCategory, visitTimeMs);
}
 
Example #12
Source File: ChromeBackgroundService.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void fetchSnippets() {
    SnippetsBridge.fetchRemoteSuggestionsFromBackground();
}
 
Example #13
Source File: ChromeBackgroundService.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void rescheduleFetching() {
    SnippetsBridge.rescheduleFetching();
}
 
Example #14
Source File: SuggestionsSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Sets the status for the section. Some statuses can cause the suggestions to be cleared. */
public void setStatus(@CategoryStatusEnum int status) {
    if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestionsList.clear();
    mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));
    refreshChildrenVisibility();
}
 
Example #15
Source File: ChromeBackgroundService.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void rescheduleFetching() {
    SnippetsBridge.rescheduleFetching();
}
 
Example #16
Source File: ChromeBackgroundService.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void fetchSnippets() {
    // Do not force regular background fetches.
    SnippetsBridge.fetchSnippets(/*forceRequest=*/false);
}
 
Example #17
Source File: NewTabPageAdapter.java    From delion with Apache License 2.0 4 votes vote down vote up
/** Start a request for new snippets. */
public void reloadSnippets() {
    mWantsSnippets = true;
    SnippetsBridge.fetchSnippets();
}
 
Example #18
Source File: ChromeBackgroundService.java    From delion with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected void rescheduleSnippets() {
    SnippetsBridge.rescheduleFetching();
}