Commit 5e9b0c2f by tonihei Committed by Ian Baker

Deprecate MediaMetadata folderType and stabilize mediaType+isBrowsable

PiperOrigin-RevId: 522058915
parent 2e84360a
......@@ -60,7 +60,11 @@ public final class MediaMetadata implements Bundleable {
@Nullable private Uri artworkUri;
@Nullable private Integer trackNumber;
@Nullable private Integer totalTrackCount;
@Nullable private @FolderType Integer folderType;
@SuppressWarnings("deprecation") // Builder for deprecated field.
@Nullable
private @FolderType Integer folderType;
@Nullable private Boolean isBrowsable;
@Nullable private Boolean isPlayable;
@Nullable private Integer recordingYear;
......@@ -82,6 +86,7 @@ public final class MediaMetadata implements Bundleable {
public Builder() {}
@SuppressWarnings("deprecation") // Assigning from deprecated fields.
private Builder(MediaMetadata mediaMetadata) {
this.title = mediaMetadata.title;
this.artist = mediaMetadata.artist;
......@@ -250,9 +255,11 @@ public final class MediaMetadata implements Bundleable {
/**
* Sets the {@link FolderType}.
*
* <p>This method will be deprecated. Use {@link #setIsBrowsable} to indicate if an item is a
* browsable folder and use {@link #setMediaType} to indicate the type of the folder.
* @deprecated Use {@link #setIsBrowsable} to indicate if an item is a browsable folder and use
* {@link #setMediaType} to indicate the type of the folder.
*/
@SuppressWarnings("deprecation") // Using deprecated type.
@Deprecated
@CanIgnoreReturnValue
public Builder setFolderType(@Nullable @FolderType Integer folderType) {
this.folderType = folderType;
......@@ -452,6 +459,7 @@ public final class MediaMetadata implements Bundleable {
}
/** Populates all the fields from {@code mediaMetadata}, provided they are non-null. */
@SuppressWarnings("deprecation") // Populating deprecated fields.
@CanIgnoreReturnValue
public Builder populate(@Nullable MediaMetadata mediaMetadata) {
if (mediaMetadata == null) {
......@@ -745,12 +753,17 @@ public final class MediaMetadata implements Bundleable {
* <p>One of {@link #FOLDER_TYPE_NONE}, {@link #FOLDER_TYPE_MIXED}, {@link #FOLDER_TYPE_TITLES},
* {@link #FOLDER_TYPE_ALBUMS}, {@link #FOLDER_TYPE_ARTISTS}, {@link #FOLDER_TYPE_GENRES}, {@link
* #FOLDER_TYPE_PLAYLISTS} or {@link #FOLDER_TYPE_YEARS}.
*
* @deprecated Use {@link #isBrowsable} to indicate if an item is a browsable folder and use
* {@link #mediaType} to indicate the type of the folder.
*/
// @Target list includes both 'default' targets and TYPE_USE, to ensure backwards compatibility
// with Kotlin usages from before TYPE_USE was added.
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_USE})
@Deprecated
@SuppressWarnings("deprecation") // Defining deprecated constants.
@IntDef({
FOLDER_TYPE_NONE,
FOLDER_TYPE_MIXED,
......@@ -763,22 +776,60 @@ public final class MediaMetadata implements Bundleable {
})
public @interface FolderType {}
/** Type for an item that is not a folder. */
public static final int FOLDER_TYPE_NONE = -1;
/** Type for a folder containing media of mixed types. */
public static final int FOLDER_TYPE_MIXED = 0;
/** Type for a folder containing only playable media. */
public static final int FOLDER_TYPE_TITLES = 1;
/** Type for a folder containing media categorized by album. */
public static final int FOLDER_TYPE_ALBUMS = 2;
/** Type for a folder containing media categorized by artist. */
public static final int FOLDER_TYPE_ARTISTS = 3;
/** Type for a folder containing media categorized by genre. */
public static final int FOLDER_TYPE_GENRES = 4;
/** Type for a folder containing a playlist. */
public static final int FOLDER_TYPE_PLAYLISTS = 5;
/** Type for a folder containing media categorized by year. */
public static final int FOLDER_TYPE_YEARS = 6;
/**
* Type for an item that is not a folder.
*
* @deprecated Use {@link #isBrowsable} set to false instead.
*/
@Deprecated public static final int FOLDER_TYPE_NONE = -1;
/**
* Type for a folder containing media of mixed types.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_MIXED} instead.
*/
@Deprecated public static final int FOLDER_TYPE_MIXED = 0;
/**
* Type for a folder containing only playable media.
*
* @deprecated Use {@link #isBrowsable} set to true instead.
*/
@Deprecated public static final int FOLDER_TYPE_TITLES = 1;
/**
* Type for a folder containing media categorized by album.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_ALBUMS} instead.
*/
@Deprecated public static final int FOLDER_TYPE_ALBUMS = 2;
/**
* Type for a folder containing media categorized by artist.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_ARTISTS} instead.
*/
@Deprecated public static final int FOLDER_TYPE_ARTISTS = 3;
/**
* Type for a folder containing media categorized by genre.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_GENRES} instead.
*/
@Deprecated public static final int FOLDER_TYPE_GENRES = 4;
/**
* Type for a folder containing a playlist.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_PLAYLISTS} instead.
*/
@Deprecated public static final int FOLDER_TYPE_PLAYLISTS = 5;
/**
* Type for a folder containing media categorized by year.
*
* @deprecated Use {@link #isBrowsable} set to true and {@link #mediaType} set to {@link
* #MEDIA_TYPE_FOLDER_YEARS} instead.
*/
@Deprecated public static final int FOLDER_TYPE_YEARS = 6;
/**
* The picture type of the artwork.
......@@ -887,10 +938,13 @@ public final class MediaMetadata implements Bundleable {
/**
* Optional {@link FolderType}.
*
* <p>This field will be deprecated. Use {@link #isBrowsable} to indicate if an item is a
* browsable folder and use {@link #mediaType} to indicate the type of the folder.
* @deprecated Use {@link #isBrowsable} to indicate if an item is a browsable folder and use
* {@link #mediaType} to indicate the type of the folder.
*/
@Nullable public final @FolderType Integer folderType;
@SuppressWarnings("deprecation") // Defining field of deprecated type.
@Deprecated
@Nullable
public final @FolderType Integer folderType;
/** Optional boolean to indicate that the media is a browsable folder. */
@Nullable public final Boolean isBrowsable;
/** Optional boolean to indicate that the media is playable. */
......@@ -955,6 +1009,7 @@ public final class MediaMetadata implements Bundleable {
*/
@Nullable public final Bundle extras;
@SuppressWarnings("deprecation") // Assigning deprecated fields.
private MediaMetadata(Builder builder) {
// Handle compatibility for deprecated fields.
@Nullable Boolean isBrowsable = builder.isBrowsable;
......@@ -1013,6 +1068,7 @@ public final class MediaMetadata implements Bundleable {
return new Builder(/* mediaMetadata= */ this);
}
@SuppressWarnings("deprecation") // Comparing deprecated fields.
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
......@@ -1056,6 +1112,7 @@ public final class MediaMetadata implements Bundleable {
&& Util.areEqual(mediaType, that.mediaType);
}
@SuppressWarnings("deprecation") // Hashing deprecated fields.
@Override
public int hashCode() {
return Objects.hashCode(
......@@ -1130,6 +1187,7 @@ public final class MediaMetadata implements Bundleable {
private static final String FIELD_IS_BROWSABLE = Util.intToStringMaxRadix(32);
private static final String FIELD_EXTRAS = Util.intToStringMaxRadix(1000);
@SuppressWarnings("deprecation") // Bundling deprecated fields.
@Override
public Bundle toBundle() {
Bundle bundle = new Bundle();
......@@ -1238,6 +1296,7 @@ public final class MediaMetadata implements Bundleable {
/** Object that can restore {@link MediaMetadata} from a {@link Bundle}. */
public static final Creator<MediaMetadata> CREATOR = MediaMetadata::fromBundle;
@SuppressWarnings("deprecation") // Unbundling deprecated fields.
private static MediaMetadata fromBundle(Bundle bundle) {
Builder builder = new Builder();
builder
......@@ -1320,6 +1379,7 @@ public final class MediaMetadata implements Bundleable {
return builder.build();
}
@SuppressWarnings("deprecation") // Converting deprecated field.
private static @FolderType int getFolderTypeFromMediaType(@MediaType int mediaType) {
switch (mediaType) {
case MEDIA_TYPE_ALBUM:
......@@ -1369,6 +1429,7 @@ public final class MediaMetadata implements Bundleable {
}
}
@SuppressWarnings("deprecation") // Converting deprecated field.
private static @MediaType int getMediaTypeFromFolderType(@FolderType int folderType) {
switch (folderType) {
case FOLDER_TYPE_ALBUMS:
......
......@@ -30,6 +30,7 @@ public class MediaMetadataTest {
private static final String EXTRAS_KEY = "exampleKey";
private static final String EXTRAS_VALUE = "exampleValue";
@SuppressWarnings("deprecation") // Testing deprecated field.
@Test
public void builder_minimal_correctDefaults() {
MediaMetadata mediaMetadata = new MediaMetadata.Builder().build();
......@@ -134,6 +135,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadataFromBundle.extras.getString(EXTRAS_KEY)).isEqualTo(EXTRAS_VALUE);
}
@SuppressWarnings("deprecation") // Testing deprecated setter.
@Test
public void builderSetFolderType_toNone_setsIsBrowsableToFalse() {
MediaMetadata mediaMetadata =
......@@ -142,6 +144,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.isBrowsable).isFalse();
}
@SuppressWarnings("deprecation") // Testing deprecated setter.
@Test
public void builderSetFolderType_toNotNone_setsIsBrowsableToTrueAndMatchingMediaType() {
MediaMetadata mediaMetadata =
......@@ -151,6 +154,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.mediaType).isEqualTo(MediaMetadata.MEDIA_TYPE_FOLDER_PLAYLISTS);
}
@SuppressWarnings("deprecation") // Testing deprecated setter.
@Test
public void
builderSetFolderType_toNotNoneWithManualMediaType_setsIsBrowsableToTrueAndDoesNotOverrideMediaType() {
......@@ -164,6 +168,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.mediaType).isEqualTo(MediaMetadata.MEDIA_TYPE_FOLDER_PODCASTS);
}
@SuppressWarnings("deprecation") // Testing deprecated field.
@Test
public void builderSetIsBrowsable_toTrueWithoutMediaType_setsFolderTypeToMixed() {
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setIsBrowsable(true).build();
......@@ -171,6 +176,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.folderType).isEqualTo(MediaMetadata.FOLDER_TYPE_MIXED);
}
@SuppressWarnings("deprecation") // Testing deprecated field.
@Test
public void builderSetIsBrowsable_toTrueWithMediaType_setsFolderTypeToMatchMediaType() {
MediaMetadata mediaMetadata =
......@@ -182,6 +188,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.folderType).isEqualTo(MediaMetadata.FOLDER_TYPE_ARTISTS);
}
@SuppressWarnings("deprecation") // Testing deprecated field.
@Test
public void builderSetFolderType_toFalse_setsFolderTypeToNone() {
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setIsBrowsable(false).build();
......@@ -189,6 +196,7 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.folderType).isEqualTo(MediaMetadata.FOLDER_TYPE_NONE);
}
@SuppressWarnings("deprecation") // Setting deprecated fields.
private static MediaMetadata getFullyPopulatedMediaMetadata() {
Bundle extras = new Bundle();
extras.putString(EXTRAS_KEY, EXTRAS_VALUE);
......
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