From c4331a10fa23ebb3cb429304ff85716cb7e33125 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 12 May 2017 08:47:01 +0200 Subject: [PATCH] re-use second fragment if available --- .../ui/activity/FileDisplayActivity.java | 22 +++++++++---------- .../ui/preview/PreviewMediaFragment.java | 21 +++++------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 8f2b796ccc..8a1100c9f3 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -83,12 +83,12 @@ import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.ui.dialog.SortingOrderDialogFragment; import com.owncloud.android.ui.events.TokenPushEvent; -import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment; import com.owncloud.android.ui.fragment.ExtendedListFragment; import com.owncloud.android.ui.fragment.FileDetailFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; import com.owncloud.android.ui.fragment.TaskRetainerFragment; +import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment; import com.owncloud.android.ui.helpers.UriUploader; import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; @@ -428,7 +428,12 @@ public class FileDisplayActivity extends HookActivity /// Second fragment OCFile file = getFile(); - Fragment secondFragment = chooseInitialSecondFragment(file); + + Fragment secondFragment = getSecondFragment(); + if (secondFragment == null) { + secondFragment = chooseInitialSecondFragment(file); + } + if (secondFragment != null) { setSecondFragment(secondFragment); updateFragmentsVisibility(true); @@ -467,13 +472,9 @@ public class FileDisplayActivity extends HookActivity Fragment secondFragment = null; if (file != null && !file.isFolder()) { if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) { - int startPlaybackPosition = - getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0); - boolean autoplay = - getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true); - secondFragment = new PreviewMediaFragment(file, getAccount(), - startPlaybackPosition, autoplay); - + int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0); + boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true); + secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay); } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) { secondFragment = null; } else { @@ -547,8 +548,7 @@ public class FileDisplayActivity extends HookActivity } public FileFragment getSecondFragment() { - Fragment second = getSupportFragmentManager().findFragmentByTag( - FileDisplayActivity.TAG_SECOND_FRAGMENT); + Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT); if (second != null) { return (FileFragment) second; } diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 7022a34c66..2a6f9d5f03 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -234,14 +234,11 @@ public class PreviewMediaFragment extends FileFragment implements if (!file.isDown()) { throw new IllegalStateException("There is no local file to preview"); } - - } - else { - file = (OCFile) savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE); + } else { + file = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE); setFile(file); mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT); - mSavedPlaybackPosition = - savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION); + mSavedPlaybackPosition = savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION); mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING); } @@ -251,15 +248,12 @@ public class PreviewMediaFragment extends FileFragment implements mVideoPreview.setVisibility(View.VISIBLE); mImagePreview.setVisibility(View.GONE); prepareVideo(); - - } - else { + } else { mVideoPreview.setVisibility(View.GONE); mImagePreview.setVisibility(View.VISIBLE); extractAndSetCoverArt(file); } } - } /** @@ -307,11 +301,8 @@ public class PreviewMediaFragment extends FileFragment implements } else { if (mMediaServiceBinder != null) { - outState.putInt( - PreviewMediaFragment.EXTRA_PLAY_POSITION, - mMediaServiceBinder.getCurrentPosition()); - outState.putBoolean( - PreviewMediaFragment.EXTRA_PLAYING, mMediaServiceBinder.isPlaying()); + outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION, mMediaServiceBinder.getCurrentPosition()); + outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING, mMediaServiceBinder.isPlaying()); } } }