[Android] TV: Release bg images reference and restore them

Geoffrey Métais git at videolan.org
Fri Jun 16 16:36:11 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 16 16:27:53 2017 +0200| [9b98cb2cf251c77007460b8f889b5dedd6457bcd] | committer: Geoffrey Métais

TV: Release bg images reference and restore them

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

 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java |  8 ++++++++
 .../vlc/gui/tv/browser/MediaLibBrowserFragment.java | 21 +++++++++++++--------
 .../vlc/gui/tv/browser/SortedBrowserFragment.java   | 13 +++++++++++++
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 489263e67..1e93e4966 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -201,6 +201,13 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
     }
 
     @Override
+    protected void onStart() {
+        super.onStart();
+        if (mSelectedItem != null)
+            TvUtil.updateBackground(mBackgroundManager, mSelectedItem);
+    }
+
+    @Override
     protected void onStop() {
         super.onStop();
         if (AndroidDevices.isAndroidTv()) {
@@ -208,6 +215,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
                     RecommendationsService.class);
             startService(recommendationIntent);
         }
+        mBackgroundManager.release();
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
index 7a1c32771..1ee2a6593 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.tv.browser;
 
+import android.annotation.TargetApi;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
@@ -37,12 +38,11 @@ import org.videolan.medialibrary.Medialibrary;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.tv.TvUtil;
 
-import java.util.concurrent.CyclicBarrier;
-
+ at TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 public abstract class MediaLibBrowserFragment extends GridFragment implements OnItemViewSelectedListener {
-    protected final CyclicBarrier mBarrier = new CyclicBarrier(2);
     protected Medialibrary mMediaLibrary;
     private BackgroundManager mBackgroundManager;
+    private Object mSelectedItem;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -58,13 +58,17 @@ public abstract class MediaLibBrowserFragment extends GridFragment implements On
         setOnItemViewSelectedListener(this);
     }
 
-    public void onResume() {
-        super.onResume();
+    @Override
+    public void onStart() {
+        super.onStart();
+        if (mSelectedItem != null)
+            TvUtil.updateBackground(mBackgroundManager, mSelectedItem);
     }
 
-    public void onPause() {
-        super.onPause();
-        mBarrier.reset();
+    @Override
+    public void onStop() {
+        super.onStop();
+        mBackgroundManager.release();
     }
 
     public void refresh() {
@@ -77,6 +81,7 @@ public abstract class MediaLibBrowserFragment extends GridFragment implements On
     @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
     public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                                RowPresenter.ViewHolder rowViewHolder, Row row) {
+        mSelectedItem = item;
         TvUtil.updateBackground(mBackgroundManager, item);
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
index 1a61d37f1..6e5bc74e2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
@@ -113,12 +113,25 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
     }
 
     @Override
+    public void onStart() {
+        super.onStart();
+        if (mItemSelected != null)
+            TvUtil.updateBackground(mBackgroundManager, mItemSelected);
+    }
+
+    @Override
     public void onResume() {
         super.onResume();
         VLCApplication.storeData(CURRENT_BROWSER_LIST, mVideosList);
     }
 
     @Override
+    public void onStop() {
+        super.onStop();
+        mBackgroundManager.release();
+    }
+
+    @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         if (mItemSelected != null)



More information about the Android mailing list