\r
// If we are on a large device -> update fragment\r
if (mDualPane) {\r
- FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);\r
- if (fileDetails == null) {\r
- // first selected file since the current directory was listed\r
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
- transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
- transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);\r
- transaction.commit();\r
- } else {\r
- // another select file\r
- fileDetails.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this));\r
- } \r
+ // buttons in the details view a are problematic when trying to reuse an existing fragment; create always a new one solves some of them, BUT no all; downloads are 'dangerous'\r
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();\r
+ transaction.replace(R.id.file_details_container, new FileDetailFragment(file, AccountUtils.getCurrentOwnCloudAccount(this)), FileDetailFragment.FTAG);\r
+ transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);\r
+ transaction.commit();\r
\r
} else { // small or medium screen device -> new Activity\r
Intent showDetailsIntent = new Intent(this, FileDetailActivity.class);\r
import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
import android.graphics.BitmapFactory.Options;\r
+import android.graphics.drawable.BitmapDrawable;\r
+import android.graphics.drawable.Drawable;\r
import android.net.Uri;\r
import android.os.Bundle;\r
import android.util.Log;\r
\r
import eu.alefzero.owncloud.DisplayUtils;\r
import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
import eu.alefzero.owncloud.files.services.FileDownloader;\r
-import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
\r
/**\r
* This Fragment is used to display the details about a file.\r
getActivity().startService(i);\r
}\r
\r
+\r
+ /**\r
+ * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.\r
+ * \r
+ * @return True when the fragment was created with the empty layout.\r
+ */\r
+ public boolean isEmpty() {\r
+ return mLayout == R.layout.file_details_empty;\r
+ }\r
+\r
+ \r
/**\r
* Can be used to get the file that is currently being displayed.\r
* @return The file on the screen.\r
*/\r
public void updateFileDetails() {\r
\r
- if (mFile != null && mLayout == R.layout.file_details_fragment) {\r
+ if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
+ \r
Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
// set file details\r
setFilename(mFile.getFileName());\r
\r
setTimeModified(mFile.getModificationTimestamp());\r
\r
- // Update preview\r
if (mFile.getStoragePath() != null) {\r
+ // Update preview\r
ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
+ boolean previewIsSet = false;\r
try {\r
if (mFile.getMimetype().startsWith("image/")) {\r
BitmapFactory.Options options = new Options();\r
\r
Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
\r
- int width = options.outWidth;\r
- int height = options.outHeight;\r
- int scale = 1;\r
- if (width >= 2048 || height >= 2048) {\r
- scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
- options.inSampleSize = scale;\r
- bmp.recycle();\r
+ if (bmp != null) {\r
+ int width = options.outWidth;\r
+ int height = options.outHeight;\r
+ int scale = 1;\r
+ if (width >= 2048 || height >= 2048) {\r
+ scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
+ options.inSampleSize = scale;\r
+ bmp.recycle();\r
\r
- bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+ bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+ }\r
+ }\r
+ if (bmp != null) {\r
+ //preview.setImageBitmap(bmp);\r
+ preview.setImageDrawable(new BitmapDrawable(preview.getResources(), bmp));\r
+ previewIsSet = true;\r
}\r
- preview.setImageBitmap(bmp);\r
}\r
} catch (OutOfMemoryError e) {\r
preview.setVisibility(View.INVISIBLE);\r
} catch (Throwable t) {\r
preview.setVisibility(View.INVISIBLE);\r
Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
+ \r
+ } finally {\r
+ if (!previewIsSet) {\r
+ resetPreview();\r
+ }\r
}\r
+ // Change download button to open button\r
downloadButton.setText(R.string.filedetails_open);\r
downloadButton.setOnClickListener(new OnClickListener() {\r
@Override\r
} else {\r
// Make download button effective\r
downloadButton.setOnClickListener(this);\r
+ // Be sure that preview image is reset; the fragment is reused when possible, a preview of other file could be there\r
+ resetPreview();\r
}\r
}\r
}\r
\r
+ \r
/**\r
* Updates the filename in view\r
* @param filename to set\r
\r
}\r
\r
+ \r
+ /**\r
+ * Make the preview image shows the ownCloud logo.\r
+ * \r
+ * To be called when setting a preview image is not possible.\r
+ */\r
+ private void resetPreview() {\r
+ ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
+ preview.setImageDrawable(getResources().getDrawable(R.drawable.owncloud_logo));\r
+ }\r
+\r
\r
}\r