mirror of
https://github.com/samsonjs/media.git
synced 2026-04-18 13:25:47 +00:00
Add year to MediaMetadata.
#minor-release PiperOrigin-RevId: 375674759
This commit is contained in:
parent
69394e6fb5
commit
50cae4b944
3 changed files with 37 additions and 3 deletions
|
|
@ -53,6 +53,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable private Integer totalTrackCount;
|
||||
@Nullable @FolderType private Integer folderType;
|
||||
@Nullable private Boolean isPlayable;
|
||||
@Nullable private Integer year;
|
||||
@Nullable private Bundle extras;
|
||||
|
||||
public Builder() {}
|
||||
|
|
@ -74,6 +75,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.totalTrackCount = mediaMetadata.totalTrackCount;
|
||||
this.folderType = mediaMetadata.folderType;
|
||||
this.isPlayable = mediaMetadata.isPlayable;
|
||||
this.year = mediaMetadata.year;
|
||||
this.extras = mediaMetadata.extras;
|
||||
}
|
||||
|
||||
|
|
@ -177,6 +179,12 @@ public final class MediaMetadata implements Bundleable {
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Sets the year. */
|
||||
public Builder setYear(@Nullable Integer year) {
|
||||
this.year = year;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the extras {@link Bundle}. */
|
||||
public Builder setExtras(@Nullable Bundle extras) {
|
||||
this.extras = extras;
|
||||
|
|
@ -301,6 +309,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable @FolderType public final Integer folderType;
|
||||
/** Optional boolean for media playability. */
|
||||
@Nullable public final Boolean isPlayable;
|
||||
/** Optional year. */
|
||||
@Nullable public final Integer year;
|
||||
/**
|
||||
* Optional extras {@link Bundle}.
|
||||
*
|
||||
|
|
@ -326,6 +336,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.totalTrackCount = builder.totalTrackCount;
|
||||
this.folderType = builder.folderType;
|
||||
this.isPlayable = builder.isPlayable;
|
||||
this.year = builder.year;
|
||||
this.extras = builder.extras;
|
||||
}
|
||||
|
||||
|
|
@ -358,7 +369,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
&& Util.areEqual(trackNumber, that.trackNumber)
|
||||
&& Util.areEqual(totalTrackCount, that.totalTrackCount)
|
||||
&& Util.areEqual(folderType, that.folderType)
|
||||
&& Util.areEqual(isPlayable, that.isPlayable);
|
||||
&& Util.areEqual(isPlayable, that.isPlayable)
|
||||
&& Util.areEqual(year, that.year);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -379,7 +391,8 @@ public final class MediaMetadata implements Bundleable {
|
|||
trackNumber,
|
||||
totalTrackCount,
|
||||
folderType,
|
||||
isPlayable);
|
||||
isPlayable,
|
||||
year);
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
|
@ -403,6 +416,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
FIELD_TOTAL_TRACK_COUNT,
|
||||
FIELD_FOLDER_TYPE,
|
||||
FIELD_IS_PLAYABLE,
|
||||
FIELD_YEAR,
|
||||
FIELD_EXTRAS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
|
@ -423,6 +437,7 @@ public final class MediaMetadata implements Bundleable {
|
|||
private static final int FIELD_TOTAL_TRACK_COUNT = 13;
|
||||
private static final int FIELD_FOLDER_TYPE = 14;
|
||||
private static final int FIELD_IS_PLAYABLE = 15;
|
||||
private static final int FIELD_YEAR = 16;
|
||||
private static final int FIELD_EXTRAS = 1000;
|
||||
|
||||
@Override
|
||||
|
|
@ -457,6 +472,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
if (isPlayable != null) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLAYABLE), isPlayable);
|
||||
}
|
||||
if (year != null) {
|
||||
bundle.putInt(keyForField(FIELD_YEAR), year);
|
||||
}
|
||||
if (extras != null) {
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
}
|
||||
|
|
@ -505,6 +523,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
if (bundle.containsKey(keyForField(FIELD_IS_PLAYABLE))) {
|
||||
builder.setIsPlayable(bundle.getBoolean(keyForField(FIELD_IS_PLAYABLE)));
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_YEAR))) {
|
||||
builder.setYear(bundle.getInt(keyForField(FIELD_YEAR)));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,14 @@ public final class TextInformationFrame extends Id3Frame {
|
|||
// Do nothing, invalid input.
|
||||
}
|
||||
break;
|
||||
case "TYE":
|
||||
case "TYER":
|
||||
try {
|
||||
builder.setYear(Integer.parseInt(value));
|
||||
} catch (NumberFormatException e) {
|
||||
// Do nothing, invalid input.
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public class MediaMetadataTest {
|
|||
assertThat(mediaMetadata.totalTrackCount).isNull();
|
||||
assertThat(mediaMetadata.folderType).isNull();
|
||||
assertThat(mediaMetadata.isPlayable).isNull();
|
||||
assertThat(mediaMetadata.year).isNull();
|
||||
assertThat(mediaMetadata.extras).isNull();
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +100,7 @@ public class MediaMetadataTest {
|
|||
.setTotalTrackCount(12)
|
||||
.setFolderType(MediaMetadata.FOLDER_TYPE_PLAYLISTS)
|
||||
.setIsPlayable(true)
|
||||
.setYear(2000)
|
||||
.setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o).
|
||||
.build();
|
||||
|
||||
|
|
@ -114,6 +116,7 @@ public class MediaMetadataTest {
|
|||
String albumTitle = "album title";
|
||||
String albumArtist = "album Artist";
|
||||
String trackNumberInfo = "11/17";
|
||||
String year = "2000";
|
||||
|
||||
List<Metadata.Entry> entries =
|
||||
ImmutableList.of(
|
||||
|
|
@ -124,7 +127,8 @@ public class MediaMetadataTest {
|
|||
new TextInformationFrame(
|
||||
/* id= */ "TP2", /* description= */ null, /* value= */ albumArtist),
|
||||
new TextInformationFrame(
|
||||
/* id= */ "TRK", /* description= */ null, /* value= */ trackNumberInfo));
|
||||
/* id= */ "TRK", /* description= */ null, /* value= */ trackNumberInfo),
|
||||
new TextInformationFrame(/* id= */ "TYE", /* description= */ null, /* value= */ year));
|
||||
MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
|
||||
|
||||
for (Metadata.Entry entry : entries) {
|
||||
|
|
@ -137,6 +141,7 @@ public class MediaMetadataTest {
|
|||
assertThat(builder.build().albumArtist.toString()).isEqualTo(albumArtist);
|
||||
assertThat(builder.build().trackNumber).isEqualTo(11);
|
||||
assertThat(builder.build().totalTrackCount).isEqualTo(17);
|
||||
assertThat(builder.build().year).isEqualTo(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue