aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain
diff options
context:
space:
mode:
authormar-v-in <github@rvin.mooo.com>2014-08-01 12:41:30 +0200
committermar-v-in <github@rvin.mooo.com>2014-08-01 12:41:30 +0200
commitb206b6d351e38c96eb44d801a45c872844c1a0fd (patch)
treee1b113017e15f60e4c0e7ca0198886ff61d1f818 /OpenKeychain
parent1ebb92b33638e427befa37fd2b6eef67ed3e4b88 (diff)
downloadopen-keychain-b206b6d351e38c96eb44d801a45c872844c1a0fd.tar.gz
open-keychain-b206b6d351e38c96eb44d801a45c872844c1a0fd.tar.bz2
open-keychain-b206b6d351e38c96eb44d801a45c872844c1a0fd.zip
Cache input file thumbnail.
Diffstat (limited to 'OpenKeychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
index 1125dce77..7538d2a56 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFileFragment.java
@@ -38,9 +38,13 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
+import org.sufficientlysecure.keychain.util.Log;
import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
public class EncryptFileFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
public static final String ARG_URIS = "uris";
@@ -55,6 +59,7 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
private View mShareFile;
private View mEncryptFile;
private SelectedFilesAdapter mAdapter = new SelectedFilesAdapter();
+ private final Map<Uri, Bitmap> thumbnailCache = new HashMap<Uri, Bitmap>();
@Override
public void onAttach(Activity activity) {
@@ -237,6 +242,14 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
@Override
public void onNotifyUpdate() {
+ // Clear cache if needed
+ for (Uri uri : new HashSet<Uri>(thumbnailCache.keySet())) {
+ if (!mEncryptInterface.getInputUris().contains(uri)) {
+ Log.d(Constants.TAG, "Removed thumbnail for uri: "+uri);
+ thumbnailCache.remove(uri);
+ }
+ }
+
mAdapter.notifyDataSetChanged();
}
@@ -258,14 +271,15 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
+ Uri inputUri = mEncryptInterface.getInputUris().get(position);
View view;
if (convertView == null) {
view = getActivity().getLayoutInflater().inflate(R.layout.file_list_entry, null);
} else {
view = convertView;
}
- ((TextView) view.findViewById(R.id.filename)).setText(FileHelper.getFilename(getActivity(), mEncryptInterface.getInputUris().get(position)));
- long size = FileHelper.getFileSize(getActivity(), mEncryptInterface.getInputUris().get(position));
+ ((TextView) view.findViewById(R.id.filename)).setText(FileHelper.getFilename(getActivity(), inputUri));
+ long size = FileHelper.getFileSize(getActivity(), inputUri);
if (size == -1) {
((TextView) view.findViewById(R.id.filesize)).setText("");
} else {
@@ -278,7 +292,10 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
}
});
int px = OtherHelper.dpToPx(getActivity(), 48);
- Bitmap bitmap = FileHelper.getThumbnail(getActivity(), mEncryptInterface.getInputUris().get(position), new Point(px, px));
+ if (!thumbnailCache.containsKey(inputUri)) {
+ thumbnailCache.put(inputUri, FileHelper.getThumbnail(getActivity(), inputUri, new Point(px, px)));
+ }
+ Bitmap bitmap = thumbnailCache.get(inputUri);
if (bitmap != null) {
((ImageView) view.findViewById(R.id.thumbnail)).setImageBitmap(bitmap);
} else {