[Android] Set type to medialibrary items

Geoffrey Métais git at videolan.org
Fri Nov 4 11:50:56 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov  4 11:11:51 2016 +0100| [8ec4cb0d6c67abf23c90ff0a001ff39d22807720] | committer: Geoffrey Métais

Set type to medialibrary items

In order to avoid calls to instanceof

> https://code.videolan.org/videolan/vlc-android/commit/8ec4cb0d6c67abf23c90ff0a001ff39d22807720
---

 medialibrary/src/org/videolan/medialibrary/media/Album.java       | 5 +++++
 medialibrary/src/org/videolan/medialibrary/media/Artist.java      | 5 +++++
 medialibrary/src/org/videolan/medialibrary/media/DummyItem.java   | 5 +++++
 medialibrary/src/org/videolan/medialibrary/media/Genre.java       | 5 +++++
 .../src/org/videolan/medialibrary/media/MediaLibraryItem.java     | 8 ++++++++
 .../src/org/videolan/medialibrary/media/MediaWrapper.java         | 5 +++++
 medialibrary/src/org/videolan/medialibrary/media/Playlist.java    | 5 +++++
 7 files changed, 38 insertions(+)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/Album.java b/medialibrary/src/org/videolan/medialibrary/media/Album.java
index 41cc70e..6e8408f 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Album.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Album.java
@@ -57,6 +57,11 @@ public class Album extends MediaLibraryItem {
         return nativeGetTracksFromAlbum(ml, mId);
     }
 
+    @Override
+    public int getItemType() {
+        return TYPE_ALBUM;
+    }
+
     private native MediaWrapper[] nativeGetTracksFromAlbum(Medialibrary ml, long mId);
 
     @Override
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Artist.java b/medialibrary/src/org/videolan/medialibrary/media/Artist.java
index 43470af..b9cf0ae 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Artist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Artist.java
@@ -46,6 +46,11 @@ public class Artist extends MediaLibraryItem {
         return nativeGetMediaFromArtist(ml, mId);
     }
 
+    @Override
+    public int getItemType() {
+        return TYPE_ARTIST;
+    }
+
     private native Album[] nativeGetAlbumsFromArtist(Medialibrary ml, long mId);
     private native MediaWrapper[] nativeGetMediaFromArtist(Medialibrary ml, long mId);
 
diff --git a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
index df32b77..f05a403 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/DummyItem.java
@@ -17,6 +17,11 @@ public class DummyItem extends MediaLibraryItem {
     }
 
     @Override
+    public int getItemType() {
+        return TYPE_DUMMY;
+    }
+
+    @Override
     public void writeToParcel(Parcel parcel, int i) {
         super.writeToParcel(parcel, i);
     }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Genre.java b/medialibrary/src/org/videolan/medialibrary/media/Genre.java
index b594455..1fdfc41 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Genre.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Genre.java
@@ -23,6 +23,11 @@ public class Genre extends MediaLibraryItem {
         return nativeGetTracksFromGenre(ml, mId);
     }
 
+    @Override
+    public int getItemType() {
+        return TYPE_GENRE;
+    }
+
     private native Album[] nativeGetAlbumsFromGenre(Medialibrary ml, long mId);
     private native Artist[] nativeGetArtistsFromGenre(Medialibrary ml, long mId);
     private native MediaWrapper[] nativeGetTracksFromGenre(Medialibrary ml, long mId);
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index 3ea9d68..cb000ee 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -7,7 +7,15 @@ import org.videolan.medialibrary.Medialibrary;
 
 public abstract class MediaLibraryItem implements Parcelable {
 
+    public static final int TYPE_ALBUM = 0;
+    public static final int TYPE_ARTIST = 1;
+    public static final int TYPE_GENRE = 2;
+    public static final int TYPE_PLAYLIST = 3;
+    public static final int TYPE_MEDIA = 4;
+    public static final int TYPE_DUMMY = 5;
+
     public abstract MediaWrapper[] getTracks(Medialibrary ml);
+    public abstract int getItemType();
 
     protected long mId;
     protected String mTitle;
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
index 1ee1a7a..5db7866 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
@@ -265,6 +265,11 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
         return new MediaWrapper[] {this};
     }
 
+    @Override
+    public int getItemType() {
+        return TYPE_MEDIA;
+    }
+
     public long getId() {
         return mId;
     }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
index d4c0cb5..b8d5832 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Playlist.java
@@ -19,6 +19,11 @@ public class Playlist extends MediaLibraryItem {
         return nativeGetTracksFromPlaylist(ml, mId);
     }
 
+    @Override
+    public int getItemType() {
+        return TYPE_PLAYLIST;
+    }
+
     public boolean append(Medialibrary ml, long mediaId) {
         return nativePlaylistAppend(ml, mId, mediaId);
     }



More information about the Android mailing list