Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java |
| index 3b150b8d5bc2f4079f80b08b8103c16b6eaedbb5..63c519cfa993191465c961a83de9cf7f773df44b 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/ListUrlsActivity.java |
| @@ -36,7 +36,9 @@ import org.chromium.chrome.browser.widget.FadingShadow; |
| import org.chromium.chrome.browser.widget.FadingShadowView; |
| import org.chromium.components.location.LocationUtils; |
| +import java.util.ArrayList; |
| import java.util.Collection; |
| +import java.util.List; |
| /** |
| * This activity displays a list of nearby URLs as stored in the {@link UrlManager}. |
| @@ -73,6 +75,7 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O |
| private boolean mIsRefreshing; |
| private boolean mIsRefreshUserInitiated; |
| private NearbyForegroundSubscription mNearbyForegroundSubscription; |
| + private List<PwsResult> mPwsResults; |
|
gone
2016/08/10 00:29:18
private final List<PwsResult> mPwsResults = new Ar
cco3
2016/08/12 18:22:10
Done.
|
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| @@ -123,6 +126,7 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O |
| mIsRefreshing = false; |
| mIsRefreshUserInitiated = false; |
| mNearbyForegroundSubscription = new NearbyForegroundSubscription(this); |
| + mPwsResults = new ArrayList<>(); |
| } |
| @Override |
| @@ -212,16 +216,14 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O |
| PhysicalWebUma.onForegroundPwsResolution(ListUrlsActivity.this, duration); |
| } |
| - // filter out duplicate site URLs. |
| + // filter out duplicate groups. |
| for (PwsResult pwsResult : pwsResults) { |
| - String siteUrl = pwsResult.siteUrl; |
| - String iconUrl = pwsResult.iconUrl; |
| - |
| - if (siteUrl != null && !mAdapter.hasSiteUrl(siteUrl)) { |
| + mPwsResults.add(pwsResult); |
| + if (!mAdapter.hasGroupId(pwsResult.groupId)) { |
| mAdapter.add(pwsResult); |
| - if (iconUrl != null && !mAdapter.hasIcon(iconUrl)) { |
| - fetchIcon(iconUrl); |
| + if (pwsResult.iconUrl != null && !mAdapter.hasIcon(pwsResult.iconUrl)) { |
| + fetchIcon(pwsResult.iconUrl); |
| } |
| } |
| } |
| @@ -240,8 +242,22 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O |
| @Override |
| public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { |
| PhysicalWebUma.onUrlSelected(this); |
| - PwsResult pwsResult = mAdapter.getItem(position); |
| - Intent intent = createNavigateToUrlIntent(pwsResult); |
| + PwsResult minPwsResult = mAdapter.getItem(position); |
| + String groupId = minPwsResult.groupId; |
| + |
| + // Make sure the PwsResult corresponds to the closest UrlDevice in the group. |
| + double minDistance = Double.MAX_VALUE; |
| + for (PwsResult pwsResult : mPwsResults) { |
| + if (pwsResult.groupId.equals(groupId)) { |
| + double distance = UrlManager.getInstance() |
| + .getUrlInfoByUrl(pwsResult.requestUrl).getDistance(); |
| + if (distance < minDistance) { |
| + minDistance = distance; |
| + minPwsResult = pwsResult; |
| + } |
| + } |
| + } |
| + Intent intent = createNavigateToUrlIntent(minPwsResult); |
| mContext.startActivity(intent); |
| } |
| @@ -289,6 +305,7 @@ public class ListUrlsActivity extends AppCompatActivity implements AdapterView.O |
| (AnimationDrawable) mScanningImageView.getDrawable(); |
| animationDrawable.start(); |
| + mPwsResults.clear(); |
| resolve(urls, isUserInitiated); |
| } |
| } |