Merge "Get clock title on demand"

This commit is contained in:
Treehugger Robot
2019-12-16 14:45:23 +00:00
committed by Gerrit Code Review
4 changed files with 9 additions and 9 deletions

View File

@@ -25,12 +25,12 @@ import java.util.function.Supplier;
final class ClockInfo { final class ClockInfo {
private final String mName; private final String mName;
private final String mTitle; private final Supplier<String> mTitle;
private final String mId; private final String mId;
private final Supplier<Bitmap> mThumbnail; private final Supplier<Bitmap> mThumbnail;
private final Supplier<Bitmap> mPreview; private final Supplier<Bitmap> mPreview;
private ClockInfo(String name, String title, String id, private ClockInfo(String name, Supplier<String> title, String id,
Supplier<Bitmap> thumbnail, Supplier<Bitmap> preview) { Supplier<Bitmap> thumbnail, Supplier<Bitmap> preview) {
mName = name; mName = name;
mTitle = title; mTitle = title;
@@ -50,7 +50,7 @@ final class ClockInfo {
* Gets the name (title) of the clock face to be shown in the picker app. * Gets the name (title) of the clock face to be shown in the picker app.
*/ */
String getTitle() { String getTitle() {
return mTitle; return mTitle.get();
} }
/** /**
@@ -80,7 +80,7 @@ final class ClockInfo {
static class Builder { static class Builder {
private String mName; private String mName;
private String mTitle; private Supplier<String> mTitle;
private String mId; private String mId;
private Supplier<Bitmap> mThumbnail; private Supplier<Bitmap> mThumbnail;
private Supplier<Bitmap> mPreview; private Supplier<Bitmap> mPreview;
@@ -94,7 +94,7 @@ final class ClockInfo {
return this; return this;
} }
public Builder setTitle(String title) { public Builder setTitle(Supplier<String> title) {
mTitle = title; mTitle = title;
return this; return this;
} }

View File

@@ -322,7 +322,7 @@ public final class ClockManager {
mClocks.put(plugin.getClass().getName(), plugin); mClocks.put(plugin.getClass().getName(), plugin);
mClockInfo.add(ClockInfo.builder() mClockInfo.add(ClockInfo.builder()
.setName(plugin.getName()) .setName(plugin.getName())
.setTitle(plugin.getTitle()) .setTitle(plugin::getTitle)
.setId(id) .setId(id)
.setThumbnail(plugin::getThumbnail) .setThumbnail(plugin::getThumbnail)
.setPreview(() -> plugin.getPreview(mWidth, mHeight)) .setPreview(() -> plugin.getPreview(mWidth, mHeight))

View File

@@ -57,7 +57,7 @@ public final class ClockInfoTest extends SysuiTestCase {
@Test @Test
public void testGetTitle() { public void testGetTitle() {
final String title = "title"; final String title = "title";
ClockInfo info = ClockInfo.builder().setTitle(title).build(); ClockInfo info = ClockInfo.builder().setTitle(() -> title).build();
assertThat(info.getTitle()).isEqualTo(title); assertThat(info.getTitle()).isEqualTo(title);
} }

View File

@@ -117,12 +117,12 @@ public final class ClockOptionsProviderTest extends SysuiTestCase {
public void testQuery_listOptions() { public void testQuery_listOptions() {
mClocks.add(ClockInfo.builder() mClocks.add(ClockInfo.builder()
.setName("name_a") .setName("name_a")
.setTitle("title_a") .setTitle(() -> "title_a")
.setId("id_a") .setId("id_a")
.build()); .build());
mClocks.add(ClockInfo.builder() mClocks.add(ClockInfo.builder()
.setName("name_b") .setName("name_b")
.setTitle("title_b") .setTitle(() -> "title_b")
.setId("id_b") .setId("id_b")
.build()); .build());
Cursor cursor = mProvider.query(mListOptionsUri, null, null, null); Cursor cursor = mProvider.query(mListOptionsUri, null, null, null);