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