aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-09-16 02:11:13 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-09-16 02:11:13 +0200
commit5ac939387f35e634bec23f79220e6f8e7ff909d9 (patch)
tree3af8e6dad5a4aa5e678563d2ee5ba39ee2ba9336 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
parentf90f86ae04cd3ecdc5ca1b9c9c013e8891ffc88e (diff)
downloadopen-keychain-5ac939387f35e634bec23f79220e6f8e7ff909d9.tar.gz
open-keychain-5ac939387f35e634bec23f79220e6f8e7ff909d9.tar.bz2
open-keychain-5ac939387f35e634bec23f79220e6f8e7ff909d9.zip
multidecrypt: put drawable cache in map attribute
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java85
1 files changed, 44 insertions, 41 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
index 857c8f283..27ad9cbb1 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java
@@ -260,7 +260,7 @@ public class DecryptListFragment
final Uri uri = mCurrentInputUri;
mCurrentInputUri = null;
- mAdapter.addResult(uri, result, null);
+ mAdapter.addResult(uri, result);
cryptoOperation();
}
@@ -295,37 +295,54 @@ public class DecryptListFragment
}
+ HashMap<Uri,Drawable> mIconCache = new HashMap<>();
+
private void processResult(final Uri uri) {
- new AsyncTask<Void, Void, Drawable>() {
+ new AsyncTask<Void, Void, Void>() {
@Override
- protected Drawable doInBackground(Void... params) {
+ protected Void doInBackground(Void... params) {
InputDataResult result = mInputDataResults.get(uri);
Context context = getActivity();
- OpenPgpMetadata metadata = result.mMetadata.get(0);
- Uri outputUri = result.getOutputUris().get(0);
- if (metadata == null || context == null || outputUri == null) {
+ if (context == null) {
return null;
}
- String type = metadata.getMimeType();
+ for (int i = 0; i < result.getOutputUris().size(); i++) {
- if (ClipDescription.compareMimeTypes(type, "image/*")) {
- int px = FormattingUtils.dpToPx(context, 48);
- Bitmap bitmap = FileHelper.getThumbnail(context, outputUri, new Point(px, px));
- return new BitmapDrawable(context.getResources(), bitmap);
- }
+ Uri outputUri = result.getOutputUris().get(i);
+ if (mIconCache.containsKey(outputUri)) {
+ continue;
+ }
- final Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(outputUri, type);
+ OpenPgpMetadata metadata = result.mMetadata.get(i);
+ String type = metadata.getMimeType();
+
+ Drawable icon = null;
+
+ if (ClipDescription.compareMimeTypes(type, "image/*")) {
+ int px = FormattingUtils.dpToPx(context, 48);
+ Bitmap bitmap = FileHelper.getThumbnail(context, outputUri, new Point(px, px));
+ icon = new BitmapDrawable(context.getResources(), bitmap);
+ } else {
+ final Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(outputUri, type);
+
+ final List<ResolveInfo> matches =
+ context.getPackageManager().queryIntentActivities(intent, 0);
+ // noinspection LoopStatementThatDoesntLoop
+ for (ResolveInfo match : matches) {
+ icon = match.loadIcon(getActivity().getPackageManager());
+ break;
+ }
+ }
+
+ if (icon != null) {
+ mIconCache.put(outputUri, icon);
+ }
- final List<ResolveInfo> matches =
- context.getPackageManager().queryIntentActivities(intent, 0);
- //noinspection LoopStatementThatDoesntLoop
- for (ResolveInfo match : matches) {
- return match.loadIcon(getActivity().getPackageManager());
}
return null;
@@ -333,20 +350,14 @@ public class DecryptListFragment
}
@Override
- protected void onPostExecute(Drawable icon) {
- processResult(uri, icon);
+ protected void onPostExecute(Void v) {
+ InputDataResult result = mInputDataResults.get(uri);
+ mAdapter.addResult(uri, result);
}
}.execute();
}
- private void processResult(final Uri uri, Drawable icon) {
-
- InputDataResult result = mInputDataResults.get(uri);
- mAdapter.addResult(uri, result, icon);
-
- }
-
public void retryUri(Uri uri) {
// never interrupt running operations!
@@ -521,7 +532,6 @@ public class DecryptListFragment
public class ViewModel {
Uri mInputUri;
InputDataResult mResult;
- Drawable mIcon;
int mProgress, mMax;
String mProgressMsg;
@@ -538,10 +548,6 @@ public class DecryptListFragment
mResult = result;
}
- void addIcon(Drawable icon) {
- mIcon = icon;
- }
-
boolean hasResult() {
return mResult != null;
}
@@ -671,11 +677,11 @@ public class DecryptListFragment
holder.vFilesize.setText(FileHelper.readableFileSize(size));
}
- if (model.mIcon != null) {
- holder.vThumbnail.setImageDrawable(model.mIcon);
- } else {
+ // if (model.mIcon != null) {
+ // holder.vThumbnail.setImageDrawable(model.mIcon);
+ //} else {
holder.vThumbnail.setImageResource(R.drawable.ic_doc_generic_am);
- }
+ //}
holder.vFile.setOnClickListener(new OnClickListener() {
@Override
@@ -787,16 +793,13 @@ public class DecryptListFragment
notifyItemChanged(pos);
}
- public void addResult(Uri uri, InputDataResult result, Drawable icon) {
+ public void addResult(Uri uri, InputDataResult result) {
ViewModel model = new ViewModel(uri);
int pos = mDataset.indexOf(model);
model = mDataset.get(pos);
model.addResult(result);
- if (icon != null) {
- model.addIcon(icon);
- }
notifyItemChanged(pos);
}