[Android] Add content fragment only on activity creation

Geoffrey Métais git at videolan.org
Mon Oct 30 17:55:06 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct 30 16:44:27 2017 +0100| [b60eba5033c0bc03cc8dbe8c6b4180c7ceeb3046] | committer: Geoffrey Métais

Add content fragment only on activity creation

on re-creation, fragment will be restored

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

 .../vlc/gui/tv/browser/VerticalGridActivity.java   | 62 +++++++++++-----------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index 3638a0d1f..51df6fb58 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -49,38 +49,40 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.tv_vertical_grid);
-        mContentLoadingProgressBar = (ProgressBar) findViewById(R.id.tv_fragment_progress);
-        mEmptyView = (TextView) findViewById(R.id.tv_fragment_empty);
-        long type = getIntent().getLongExtra(MainTvActivity.BROWSER_TYPE, -1);
-        if (type == MainTvActivity.HEADER_VIDEO)
-            mFragment = new VideoBrowserFragment();
-        else if (type == MainTvActivity.HEADER_CATEGORIES)
-            if (getIntent().getLongExtra(MusicFragment.AUDIO_CATEGORY, MusicFragment.CATEGORY_SONGS) == MusicFragment.CATEGORY_SONGS &&
-                VLCApplication.getMLInstance().getAudioCount() > GRID_LIMIT) {
-                mFragment = new SongsBrowserFragment();
-            } else {
-                mFragment = new MusicFragment();
-                Bundle args = new Bundle();
-                args.putParcelable(MusicFragment.AUDIO_ITEM, getIntent().getParcelableExtra(MusicFragment.AUDIO_ITEM));
-                ((Fragment)mFragment).setArguments(args);
+        mContentLoadingProgressBar = findViewById(R.id.tv_fragment_progress);
+        mEmptyView = findViewById(R.id.tv_fragment_empty);
+        if (savedInstanceState == null) {
+            long type = getIntent().getLongExtra(MainTvActivity.BROWSER_TYPE, -1);
+            if (type == MainTvActivity.HEADER_VIDEO)
+                mFragment = new VideoBrowserFragment();
+            else if (type == MainTvActivity.HEADER_CATEGORIES)
+                if (getIntent().getLongExtra(MusicFragment.AUDIO_CATEGORY, MusicFragment.CATEGORY_SONGS) == MusicFragment.CATEGORY_SONGS &&
+                    VLCApplication.getMLInstance().getAudioCount() > GRID_LIMIT) {
+                    mFragment = new SongsBrowserFragment();
+                } else {
+                    mFragment = new MusicFragment();
+                    Bundle args = new Bundle();
+                    args.putParcelable(MusicFragment.AUDIO_ITEM, getIntent().getParcelableExtra(MusicFragment.AUDIO_ITEM));
+                    ((Fragment)mFragment).setArguments(args);
+                }
+            else if (type == MainTvActivity.HEADER_NETWORK) {
+                Uri uri = getIntent().getData();
+                if (uri == null)
+                    uri = getIntent().getParcelableExtra(SortedBrowserFragment.KEY_URI);
+                if (uri == null)
+                    mFragment = new BrowserGridFragment();
+                else
+                    mFragment = new NetworkBrowserFragment();
+            } else if (type == MainTvActivity.HEADER_DIRECTORIES)
+                mFragment = new DirectoryBrowserFragment();
+            else {
+                finish();
+                return;
             }
-        else if (type == MainTvActivity.HEADER_NETWORK) {
-            Uri uri = getIntent().getData();
-            if (uri == null)
-                uri = getIntent().getParcelableExtra(SortedBrowserFragment.KEY_URI);
-            if (uri == null)
-                mFragment = new BrowserGridFragment();
-            else
-                mFragment = new NetworkBrowserFragment();
-        } else if (type == MainTvActivity.HEADER_DIRECTORIES)
-            mFragment = new DirectoryBrowserFragment();
-        else {
-            finish();
-            return;
+            getSupportFragmentManager().beginTransaction()
+                    .add(R.id.tv_fragment_placeholder, ((Fragment)mFragment))
+                    .commit();
         }
-        getSupportFragmentManager().beginTransaction()
-                .add(R.id.tv_fragment_placeholder, ((Fragment)mFragment))
-                .commit();
     }
 
     @Override



More information about the Android mailing list