From: David A. Velasco Date: Thu, 5 Jul 2012 09:54:12 +0000 (+0200) Subject: FileDetailFragment is not reused in double pane view to avoid problems with preview... X-Git-Tag: oc-android-1.4.3~310 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8d3b028e7215def932d499b9f54c57c8927acf4e FileDetailFragment is not reused in double pane view to avoid problems with preview-imaegs and buttons refresh --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ac0ed718..aa9fb399 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.146B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 74c2ee5b..5245abf7 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -719,17 +719,11 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // If we are on a large device -> update fragment if (mDualPane) { - FileDetailFragment fileDetails = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG); - if (fileDetails == null) { - // first selected file since the current directory was listed - 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 { - // another select file - fileDetails.updateFileDetails(file, AccountUtils.getCurrentOwnCloudAccount(this)); - } + // 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' + 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); diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 627c26ab..0bf9564b 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -27,6 +27,8 @@ import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -44,10 +46,8 @@ import com.actionbarsherlock.app.SherlockFragment; import eu.alefzero.owncloud.DisplayUtils; import eu.alefzero.owncloud.R; -import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.files.services.FileDownloader; -import eu.alefzero.owncloud.utils.OwnCloudVersion; /** * This Fragment is used to display the details about a file. @@ -165,6 +165,17 @@ public class FileDetailFragment extends SherlockFragment implements getActivity().startService(i); } + + /** + * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced. + * + * @return True when the fragment was created with the empty layout. + */ + public boolean isEmpty() { + return mLayout == R.layout.file_details_empty; + } + + /** * Can be used to get the file that is currently being displayed. * @return The file on the screen. @@ -190,7 +201,8 @@ public class FileDetailFragment extends SherlockFragment implements */ public void updateFileDetails() { - if (mFile != null && mLayout == R.layout.file_details_fragment) { + if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) { + Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn); // set file details setFilename(mFile.getFileName()); @@ -203,9 +215,10 @@ public class FileDetailFragment extends SherlockFragment implements setTimeModified(mFile.getModificationTimestamp()); - // Update preview if (mFile.getStoragePath() != null) { + // Update preview ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview); + boolean previewIsSet = false; try { if (mFile.getMimetype().startsWith("image/")) { BitmapFactory.Options options = new Options(); @@ -220,17 +233,23 @@ public class FileDetailFragment extends SherlockFragment implements Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); - int width = options.outWidth; - int height = options.outHeight; - int scale = 1; - if (width >= 2048 || height >= 2048) { - scale = (int) (Math.ceil(Math.max(height, width)/2048.)); - options.inSampleSize = scale; - bmp.recycle(); + if (bmp != null) { + int width = options.outWidth; + int height = options.outHeight; + int scale = 1; + if (width >= 2048 || height >= 2048) { + scale = (int) (Math.ceil(Math.max(height, width)/2048.)); + options.inSampleSize = scale; + bmp.recycle(); - bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); + bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options); + } + } + if (bmp != null) { + //preview.setImageBitmap(bmp); + preview.setImageDrawable(new BitmapDrawable(preview.getResources(), bmp)); + previewIsSet = true; } - preview.setImageBitmap(bmp); } } catch (OutOfMemoryError e) { preview.setVisibility(View.INVISIBLE); @@ -243,7 +262,13 @@ public class FileDetailFragment extends SherlockFragment implements } catch (Throwable t) { preview.setVisibility(View.INVISIBLE); Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t); + + } finally { + if (!previewIsSet) { + resetPreview(); + } } + // Change download button to open button downloadButton.setText(R.string.filedetails_open); downloadButton.setOnClickListener(new OnClickListener() { @Override @@ -290,10 +315,13 @@ public class FileDetailFragment extends SherlockFragment implements } else { // Make download button effective downloadButton.setOnClickListener(this); + // Be sure that preview image is reset; the fragment is reused when possible, a preview of other file could be there + resetPreview(); } } } + /** * Updates the filename in view * @param filename to set @@ -387,5 +415,16 @@ public class FileDetailFragment extends SherlockFragment implements } + + /** + * Make the preview image shows the ownCloud logo. + * + * To be called when setting a preview image is not possible. + */ + private void resetPreview() { + ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview); + preview.setImageDrawable(getResources().getDrawable(R.drawable.owncloud_logo)); + } + }