[Android] Set seen feature as a preference

Alexandre Perraud git at videolan.org
Wed Jul 12 11:54:53 CEST 2017


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Tue Jul 11 10:27:09 2017 +0200| [3a8ab8d22725af12b07132c9f1a08d8fb35412cc] | committer: Alexandre Perraud

Set seen feature as a preference

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

 vlc-android/res/values/strings.xml                               | 2 ++
 vlc-android/res/xml/preferences_video.xml                        | 5 +++++
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java           | 5 +++++
 .../org/videolan/vlc/gui/preferences/PreferencesActivity.java    | 1 +
 .../src/org/videolan/vlc/gui/preferences/PreferencesVideo.java   | 3 +++
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java        | 5 +++++
 vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java | 9 ++++++++-
 7 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 6421432ce..d75407375 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -288,6 +288,8 @@
     <string name="video_min_group_length_first">First letter only</string>
     <string name="video_min_group_length_short">Short number of letters (6)</string>
     <string name="video_min_group_length_long">Long number of letters (9)</string>
+    <string name="media_seen">Show seen video marker</string>
+    <string name="media_seen_summary">Mark a video as seen when you play it until the end</string>
     <string name="force_list_portrait">No grid in portrait mode</string>
     <string name="force_list_portrait_summary">Show videos in list instead of grid in portrait mode</string>
     <string name="force_play_all_summary">Play all videos, starting with the one you clicked on</string>
diff --git a/vlc-android/res/xml/preferences_video.xml b/vlc-android/res/xml/preferences_video.xml
index 58ee7b115..09777614a 100644
--- a/vlc-android/res/xml/preferences_video.xml
+++ b/vlc-android/res/xml/preferences_video.xml
@@ -14,6 +14,11 @@
         android:title="@string/video_min_group_length_title" />
 
     <CheckBoxPreference
+        android:defaultValue="true"
+        android:key="media_seen"
+        android:summary="@string/media_seen_summary"
+        android:title="@string/media_seen" />
+    <CheckBoxPreference
         android:defaultValue="false"
         android:key="force_list_portrait"
         android:summary="@string/force_list_portrait_summary"
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 2a0d26087..676f757e4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -655,6 +655,11 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
                     finish();
                     startActivity(intent);
                     break;
+                case PreferencesActivity.RESULT_UPDATE_SEEN_MEDIA:
+                    for (Fragment fragment : getSupportFragmentManager().getFragments())
+                        if (fragment instanceof VideoGridFragment)
+                            ((VideoGridFragment) fragment).updateSeenMediaMarker();
+                    break;
             }
         } else if (requestCode == ACTIVITY_RESULT_OPEN && resultCode == RESULT_OK){
             MediaUtils.openUri(this, data.getData());
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
index 66bde4590..599ec9743 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
@@ -53,6 +53,7 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
     public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
     public final static int RESULT_RESTART = RESULT_FIRST_USER + 2;
     public final static int RESULT_RESTART_APP = RESULT_FIRST_USER + 3;
+    public final static int RESULT_UPDATE_SEEN_MEDIA = RESULT_FIRST_USER + 4;
 
     private PlaybackService.Client mClient = new PlaybackService.Client(this, this);
     private PlaybackService mService;
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
index b4981d67e..4f7b343e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
@@ -49,6 +49,9 @@ public class PreferencesVideo extends BasePreferenceFragment {
             case "force_list_portrait":
                 ((PreferencesActivity) getActivity()).setRestart();
                 return true;
+            case "media_seen":
+                getActivity().setResult(PreferencesActivity.RESULT_UPDATE_SEEN_MEDIA);
+                break;
         }
         return super.onPreferenceTreeClick(preference);
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 0a1c20eed..100229a61 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -591,4 +591,9 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
         updateEmptyView();
         setFabPlayVisibility(true);
     }
+
+    public void updateSeenMediaMarker() {
+        mVideoAdapter.setSeenMediaMarkerVisible(PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("media_seen", true));
+        mVideoAdapter.notifyItemRangeChanged(0, mVideoAdapter.getItemCount()-1, VideoListAdapter.UPDATE_SEEN);
+    }
 }
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 d8ea5a9b7..120061855 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -85,9 +85,12 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     private int mSelectionCount = 0;
     private int mGridCardWidth = 0;
 
+    private boolean mIsSeenMediaMarkerVisible = true;
+
     VideoListAdapter(IEventsHandler eventsHandler) {
         super();
         mEventsHandler = eventsHandler;
+        mIsSeenMediaMarkerVisible = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("media_seen", true);
     }
 
     VideoComparator getComparator() {
@@ -267,7 +270,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                 }
             }
             resolution = Tools.getResolution(media);
-            seen = media.getSeen();
+            seen = mIsSeenMediaMarkerVisible ? media.getSeen() : 0L;
         }
 
         holder.binding.setVariable(BR.resolution, resolution);
@@ -568,4 +571,8 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                 return UPDATE_SEEN;
         }
     }
+
+    public void setSeenMediaMarkerVisible(boolean seenMediaMarkerVisible) {
+        mIsSeenMediaMarkerVisible = seenMediaMarkerVisible;
+    }
 }



More information about the Android mailing list