multidecrypt: put drawable cache in map attribute
This commit is contained in:
@@ -260,7 +260,7 @@ public class DecryptListFragment
|
|||||||
final Uri uri = mCurrentInputUri;
|
final Uri uri = mCurrentInputUri;
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
|
|
||||||
mAdapter.addResult(uri, result, null);
|
mAdapter.addResult(uri, result);
|
||||||
|
|
||||||
cryptoOperation();
|
cryptoOperation();
|
||||||
}
|
}
|
||||||
@@ -295,37 +295,54 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashMap<Uri,Drawable> mIconCache = new HashMap<>();
|
||||||
|
|
||||||
private void processResult(final Uri uri) {
|
private void processResult(final Uri uri) {
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Drawable>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Drawable doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
||||||
InputDataResult result = mInputDataResults.get(uri);
|
InputDataResult result = mInputDataResults.get(uri);
|
||||||
|
|
||||||
Context context = getActivity();
|
Context context = getActivity();
|
||||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
if (context == null) {
|
||||||
Uri outputUri = result.getOutputUris().get(0);
|
|
||||||
if (metadata == null || context == null || outputUri == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String type = metadata.getMimeType();
|
for (int i = 0; i < result.getOutputUris().size(); i++) {
|
||||||
|
|
||||||
if (ClipDescription.compareMimeTypes(type, "image/*")) {
|
Uri outputUri = result.getOutputUris().get(i);
|
||||||
int px = FormattingUtils.dpToPx(context, 48);
|
if (mIconCache.containsKey(outputUri)) {
|
||||||
Bitmap bitmap = FileHelper.getThumbnail(context, outputUri, new Point(px, px));
|
continue;
|
||||||
return new BitmapDrawable(context.getResources(), bitmap);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
OpenPgpMetadata metadata = result.mMetadata.get(i);
|
||||||
intent.setDataAndType(outputUri, type);
|
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;
|
return null;
|
||||||
@@ -333,20 +350,14 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Drawable icon) {
|
protected void onPostExecute(Void v) {
|
||||||
processResult(uri, icon);
|
InputDataResult result = mInputDataResults.get(uri);
|
||||||
|
mAdapter.addResult(uri, result);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processResult(final Uri uri, Drawable icon) {
|
|
||||||
|
|
||||||
InputDataResult result = mInputDataResults.get(uri);
|
|
||||||
mAdapter.addResult(uri, result, icon);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void retryUri(Uri uri) {
|
public void retryUri(Uri uri) {
|
||||||
|
|
||||||
// never interrupt running operations!
|
// never interrupt running operations!
|
||||||
@@ -521,7 +532,6 @@ public class DecryptListFragment
|
|||||||
public class ViewModel {
|
public class ViewModel {
|
||||||
Uri mInputUri;
|
Uri mInputUri;
|
||||||
InputDataResult mResult;
|
InputDataResult mResult;
|
||||||
Drawable mIcon;
|
|
||||||
|
|
||||||
int mProgress, mMax;
|
int mProgress, mMax;
|
||||||
String mProgressMsg;
|
String mProgressMsg;
|
||||||
@@ -538,10 +548,6 @@ public class DecryptListFragment
|
|||||||
mResult = result;
|
mResult = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addIcon(Drawable icon) {
|
|
||||||
mIcon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasResult() {
|
boolean hasResult() {
|
||||||
return mResult != null;
|
return mResult != null;
|
||||||
}
|
}
|
||||||
@@ -671,11 +677,11 @@ public class DecryptListFragment
|
|||||||
holder.vFilesize.setText(FileHelper.readableFileSize(size));
|
holder.vFilesize.setText(FileHelper.readableFileSize(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.mIcon != null) {
|
// if (model.mIcon != null) {
|
||||||
holder.vThumbnail.setImageDrawable(model.mIcon);
|
// holder.vThumbnail.setImageDrawable(model.mIcon);
|
||||||
} else {
|
//} else {
|
||||||
holder.vThumbnail.setImageResource(R.drawable.ic_doc_generic_am);
|
holder.vThumbnail.setImageResource(R.drawable.ic_doc_generic_am);
|
||||||
}
|
//}
|
||||||
|
|
||||||
holder.vFile.setOnClickListener(new OnClickListener() {
|
holder.vFile.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -787,16 +793,13 @@ public class DecryptListFragment
|
|||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addResult(Uri uri, InputDataResult result, Drawable icon) {
|
public void addResult(Uri uri, InputDataResult result) {
|
||||||
|
|
||||||
ViewModel model = new ViewModel(uri);
|
ViewModel model = new ViewModel(uri);
|
||||||
int pos = mDataset.indexOf(model);
|
int pos = mDataset.indexOf(model);
|
||||||
model = mDataset.get(pos);
|
model = mDataset.get(pos);
|
||||||
|
|
||||||
model.addResult(result);
|
model.addResult(result);
|
||||||
if (icon != null) {
|
|
||||||
model.addIcon(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyItemChanged(pos);
|
notifyItemChanged(pos);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user