Update Settings search result unique ids
- SearchResult stableIds are now DocIds from the database - DocIds are data reference key's hash, when the key is not empty or null - Otherwise, DocIds are a hashcode from a set of fields. Change-Id: Id36f7bf4ceaaa3a2bd326ecafbfe97fd0b247df2 Fixes: 37327194 Test: make RunSettingsRoboTest
This commit is contained in:
@@ -18,15 +18,18 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Data class as an interface for all Search Results.
|
||||
*/
|
||||
public class SearchResult implements Comparable<SearchResult> {
|
||||
|
||||
private static final String TAG = "SearchResult";
|
||||
|
||||
/**
|
||||
* Defines the lowest rank for a search result to be considered as ranked. Results with ranks
|
||||
* higher than this have no guarantee for sorting order.
|
||||
@@ -84,9 +87,10 @@ public class SearchResult implements Comparable<SearchResult> {
|
||||
/**
|
||||
* Stable id for this object.
|
||||
*/
|
||||
public final long stableId;
|
||||
public final int stableId;
|
||||
|
||||
protected SearchResult(Builder builder) {
|
||||
stableId = builder.mStableId;
|
||||
title = builder.mTitle;
|
||||
summary = builder.mSummary;
|
||||
breadcrumbs = builder.mBreadcrumbs;
|
||||
@@ -94,7 +98,6 @@ public class SearchResult implements Comparable<SearchResult> {
|
||||
icon = builder.mIcon;
|
||||
payload = builder.mResultPayload;
|
||||
viewType = payload.getType();
|
||||
stableId = Objects.hash(title, summary, breadcrumbs, rank, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,7 +121,7 @@ public class SearchResult implements Comparable<SearchResult> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) stableId;
|
||||
return stableId;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -128,13 +131,14 @@ public class SearchResult implements Comparable<SearchResult> {
|
||||
protected int mRank = 42;
|
||||
protected ResultPayload mResultPayload;
|
||||
protected Drawable mIcon;
|
||||
protected int mStableId;
|
||||
|
||||
public Builder addTitle(CharSequence title) {
|
||||
public Builder setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addSummary(CharSequence summary) {
|
||||
public Builder setSummary(CharSequence summary) {
|
||||
mSummary = summary;
|
||||
return this;
|
||||
}
|
||||
@@ -144,29 +148,37 @@ public class SearchResult implements Comparable<SearchResult> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addRank(int rank) {
|
||||
public Builder setRank(int rank) {
|
||||
if (rank >= 0 && rank <= 9) {
|
||||
mRank = rank;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addIcon(Drawable icon) {
|
||||
public Builder setIcon(Drawable icon) {
|
||||
mIcon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addPayload(ResultPayload payload) {
|
||||
public Builder setPayload(ResultPayload payload) {
|
||||
mResultPayload = payload;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setStableId(int stableId) {
|
||||
mStableId = stableId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SearchResult build() {
|
||||
// Check that all of the mandatory fields are set.
|
||||
if (mTitle == null) {
|
||||
throw new IllegalArgumentException("SearchResult missing title argument");
|
||||
if (TextUtils.isEmpty(mTitle)) {
|
||||
throw new IllegalStateException("SearchResult missing title argument");
|
||||
} else if (mStableId == 0) {
|
||||
Log.v(TAG, "No stable ID on SearchResult with title: " + mTitle);
|
||||
throw new IllegalStateException("SearchResult missing stableId argument");
|
||||
} else if (mResultPayload == null) {
|
||||
throw new IllegalArgumentException("SearchResult missing Payload argument");
|
||||
throw new IllegalStateException("SearchResult missing Payload argument");
|
||||
}
|
||||
return new SearchResult(this);
|
||||
}
|
||||
|
Reference in New Issue
Block a user