[Android] State flags system for MediaLibraryItem class

Geoffrey Métais git at videolan.org
Thu Dec 8 18:12:47 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec  8 16:36:44 2016 +0100| [e5eb6b0355317f3c4e6190d9ef4ecc0bc8174e96] | committer: Geoffrey Métais

State flags system for MediaLibraryItem class

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

 .../medialibrary/media/MediaLibraryItem.java       | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index d6462e2..9f878d4 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -17,12 +17,16 @@ public abstract class MediaLibraryItem implements Parcelable {
     public static final int TYPE_STORAGE = 6;
     public static final int TYPE_HISTORY = 7;
 
+    public static final int FLAG_NONE = 0;
+    public static final int FLAG_SELECTED = 1;
+
 
     public abstract MediaWrapper[] getTracks(Medialibrary ml);
     public abstract int getItemType();
 
     long mId;
     protected String mTitle, mDescription;
+    int mFlags;
 
     protected MediaLibraryItem() {}
 
@@ -56,6 +60,30 @@ public abstract class MediaLibraryItem implements Parcelable {
     public void setDescription(String description) {
         mDescription = description;
     }
+
+    public void setStateFlags(int flags) {
+        mFlags = flags;
+    }
+
+    public void addStateFlags(int flags) {
+        mFlags |= flags;
+    }
+
+    public boolean hasStateFlags(int flags) {
+        return (mFlags & flags) != 0;
+    }
+
+    public void toggleStateFlag(int flag) {
+        if (hasStateFlags(flag))
+            removeStateFlags(flag);
+        else
+            addStateFlags(flag);
+    }
+
+    public void removeStateFlags(int flags) {
+        mFlags &= ~flags;
+    }
+
     @Override
     public void writeToParcel(Parcel parcel, int i) {
         parcel.writeLong(mId);



More information about the Android mailing list