X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f0905fbaac2249eb08a57a27e4471d1b2ddfac98..a1bc147849ecef3fba9f9cfd9cdba037e762d14d:/src/com/owncloud/android/ui/preview/PreviewImageFragment.java diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 0995793d..581526c3 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -1,5 +1,8 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2014 ownCloud Inc. +/** + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -46,16 +49,18 @@ import android.widget.TextView; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.files.FileMenuFilter; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.utils.BitmapUtils; -import com.owncloud.android.utils.TouchImageViewCustom; +import third_parties.michaelOrtiz.TouchImageViewCustom; /** @@ -64,8 +69,6 @@ import com.owncloud.android.utils.TouchImageViewCustom; * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}. * * If the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too. - * - * @author David A. Velasco */ public class PreviewImageFragment extends FileFragment { @@ -78,6 +81,8 @@ public class PreviewImageFragment extends FileFragment { private TextView mMessageView; private ProgressBar mProgressWheel; + private Boolean mShowResizedImage = false; + public Bitmap mBitmap = null; private static final String TAG = PreviewImageFragment.class.getSimpleName(); @@ -92,13 +97,14 @@ public class PreviewImageFragment extends FileFragment { * * When 'imageFile' or 'ocAccount' are null * - * @param imageFile An {@link OCFile} to preview as an image in the fragment + * @param fileToDetail An {@link OCFile} to preview as an image in the fragment * @param ocAccount An ownCloud account; needed to start downloads * @param ignoreFirstSavedState Flag to work around an unexpected behaviour of {@link FragmentStatePagerAdapter}; TODO better solution */ - public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) { + public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState, boolean showResizedImage) { super(fileToDetail); mAccount = ocAccount; + mShowResizedImage = showResizedImage; mIgnoreFirstSavedState = ignoreFirstSavedState; } @@ -172,9 +178,6 @@ public class PreviewImageFragment extends FileFragment { if (mAccount == null) { throw new IllegalStateException("Instanced with a NULL ownCloud Account"); } - if (!getFile().isDown()) { - throw new IllegalStateException("There is no local file to preview"); - } } @@ -193,8 +196,43 @@ public class PreviewImageFragment extends FileFragment { public void onStart() { super.onStart(); if (getFile() != null) { - mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); - mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); + mImageView.setTag(getFile().getFileId()); + + if (mShowResizedImage){ + Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( + String.valueOf("r" + getFile().getRemoteId()) + ); + + if (thumbnail != null && !getFile().needsUpdateThumbnail()){ + mProgressWheel.setVisibility(View.GONE); + mImageView.setImageBitmap(thumbnail); + mImageView.setBitmap(thumbnail); + mImageView.setVisibility(View.VISIBLE); + mBitmap = thumbnail; + } else { + // generate new Thumbnail + if (ThumbnailsCacheManager.cancelPotentialWork(getFile(), mImageView)) { + final ThumbnailsCacheManager.ThumbnailGenerationTask task = + new ThumbnailsCacheManager.ThumbnailGenerationTask( + mImageView, mContainerActivity.getStorageManager(), mAccount, mProgressWheel + ); + if (thumbnail == null) { + thumbnail = ThumbnailsCacheManager.mDefaultImg; + } + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( + MainApp.getAppContext().getResources(), + thumbnail, + task + ); + mImageView.setImageDrawable(asyncDrawable); + task.execute(getFile(), false); + } + } + } else { + mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); + mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()}); + } } } @@ -293,8 +331,13 @@ public class PreviewImageFragment extends FileFragment { return true; } case R.id.action_send_file: { - mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile()); - return true; + if (getFile().isImage() && !getFile().isDown()){ + mContainerActivity.getFileOperationsHelper().sendCachedImage(getFile()); + return true; + } else { + mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile()); + return true; + } } case R.id.action_sync_file: { mContainerActivity.getFileOperationsHelper().syncFile(getFile()); @@ -360,7 +403,7 @@ public class PreviewImageFragment extends FileFragment { /** - * Weak reference to the target {@link Progressbar} shown while the load is in progress. + * Weak reference to the target {@link ProgressBar} shown while the load is in progress. * * Using a weak reference will avoid memory leaks if the target ImageView is retired from memory before the load finishes. */