Commit 7d81f20f by samrobinson Committed by Oliver Woodman

Add disc fields to MediaMetadata.

PiperOrigin-RevId: 379469182
parent f90d0a26
......@@ -57,6 +57,8 @@ public final class MediaMetadata implements Bundleable {
@Nullable private CharSequence writer;
@Nullable private CharSequence composer;
@Nullable private CharSequence conductor;
@Nullable private Integer discNumber;
@Nullable private Integer totalDiscCount;
@Nullable private Bundle extras;
public Builder() {}
......@@ -82,6 +84,8 @@ public final class MediaMetadata implements Bundleable {
this.writer = mediaMetadata.writer;
this.composer = mediaMetadata.composer;
this.conductor = mediaMetadata.conductor;
this.discNumber = mediaMetadata.discNumber;
this.totalDiscCount = mediaMetadata.totalDiscCount;
this.extras = mediaMetadata.extras;
}
......@@ -209,6 +213,18 @@ public final class MediaMetadata implements Bundleable {
return this;
}
/** Sets the disc number. */
public Builder setDiscNumber(@Nullable Integer discNumber) {
this.discNumber = discNumber;
return this;
}
/** Sets the total number of discs. */
public Builder setTotalDiscCount(@Nullable Integer totalDiscCount) {
this.totalDiscCount = totalDiscCount;
return this;
}
/** Sets the extras {@link Bundle}. */
public Builder setExtras(@Nullable Bundle extras) {
this.extras = extras;
......@@ -344,6 +360,10 @@ public final class MediaMetadata implements Bundleable {
@Nullable public final CharSequence composer;
/** Optional conductor. */
@Nullable public final CharSequence conductor;
/** Optional disc number. */
@Nullable public final Integer discNumber;
/** Optional total number of discs. */
@Nullable public final Integer totalDiscCount;
/**
* Optional extras {@link Bundle}.
......@@ -374,6 +394,8 @@ public final class MediaMetadata implements Bundleable {
this.writer = builder.writer;
this.composer = builder.composer;
this.conductor = builder.conductor;
this.discNumber = builder.discNumber;
this.totalDiscCount = builder.totalDiscCount;
this.extras = builder.extras;
}
......@@ -410,7 +432,9 @@ public final class MediaMetadata implements Bundleable {
&& Util.areEqual(year, that.year)
&& Util.areEqual(writer, that.writer)
&& Util.areEqual(composer, that.composer)
&& Util.areEqual(conductor, that.conductor);
&& Util.areEqual(conductor, that.conductor)
&& Util.areEqual(discNumber, that.discNumber)
&& Util.areEqual(totalDiscCount, that.totalDiscCount);
}
@Override
......@@ -432,10 +456,12 @@ public final class MediaMetadata implements Bundleable {
totalTrackCount,
folderType,
isPlayable,
year,
writer,
composer,
conductor,
year);
discNumber,
totalDiscCount);
}
// Bundleable implementation.
......@@ -463,6 +489,8 @@ public final class MediaMetadata implements Bundleable {
FIELD_WRITER,
FIELD_COMPOSER,
FIELD_CONDUCTOR,
FIELD_DISC_NUMBER,
FIELD_TOTAL_DISC_COUNT,
FIELD_EXTRAS
})
private @interface FieldNumber {}
......@@ -487,6 +515,8 @@ public final class MediaMetadata implements Bundleable {
private static final int FIELD_WRITER = 17;
private static final int FIELD_COMPOSER = 18;
private static final int FIELD_CONDUCTOR = 19;
private static final int FIELD_DISC_NUMBER = 20;
private static final int FIELD_TOTAL_DISC_COUNT = 21;
private static final int FIELD_EXTRAS = 1000;
@Override
......@@ -527,6 +557,12 @@ public final class MediaMetadata implements Bundleable {
if (year != null) {
bundle.putInt(keyForField(FIELD_YEAR), year);
}
if (discNumber != null) {
bundle.putInt(keyForField(FIELD_DISC_NUMBER), discNumber);
}
if (totalDiscCount != null) {
bundle.putInt(keyForField(FIELD_TOTAL_DISC_COUNT), totalDiscCount);
}
if (extras != null) {
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
}
......@@ -581,6 +617,12 @@ public final class MediaMetadata implements Bundleable {
if (bundle.containsKey(keyForField(FIELD_YEAR))) {
builder.setYear(bundle.getInt(keyForField(FIELD_YEAR)));
}
if (bundle.containsKey(keyForField(FIELD_DISC_NUMBER))) {
builder.setDiscNumber(bundle.getInt(keyForField(FIELD_DISC_NUMBER)));
}
if (bundle.containsKey(keyForField(FIELD_TOTAL_DISC_COUNT))) {
builder.setTotalDiscCount(bundle.getInt(keyForField(FIELD_TOTAL_DISC_COUNT)));
}
return builder.build();
}
......
......@@ -58,6 +58,8 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.composer).isNull();
assertThat(mediaMetadata.conductor).isNull();
assertThat(mediaMetadata.writer).isNull();
assertThat(mediaMetadata.discNumber).isNull();
assertThat(mediaMetadata.totalDiscCount).isNull();
assertThat(mediaMetadata.extras).isNull();
}
......@@ -107,6 +109,8 @@ public class MediaMetadataTest {
.setComposer("Composer")
.setConductor("Conductor")
.setWriter("Writer")
.setDiscNumber(1)
.setTotalDiscCount(3)
.setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o).
.build();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment