- public void onFileClick(OCFile file) {
-
- // If we are on a large device -> update fragment
- if (mDualPane) {
- // buttons in the details view are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction
- .replace(R.id.file_details_container,
- new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)),
- FileDetailFragment.FTAG);
- transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
- transaction.commit();
-
- } else { // small or medium screen device -> new Activity
- Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);
- showDetailsIntent.putExtra(FileDetailFragment.EXTRA_FILE, file);
- showDetailsIntent.putExtra(FileDetailFragment.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(this));
- startActivity(showDetailsIntent);
+ public void startImagePreview(OCFile file) {
+ Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
+ showDetailsIntent.putExtra(EXTRA_FILE, file);
+ showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
+ startActivity(showDetailsIntent);
+ }
+
+ /**
+ * Stars the preview of an already down media {@link OCFile}.
+ *
+ * @param file Media {@link OCFile} to preview.
+ * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
+ * @param autoplay When 'true', the playback will start without user interactions.
+ */
+ @Override
+ public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
+ Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+ setSecondFragment(mediaFragment);
+ updateFragmentsVisibility(true);
+ updateNavigationElementsInActionBar(file);
+ setFile(file);
+ }
+
+ /**
+ * Requests the download of the received {@link OCFile} , updates the UI
+ * to monitor the download progress and prepares the activity to preview
+ * or open the file when the download finishes.
+ *
+ * @param file {@link OCFile} to download and preview.
+ */
+ @Override
+ public void startDownloadForPreview(OCFile file) {
+ Fragment detailFragment = new FileDetailFragment(file, getAccount());
+ setSecondFragment(detailFragment);
+ mWaitingToPreview = file;
+ requestForDownload();
+ updateFragmentsVisibility(true);
+ updateNavigationElementsInActionBar(file);
+ setFile(file);
+ }
+
+
+ /**
+ * Shows the information of the {@link OCFile} received as a
+ * parameter in the second fragment.
+ *
+ * @param file {@link OCFile} whose details will be shown
+ */
+ @Override
+ public void showDetails(OCFile file) {
+ Fragment detailFragment = new FileDetailFragment(file, getAccount());
+ setSecondFragment(detailFragment);
+ updateFragmentsVisibility(true);
+ updateNavigationElementsInActionBar(file);
+ setFile(file);
+ }
+
+
+ /**
+ * TODO
+ */
+ private void updateNavigationElementsInActionBar(OCFile currentFile) {
+ ActionBar actionBar = getSupportActionBar();
+ if (currentFile == null || mDualPane) {
+ // only list of files - set for browsing through folders
+ OCFile currentDir = getCurrentDir();
+ actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
+ actionBar.setDisplayShowTitleEnabled(false);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ actionBar.setListNavigationCallbacks(mDirectories, this); // assuming mDirectories is updated
+
+ } else {
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowTitleEnabled(true);
+ actionBar.setTitle(currentFile.getFileName());
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);