re-use second fragment if available

This commit is contained in:
tobiasKaminsky 2017-05-12 08:47:01 +02:00
parent 8ec2a1de46
commit c4331a10fa
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 17 additions and 26 deletions

View file

@ -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;
}

View file

@ -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());
}
}
}