Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileGroupDelegateImpl.java

Issue 2758753003: 📰 Refresh the tiles when a removal is undone (Closed)
Patch Set: address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.suggestions; 5 package org.chromium.chrome.browser.suggestions;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Context; 8 import android.content.Context;
9 import android.os.Build; 9 import android.os.Build;
10 10
11 import org.chromium.base.Callback;
11 import org.chromium.base.CommandLine; 12 import org.chromium.base.CommandLine;
12 import org.chromium.base.VisibleForTesting; 13 import org.chromium.base.VisibleForTesting;
13 import org.chromium.base.metrics.RecordUserAction; 14 import org.chromium.base.metrics.RecordUserAction;
14 import org.chromium.chrome.R; 15 import org.chromium.chrome.R;
15 import org.chromium.chrome.browser.ChromeActivity; 16 import org.chromium.chrome.browser.ChromeActivity;
16 import org.chromium.chrome.browser.ChromeSwitches; 17 import org.chromium.chrome.browser.ChromeSwitches;
17 import org.chromium.chrome.browser.ntp.NewTabPageUma; 18 import org.chromium.chrome.browser.ntp.NewTabPageUma;
18 import org.chromium.chrome.browser.profiles.Profile; 19 import org.chromium.chrome.browser.profiles.Profile;
19 import org.chromium.chrome.browser.snackbar.Snackbar; 20 import org.chromium.chrome.browser.snackbar.Snackbar;
20 import org.chromium.chrome.browser.snackbar.SnackbarManager; 21 import org.chromium.chrome.browser.snackbar.SnackbarManager;
(...skipping 25 matching lines...) Expand all
46 public TileGroupDelegateImpl(ChromeActivity activity, Profile profile, 47 public TileGroupDelegateImpl(ChromeActivity activity, Profile profile,
47 TabModelSelector tabModelSelector, SuggestionsNavigationDelegate nav igationDelegate) { 48 TabModelSelector tabModelSelector, SuggestionsNavigationDelegate nav igationDelegate) {
48 mContext = activity; 49 mContext = activity;
49 mSnackbarManager = activity.getSnackbarManager(); 50 mSnackbarManager = activity.getSnackbarManager();
50 mTabModelSelector = tabModelSelector; 51 mTabModelSelector = tabModelSelector;
51 mNavigationDelegate = navigationDelegate; 52 mNavigationDelegate = navigationDelegate;
52 mMostVisitedSites = buildMostVisitedSites(profile); 53 mMostVisitedSites = buildMostVisitedSites(profile);
53 } 54 }
54 55
55 @Override 56 @Override
56 public void removeMostVisitedItem(Tile item) { 57 public void removeMostVisitedItem(Tile item, Callback<String> removalUndoneC allback) {
57 assert !mIsDestroyed; 58 assert !mIsDestroyed;
58 59
59 mMostVisitedSites.addBlacklistedUrl(item.getUrl()); 60 mMostVisitedSites.addBlacklistedUrl(item.getUrl());
60 showTileRemovedSnackbar(item.getUrl()); 61 showTileRemovedSnackbar(item.getUrl(), removalUndoneCallback);
61 } 62 }
62 63
63 @Override 64 @Override
64 public void openMostVisitedItem(int windowDisposition, Tile item) { 65 public void openMostVisitedItem(int windowDisposition, Tile item) {
65 assert !mIsDestroyed; 66 assert !mIsDestroyed;
66 67
67 String url = item.getUrl(); 68 String url = item.getUrl();
68 69
69 // TODO(treib): Should we call recordOpenedMostVisitedItem here? 70 // TODO(treib): Should we call recordOpenedMostVisitedItem here?
70 if (windowDisposition != WindowOpenDisposition.NEW_WINDOW) { 71 if (windowDisposition != WindowOpenDisposition.NEW_WINDOW) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } else { 121 } else {
121 return new MostVisitedSites(profile); 122 return new MostVisitedSites(profile);
122 } 123 }
123 } 124 }
124 125
125 @VisibleForTesting 126 @VisibleForTesting
126 public static void setMostVisitedSitesForTests(MostVisitedSites mostVisitedS itesForTests) { 127 public static void setMostVisitedSitesForTests(MostVisitedSites mostVisitedS itesForTests) {
127 sMostVisitedSitesForTests = mostVisitedSitesForTests; 128 sMostVisitedSitesForTests = mostVisitedSitesForTests;
128 } 129 }
129 130
130 private void showTileRemovedSnackbar(String url) { 131 private void showTileRemovedSnackbar(String url, final Callback<String> remo valUndoneCallback) {
131 if (mTileRemovedSnackbarController == null) { 132 if (mTileRemovedSnackbarController == null) {
132 mTileRemovedSnackbarController = new SnackbarController() { 133 mTileRemovedSnackbarController = new SnackbarController() {
133 @Override 134 @Override
134 public void onDismissNoAction(Object actionData) {} 135 public void onDismissNoAction(Object actionData) {}
135 136
136 /** Undoes the tile removal. */ 137 /** Undoes the tile removal. */
137 @Override 138 @Override
138 public void onAction(Object actionData) { 139 public void onAction(Object actionData) {
139 if (mIsDestroyed) return; 140 if (mIsDestroyed) return;
140 String url = (String) actionData; 141 String url = (String) actionData;
142 removalUndoneCallback.onResult(url);
141 mMostVisitedSites.removeBlacklistedUrl(url); 143 mMostVisitedSites.removeBlacklistedUrl(url);
142 } 144 }
143 }; 145 };
144 } 146 }
145 Snackbar snackbar = Snackbar.make(mContext.getString(R.string.most_visit ed_item_removed), 147 Snackbar snackbar = Snackbar.make(mContext.getString(R.string.most_visit ed_item_removed),
146 mTileRemovedSnackbarController, Snac kbar.TYPE_ACTION, 148 mTileRemovedSnackbarController, Snac kbar.TYPE_ACTION,
147 Snackbar.UMA_NTP_MOST_VISITED_DELETE _UNDO) 149 Snackbar.UMA_NTP_MOST_VISITED_DELETE _UNDO)
148 .setAction(mContext.getString(R.string.undo) , url); 150 .setAction(mContext.getString(R.string.undo) , url);
149 mSnackbarManager.showSnackbar(snackbar); 151 mSnackbarManager.showSnackbar(snackbar);
150 } 152 }
(...skipping 29 matching lines...) Expand all
180 } 182 }
181 } 183 }
182 return false; 184 return false;
183 } 185 }
184 186
185 private static boolean matchURLs(String url1, String url2, boolean matchByHo st) { 187 private static boolean matchURLs(String url1, String url2, boolean matchByHo st) {
186 if (url1 == null || url2 == null) return false; 188 if (url1 == null || url2 == null) return false;
187 return matchByHost ? UrlUtilities.sameHost(url1, url2) : url1.equals(url 2); 189 return matchByHost ? UrlUtilities.sameHost(url1, url2) : url1.equals(url 2);
188 } 190 }
189 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698