Commit 21671097 authored by Alexandre Perraud's avatar Alexandre Perraud

Add "mark video as seen" feature

parent 0b269320
......@@ -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;
......
......@@ -13,6 +13,10 @@
name="media"
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" />
......
......@@ -10,6 +10,10 @@
name="media"
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" />
......
......@@ -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));
}
......
......@@ -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;
}
}
}
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 to comment