mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-13 10:52:15 -05:00
weird case for ligi
This commit is contained in:
parent
fa61438306
commit
b01dd39bd7
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -31,6 +32,7 @@ import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -70,9 +72,9 @@ import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.StatusHolder;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.ui.util.StatusHolder;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@ -162,11 +164,20 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_OUTPUT: {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
mCurrentInputUri = null;
|
||||
return;
|
||||
}
|
||||
// This happens after output file was selected, so start our operation
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
Uri saveUri = data.getData();
|
||||
Uri outputUri = mOutputUris.get(mCurrentInputUri);
|
||||
// TODO save from outputUri to saveUri
|
||||
Uri decryptedDataUri = mOutputUris.get(mCurrentInputUri);
|
||||
try {
|
||||
FileHelper.copyUri(getActivity(), decryptedDataUri, saveUri);
|
||||
} catch (IOException e) {
|
||||
Notify.create(activity, "Error saving file!", Style.ERROR).show();
|
||||
}
|
||||
|
||||
mCurrentInputUri = null;
|
||||
}
|
||||
@ -236,8 +247,16 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
}
|
||||
|
||||
Uri outputUri = mOutputUris.get(uri);
|
||||
Intent intent = new Intent();
|
||||
intent.setDataAndType(outputUri, metadata.getMimeType());
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType(metadata.getMimeType());
|
||||
intent.putExtra(Intent.EXTRA_STREAM, outputUri);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
} else {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
}
|
||||
// activity.startActivity(Intent.createChooser(intent, null));
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
};
|
||||
@ -388,7 +407,7 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class DecryptFilesAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
public static class DecryptFilesAdapter extends RecyclerView.Adapter<DecryptItemViewHolder> {
|
||||
private Context mContext;
|
||||
private ArrayList<ViewModel> mDataset;
|
||||
private OnMenuItemClickListener mMenuItemClickListener;
|
||||
@ -469,16 +488,16 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
|
||||
// Create new views (invoked by the layout manager)
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public DecryptItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
//inflate your layout and pass it to view holder
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.decrypt_list_entry, parent, false);
|
||||
return new ViewHolder(v);
|
||||
return new DecryptItemViewHolder(v);
|
||||
}
|
||||
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, final int position) {
|
||||
public void onBindViewHolder(DecryptItemViewHolder holder, final int position) {
|
||||
// - get element from your dataset at this position
|
||||
// - replace the contents of the view with that element
|
||||
final ViewModel model = mDataset.get(position);
|
||||
@ -577,11 +596,21 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
|
||||
}
|
||||
|
||||
private Drawable loadIcon(String mimeType) {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setType(mimeType);
|
||||
|
||||
// Provide a reference to the views for each data item
|
||||
// Complex data items may need more than one view per item, and
|
||||
// you provide access to all the views for a data item in a view holder
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder implements StatusHolder {
|
||||
final List<ResolveInfo> matches = getActivity()
|
||||
.getPackageManager().queryIntentActivities(intent, 0);
|
||||
//noinspection LoopStatementThatDoesntLoop
|
||||
for (ResolveInfo match : matches) {
|
||||
return match.loadIcon(getActivity().getPackageManager());
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static class DecryptItemViewHolder extends RecyclerView.ViewHolder implements StatusHolder {
|
||||
public ViewAnimator vAnimator;
|
||||
|
||||
public ProgressBar vProgress;
|
||||
@ -604,7 +633,7 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
|
||||
public View vContextMenu;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
public DecryptItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
vAnimator = (ViewAnimator) itemView.findViewById(R.id.view_animator);
|
||||
@ -676,19 +705,4 @@ public class DecryptFilesListFragment extends CryptoOperationFragment implements
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable loadIcon(String mimeType) {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setType(mimeType);
|
||||
|
||||
final List<ResolveInfo> matches = getActivity()
|
||||
.getPackageManager().queryIntentActivities(intent, 0);
|
||||
//noinspection LoopStatementThatDoesntLoop
|
||||
for (ResolveInfo match : matches) {
|
||||
return match.loadIcon(getActivity().getPackageManager());
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -423,22 +423,6 @@ public class KeyFormattingUtils {
|
||||
setStatusImage(context, statusIcon, statusText, state, color, false);
|
||||
}
|
||||
|
||||
public interface StatusHolder {
|
||||
ImageView getEncryptionStatusIcon();
|
||||
TextView getEncryptionStatusText();
|
||||
|
||||
ImageView getSignatureStatusIcon();
|
||||
TextView getSignatureStatusText();
|
||||
|
||||
View getSignatureLayout();
|
||||
TextView getSignatureUserName();
|
||||
TextView getSignatureUserEmail();
|
||||
TextView getSignatureAction();
|
||||
|
||||
boolean hasEncrypt();
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated
|
||||
public static void setStatus(Context context, StatusHolder holder, DecryptVerifyResult result) {
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package org.sufficientlysecure.keychain.ui.util;
|
||||
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public interface StatusHolder {
|
||||
|
||||
ImageView getEncryptionStatusIcon();
|
||||
|
||||
TextView getEncryptionStatusText();
|
||||
|
||||
ImageView getSignatureStatusIcon();
|
||||
|
||||
TextView getSignatureStatusText();
|
||||
|
||||
View getSignatureLayout();
|
||||
|
||||
TextView getSignatureUserName();
|
||||
|
||||
TextView getSignatureUserEmail();
|
||||
|
||||
TextView getSignatureAction();
|
||||
|
||||
boolean hasEncrypt();
|
||||
|
||||
}
|
@ -37,11 +37,15 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class FileHelper {
|
||||
@ -237,4 +241,37 @@ public class FileHelper {
|
||||
public static interface FileDialogCallback {
|
||||
public void onFileSelected(File file, boolean checked);
|
||||
}
|
||||
|
||||
public static void copyUri(Context context, Uri from, Uri to) throws IOException {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = context.getContentResolver().openInputStream(from);
|
||||
out = context.getContentResolver().openOutputStream(to);
|
||||
copyStream(in, out);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "io exception while copying uri streams", e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (in != null) try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// nvm
|
||||
}
|
||||
if (out != null) try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
// nvm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyStream(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while((read = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user