Search in sources :

Example 1 with SnackbarController

use of org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController in project AndroidChromium by JackyAndroid.

the class NewTabPage method showMostVisitedItemRemovedSnackbar.

private void showMostVisitedItemRemovedSnackbar(String url) {
    if (mMostVisitedItemRemovedController == null) {
        mMostVisitedItemRemovedController = new SnackbarController() {

            @Override
            public void onDismissNoAction(Object actionData) {
            }

            /** Undoes the most visited item removal. */
            @Override
            public void onAction(Object actionData) {
                if (mIsDestroyed)
                    return;
                String url = (String) actionData;
                mMostVisitedSites.removeBlacklistedUrl(url);
            }
        };
    }
    Context context = mNewTabPageView.getContext();
    Snackbar snackbar = Snackbar.make(context.getString(R.string.most_visited_item_removed), mMostVisitedItemRemovedController, Snackbar.TYPE_ACTION, Snackbar.UMA_NTP_MOST_VISITED_DELETE_UNDO).setAction(context.getString(R.string.undo), url);
    mTab.getSnackbarManager().showSnackbar(snackbar);
}
Also used : Context(android.content.Context) SnackbarController(org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController) Snackbar(org.chromium.chrome.browser.snackbar.Snackbar)

Example 2 with SnackbarController

use of org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController in project AndroidChromium by JackyAndroid.

the class BookmarkUtils method addOrEditBookmark.

/**
     * If the tab has already been bookmarked, start {@link BookmarkEditActivity} for the
     * bookmark. If not, add the bookmark to bookmarkmodel, and show a snackbar notifying the user.
     *
     * Note: Takes ownership of bookmarkModel, and will call |destroy| on it when finished.
     *
     * @param existingBookmarkId The bookmark ID if the tab has already been bookmarked.
     * @param bookmarkModel The bookmark model.
     * @param tab The tab to add or edit a bookmark.
     * @param snackbarManager The SnackbarManager used to show the snackbar.
     * @param activity Current activity.
     * @return Bookmark ID of the bookmark. Could be <code>null</code> if bookmark didn't exist
     *   and bookmark model failed to create it.
     */
public static BookmarkId addOrEditBookmark(long existingBookmarkId, BookmarkModel bookmarkModel, Tab tab, SnackbarManager snackbarManager, Activity activity) {
    if (existingBookmarkId != Tab.INVALID_BOOKMARK_ID) {
        BookmarkId bookmarkId = new BookmarkId(existingBookmarkId, BookmarkType.NORMAL);
        startEditActivity(activity, bookmarkId);
        bookmarkModel.destroy();
        return bookmarkId;
    }
    BookmarkId parent = getLastUsedParent(activity);
    if (parent == null || !bookmarkModel.doesBookmarkExist(parent)) {
        parent = bookmarkModel.getDefaultFolder();
    }
    String url = tab.getOriginalUrl();
    BookmarkId bookmarkId = bookmarkModel.addBookmark(parent, bookmarkModel.getChildCount(parent), tab.getTitle(), url);
    Snackbar snackbar = null;
    if (bookmarkId == null) {
        snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_failed), new SnackbarController() {

            @Override
            public void onDismissNoAction(Object actionData) {
            }

            @Override
            public void onAction(Object actionData) {
            }
        }, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_BOOKMARK_ADDED).setSingleLine(false);
        RecordUserAction.record("EnhancedBookmarks.AddingFailed");
    } else {
        String folderName = bookmarkModel.getBookmarkTitle(bookmarkModel.getBookmarkById(bookmarkId).getParentId());
        SnackbarController snackbarController = createSnackbarControllerForEditButton(activity, bookmarkId);
        if (getLastUsedParent(activity) == null) {
            snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_saved), snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED);
        } else {
            snackbar = Snackbar.make(folderName, snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED).setTemplateText(activity.getString(R.string.bookmark_page_saved_folder));
        }
        snackbar.setSingleLine(false).setAction(activity.getString(R.string.bookmark_item_edit), null);
    }
    snackbarManager.showSnackbar(snackbar);
    bookmarkModel.destroy();
    return bookmarkId;
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) SnackbarController(org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController) Snackbar(org.chromium.chrome.browser.snackbar.Snackbar)

Example 3 with SnackbarController

use of org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController in project AndroidChromium by JackyAndroid.

the class OfflinePageUtils method createReloadSnackbarController.

/**
     * Gets a snackbar controller that we can use to show our snackbar.
     * @param tabModelSelector used to retrieve a tab by ID
     */
private static SnackbarController createReloadSnackbarController(final TabModelSelector tabModelSelector) {
    Log.d(TAG, "building snackbar controller");
    return new SnackbarController() {

        @Override
        public void onAction(Object actionData) {
            assert actionData != null;
            int tabId = (int) actionData;
            RecordUserAction.record("OfflinePages.ReloadButtonClicked");
            Tab foundTab = tabModelSelector.getTabById(tabId);
            if (foundTab == null)
                return;
            // Delegates to Tab to reload the page. Tab will send the correct header in order to
            // load the right page.
            foundTab.reload();
        }

        @Override
        public void onDismissNoAction(Object actionData) {
            RecordUserAction.record("OfflinePages.ReloadButtonNotClicked");
        }
    };
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) SnackbarController(org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController)

Example 4 with SnackbarController

use of org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController in project AndroidChromium by JackyAndroid.

the class OfflinePageUtils method showOfflineSnackbarIfNecessary.

/**
     * Shows the snackbar for the current tab to provide offline specific information if needed.
     * @param activity The activity owning the tab.
     * @param tab The current tab.
     */
public static void showOfflineSnackbarIfNecessary(ChromeActivity activity, Tab tab) {
    if (OfflinePageTabObserver.getInstance() == null) {
        SnackbarController snackbarController = createReloadSnackbarController(activity.getTabModelSelector());
        OfflinePageTabObserver.init(activity.getBaseContext(), activity.getSnackbarManager(), snackbarController);
    }
    showOfflineSnackbarIfNecessary(tab);
}
Also used : SnackbarController(org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController)

Aggregations

SnackbarController (org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController)4 Snackbar (org.chromium.chrome.browser.snackbar.Snackbar)2 Context (android.content.Context)1 Tab (org.chromium.chrome.browser.tab.Tab)1 BookmarkId (org.chromium.components.bookmarks.BookmarkId)1