Use tile.getTitle(context) to get tile title.

And switch to getId() instead of title when comparing 2 tiles. This is
more accurate and more efficient.

Bug: 77600770
Test: robotests
Change-Id: I587d90702d98956bf7b420529ac3280351ca4a10
This commit is contained in:
Fan Zhang
2018-08-17 11:36:20 -07:00
parent e97c21b58d
commit 54cfb64987
9 changed files with 32 additions and 32 deletions

View File

@@ -355,7 +355,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
mCache.updateIcon(tileIcon, icon);
}
holder.icon.setImageDrawable(icon);
holder.title.setText(tile.title);
holder.title.setText(tile.getTitle(mContext));
if (!TextUtils.isEmpty(tile.summary)) {
holder.summary.setText(tile.summary);
holder.summary.setVisibility(View.VISIBLE);

View File

@@ -33,7 +33,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Description about data list used in the DashboardAdapter. In the data list each item can be
@@ -147,7 +146,7 @@ public class DashboardData {
* Find the position of the Tile object.
* <p>
* First, try to find the exact identical instance of the tile object, if not found,
* then try to find a tile has the same title.
* then try to find a tile has the same id.
*
* @param tile tile that need to be found
* @return position of the object, return INDEX_NOT_FOUND if object isn't in the list
@@ -158,7 +157,7 @@ public class DashboardData {
final Object entity = mItems.get(i).entity;
if (entity == tile) {
return i;
} else if (entity instanceof Tile && tile.title.equals(((Tile) entity).title)) {
} else if (entity instanceof Tile && tile.getId() == ((Tile) entity).getId()) {
return i;
}
}
@@ -227,7 +226,7 @@ public class DashboardData {
final List<Tile> tiles = mCategory.getTiles();
for (int i = 0; i < tiles.size(); i++) {
final Tile tile = tiles.get(i);
addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
addToItemList(tile, R.layout.dashboard_tile, tile.getId(),
true /* add */);
}
}
@@ -425,8 +424,8 @@ public class DashboardData {
final Tile localTile = (Tile) entity;
final Tile targetTile = (Tile) targetItem.entity;
// Only check title and summary for dashboard tile
return TextUtils.equals(localTile.title, targetTile.title)
// Only check id and summary for dashboard tile
return localTile.getId() == targetTile.getId()
&& TextUtils.equals(localTile.summary, targetTile.summary);
case TYPE_SUGGESTION_CONTAINER:
case TYPE_CONDITION_CONTAINER:

View File

@@ -106,7 +106,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
if (pref == null) {
return;
}
pref.setTitle(tile.title);
pref.setTitle(tile.getTitle(activity.getApplicationContext()));
if (!TextUtils.isEmpty(key)) {
pref.setKey(key);
} else {

View File

@@ -156,9 +156,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
final Preference pref = getPreferenceScreen().findPreference(key);
if (pref == null) {
Log.d(getLogTag(),
String.format("Can't find pref by key %s, skipping update summary %s/%s",
key, tile.title, tile.summary));
Log.d(getLogTag(), String.format(
"Can't find pref by key %s, skipping update summary %s/%s",
key, tile.getDescription(), tile.summary));
return;
}
pref.setSummary(tile.summary);

View File

@@ -96,7 +96,7 @@ public class SummaryLoader {
return;
}
if (DEBUG) {
Log.d(TAG, "setSummary " + tile.title + " - " + summary);
Log.d(TAG, "setSummary " + tile.getDescription() + " - " + summary);
}
updateSummaryIfNeeded(tile, summary);
@@ -107,7 +107,8 @@ public class SummaryLoader {
void updateSummaryIfNeeded(Tile tile, CharSequence summary) {
if (TextUtils.equals(tile.summary, summary)) {
if (DEBUG) {
Log.d(TAG, "Summary doesn't change, skipping summary update for " + tile.title);
Log.d(TAG, "Summary doesn't change, skipping summary update for "
+ tile.getDescription());
}
return;
}
@@ -118,7 +119,7 @@ public class SummaryLoader {
} else {
if (DEBUG) {
Log.d(TAG, "SummaryConsumer is null, skipping summary update for "
+ tile.title);
+ tile.getDescription());
}
}
}