[Android] Add "mark video as seen" feature
Alexandre Perraud
git at videolan.org
Fri Jul 7 17:05:51 CEST 2017
vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri Jul 7 11:59:49 2017 +0200| [21671097221e900a6aa291f12cdebdc46bdbd2d4] | committer: Alexandre Perraud
Add "mark video as seen" feature
> https://code.videolan.org/videolan/vlc-android/commit/21671097221e900a6aa291f12cdebdc46bdbd2d4
---
.../src/org/videolan/medialibrary/media/MediaWrapper.java | 1 +
vlc-android/res/layout/video_grid_card.xml | 6 +++++-
vlc-android/res/layout/video_list_card.xml | 6 +++++-
vlc-android/src/org/videolan/vlc/PlaybackService.java | 8 +++++++-
.../src/org/videolan/vlc/gui/video/VideoListAdapter.java | 13 +++++++++++--
5 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
index 8e80ea23a..d08c8e023 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
@@ -63,6 +63,7 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
public final static int META_TITLE = 52;
public final static int META_CHAPTER = 53;
public final static int META_PROGRAM = 54;
+ public final static int META_SEEN = 55;
//video
public final static int META_VIDEOTRACK = 100;
public final static int META_ASPECT_RATIO = 101;
diff --git a/vlc-android/res/layout/video_grid_card.xml b/vlc-android/res/layout/video_grid_card.xml
index a8db395f6..a928ed2a4 100644
--- a/vlc-android/res/layout/video_grid_card.xml
+++ b/vlc-android/res/layout/video_grid_card.xml
@@ -14,6 +14,10 @@
type="org.videolan.medialibrary.media.MediaWrapper" />
<variable
+ name="seen"
+ type="long" />
+
+ <variable
name="time"
type="String" />
@@ -73,7 +77,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_seen_normal"
- android:visibility="gone"
+ android:visibility="@{seen == 0L ? View.GONE : View.VISIBLE}"
vlc:layout_constraintEnd_toEndOf="@+id/ml_item_thumbnail"
vlc:layout_constraintTop_toTopOf="@+id/ml_item_thumbnail" />
diff --git a/vlc-android/res/layout/video_list_card.xml b/vlc-android/res/layout/video_list_card.xml
index a3e2b9cee..2aaeff350 100644
--- a/vlc-android/res/layout/video_list_card.xml
+++ b/vlc-android/res/layout/video_list_card.xml
@@ -11,6 +11,10 @@
type="org.videolan.medialibrary.media.MediaWrapper" />
<variable
+ name="seen"
+ type="long" />
+
+ <variable
name="time"
type="String" />
@@ -69,7 +73,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_seen_normal"
- android:visibility="gone"
+ android:visibility="@{seen == 0L ? View.GONE : View.VISIBLE}"
vlc:layout_constraintEnd_toEndOf="@+id/ml_item_thumbnail"
vlc:layout_constraintTop_toTopOf="@+id/ml_item_thumbnail" />
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 4be73023a..666289a05 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -671,8 +671,14 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
//Save progress
long time = getTime();
float progress = time / (float)media.getLength();
- if (progress > 0.90f)
+ if (progress > 0.90f) {
+ //increase seen counter if more than 90% of the media have been seen
+ //and reset progress to 0
+ long incSeen = media.getSeen() + 1L;
+ media.setLongMeta(mMedialibrary, MediaWrapper.META_SEEN, incSeen);
+ media.setSeen(incSeen);
progress = 0f;
+ }
media.setTime(progress == 0f ? 0L : time);
media.setLongMeta(mMedialibrary, MediaWrapper.META_PROGRESS, (long) (progress*100));
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index a84c8b47d..d8ea5a9b7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -73,6 +73,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
final static int UPDATE_SELECTION = 0;
final static int UPDATE_THUMB = 1;
final static int UPDATE_TIME = 2;
+ final static int UPDATE_SEEN = 3;
private boolean mListMode = false;
private IEventsHandler mEventsHandler;
@@ -131,6 +132,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
AsyncImageLoader.loadPicture(holder.thumbView, media);
break;
case UPDATE_TIME:
+ case UPDATE_SEEN:
fillView(holder, media);
break;
case UPDATE_SELECTION:
@@ -246,6 +248,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
String resolution = "";
int max = 0;
int progress = 0;
+ long seen = 0L;
if (media.getType() == MediaWrapper.TYPE_GROUP) {
MediaGroup mediaGroup = (MediaGroup) media;
@@ -264,12 +267,14 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
}
}
resolution = Tools.getResolution(media);
+ seen = media.getSeen();
}
holder.binding.setVariable(BR.resolution, resolution);
holder.binding.setVariable(BR.time, text);
holder.binding.setVariable(BR.max, max);
holder.binding.setVariable(BR.progress, progress);
+ holder.binding.setVariable(BR.seen, seen);
}
public void setListMode(boolean value) {
@@ -545,7 +550,9 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
MediaWrapper oldItem = oldList.get(oldItemPosition);
MediaWrapper newItem = newList.get(newItemPosition);
- return oldItem.getTime() == newItem.getTime() && TextUtils.equals(oldItem.getArtworkMrl(), newItem.getArtworkMrl());
+ return oldItem.getTime() == newItem.getTime()
+ && TextUtils.equals(oldItem.getArtworkMrl(), newItem.getArtworkMrl())
+ && oldItem.getSeen() == newItem.getSeen();
}
@Nullable
@@ -555,8 +562,10 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
MediaWrapper newItem = newList.get(newItemPosition);
if (oldItem.getTime() != newItem.getTime())
return UPDATE_TIME;
- else
+ if (!TextUtils.equals(oldItem.getArtworkMrl(), newItem.getArtworkMrl()))
return UPDATE_THUMB;
+ else
+ return UPDATE_SEEN;
}
}
}
More information about the Android
mailing list