Merge changes from topics "remove_tile_summary_cache", "remove_tile_title"
* changes: Use getSummary() to get tile summary text. Use tile.getTitle(context) to get tile title.
This commit is contained in:
committed by
Android (Google) Code Review
commit
7e5ed0540f
@@ -355,9 +355,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
mCache.updateIcon(tileIcon, icon);
|
||||
}
|
||||
holder.icon.setImageDrawable(icon);
|
||||
holder.title.setText(tile.title);
|
||||
if (!TextUtils.isEmpty(tile.summary)) {
|
||||
holder.summary.setText(tile.summary);
|
||||
holder.title.setText(tile.getTitle(mContext));
|
||||
final CharSequence summary = tile.getSummary(mContext);
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.summary.setText(summary);
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
|
@@ -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,9 +424,11 @@ 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)
|
||||
&& TextUtils.equals(localTile.summary, targetTile.summary);
|
||||
// Only check id and summary for dashboard tile
|
||||
return localTile.getId() == targetTile.getId()
|
||||
&& TextUtils.equals(
|
||||
localTile.getSummaryReference(),
|
||||
targetTile.getSummaryReference());
|
||||
case TYPE_SUGGESTION_CONTAINER:
|
||||
case TYPE_CONDITION_CONTAINER:
|
||||
// Fall through to default
|
||||
|
@@ -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 {
|
||||
@@ -172,8 +172,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
|
||||
private void bindSummary(Preference preference, Tile tile) {
|
||||
if (tile.summary != null) {
|
||||
preference.setSummary(tile.summary);
|
||||
final CharSequence summary = tile.getSummary(mContext);
|
||||
if (summary != null) {
|
||||
preference.setSummary(summary);
|
||||
} else if (tile.getMetaData() != null
|
||||
&& tile.getMetaData().containsKey(META_DATA_PREFERENCE_SUMMARY_URI)) {
|
||||
// Set a placeholder summary before starting to fetch real summary, this is necessary
|
||||
@@ -183,9 +184,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
|
||||
final String uri = tile.getMetaData().getString(META_DATA_PREFERENCE_SUMMARY_URI);
|
||||
final String summary = TileUtils.getTextFromUri(
|
||||
final String summaryFromUri = TileUtils.getTextFromUri(
|
||||
mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY);
|
||||
ThreadUtils.postOnMainThread(() -> preference.setSummary(summary));
|
||||
ThreadUtils.postOnMainThread(() -> preference.setSummary(summaryFromUri));
|
||||
});
|
||||
} else {
|
||||
preference.setSummary(R.string.summary_placeholder);
|
||||
|
@@ -156,12 +156,12 @@ 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",
|
||||
key, tile.getDescription()));
|
||||
return;
|
||||
}
|
||||
pref.setSummary(tile.summary);
|
||||
pref.setSummary(tile.getSummary(pref.getContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.dashboard;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
@@ -96,29 +97,30 @@ public class SummaryLoader {
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "setSummary " + tile.title + " - " + summary);
|
||||
Log.d(TAG, "setSummary " + tile.getDescription() + " - " + summary);
|
||||
}
|
||||
|
||||
updateSummaryIfNeeded(tile, summary);
|
||||
updateSummaryIfNeeded(mActivity.getApplicationContext(), tile, summary);
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateSummaryIfNeeded(Tile tile, CharSequence summary) {
|
||||
if (TextUtils.equals(tile.summary, summary)) {
|
||||
void updateSummaryIfNeeded(Context context, Tile tile, CharSequence summary) {
|
||||
if (TextUtils.equals(tile.getSummary(context), 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;
|
||||
}
|
||||
mSummaryTextMap.put(mDashboardFeatureProvider.getDashboardKeyForTile(tile), summary);
|
||||
tile.summary = summary;
|
||||
tile.overrideSummary(summary);
|
||||
if (mSummaryConsumer != null) {
|
||||
mSummaryConsumer.notifySummaryChanged(tile);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "SummaryConsumer is null, skipping summary update for "
|
||||
+ tile.title);
|
||||
+ tile.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +217,7 @@ public class SummaryLoader {
|
||||
for (Tile tile : category.getTiles()) {
|
||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||
if (mSummaryTextMap.containsKey(key)) {
|
||||
tile.summary = mSummaryTextMap.get(key);
|
||||
tile.overrideSummary(mSummaryTextMap.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user